Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
chain.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_HANDLER_CHAIN_HPP
2#define OSMIUM_HANDLER_CHAIN_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/handler.hpp>
37
38#include <tuple>
39
40#define OSMIUM_CHAIN_HANDLER_CALL(_func_, _type_) \
41 template <int N, int SIZE, typename THandlers> \
42 struct call_ ## _func_ { \
43 void operator()(THandlers& handlers, osmium::_type_& object) { \
44 std::get<N>(handlers)._func_(object); \
45 call_ ## _func_<N+1, SIZE, THandlers>()(handlers, object); \
46 } \
47 }; \
48 template <int SIZE, typename THandlers> \
49 struct call_ ## _func_<SIZE, SIZE, THandlers> { \
50 void operator()(THandlers&, osmium::_type_&) {} \
51 };
52
53namespace osmium {
54
55 class Node;
56 class Way;
57 class Relation;
58 class Area;
59 class Changeset;
60
61 namespace handler {
62
67 template <typename... THandler>
69
70 using handlers_type = std::tuple<THandler&...>;
72
73 template <int N, int SIZE, typename THandlers>
74 struct call_flush {
75 void operator()(THandlers& handlers) {
76 std::get<N>(handlers).flush();
78 }
79 }; // struct call_flush
80
81 template <int SIZE, typename THandlers>
82 struct call_flush<SIZE, SIZE, THandlers> {
83 void operator()(THandlers& /*handlers*/) {}
84 }; // struct call_flush
85
91
92 public:
93
94 explicit ChainHandler(THandler&... handlers) :
95 m_handlers(handlers...) {
96 }
97
99 call_node<0, sizeof...(THandler), handlers_type>()(m_handlers, node);
100 }
101
103 call_way<0, sizeof...(THandler), handlers_type>()(m_handlers, way);
104 }
105
107 call_relation<0, sizeof...(THandler), handlers_type>()(m_handlers, relation);
108 }
109
111 call_changeset<0, sizeof...(THandler), handlers_type>()(m_handlers, changeset);
112 }
113
115 call_area<0, sizeof...(THandler), handlers_type>()(m_handlers, area);
116 }
117
118 void flush() {
119 call_flush<0, sizeof...(THandler), handlers_type>()(m_handlers);
120 }
121
122 }; // class ChainHandler
123
124 } // namespace handler
125
126} // namespace osmium
127
128#endif // OSMIUM_HANDLER_CHAIN_HPP
#define OSMIUM_CHAIN_HANDLER_CALL(_func_, _type_)
Definition: chain.hpp:40
Definition: area.hpp:125
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition: changeset.hpp:146
Definition: node.hpp:48
Definition: relation.hpp:161
Definition: way.hpp:72
Definition: chain.hpp:68
void relation(osmium::Relation &relation)
Definition: chain.hpp:106
void way(osmium::Way &way)
Definition: chain.hpp:102
void changeset(osmium::Changeset &changeset)
Definition: chain.hpp:110
ChainHandler(THandler &... handlers)
Definition: chain.hpp:94
void node(osmium::Node &node)
Definition: chain.hpp:98
handlers_type m_handlers
Definition: chain.hpp:71
std::tuple< THandler &... > handlers_type
Definition: chain.hpp:70
void area(osmium::Area &area)
Definition: chain.hpp:114
void flush()
Definition: chain.hpp:118
Definition: handler.hpp:71
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void operator()(THandlers &)
Definition: chain.hpp:83
void operator()(THandlers &handlers)
Definition: chain.hpp:75