Libosmium  2.7.1
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 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
36 #include <tuple>
37 
38 #include <osmium/handler.hpp>
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 
53 namespace 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&) {}
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 
102  void way(osmium::Way& way) {
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
void changeset(osmium::Changeset &changeset)
Definition: chain.hpp:110
Definition: chain.hpp:68
Definition: relation.hpp:165
Definition: area.hpp:114
Definition: handler.hpp:45
std::tuple< THandler &... > handlers_type
Definition: chain.hpp:70
Definition: way.hpp:65
Namespace for everything in the Osmium library.
Definition: assembler.hpp:66
handlers_type m_handlers
Definition: chain.hpp:71
ChainHandler(THandler &...handlers)
Definition: chain.hpp:94
void relation(osmium::Relation &relation)
Definition: chain.hpp:106
void node(osmium::Node &node)
Definition: chain.hpp:98
void way(osmium::Way &way)
Definition: chain.hpp:102
void area(osmium::Area &area)
Definition: chain.hpp:114
Definition: node.hpp:47
void operator()(THandlers &handlers)
Definition: chain.hpp:75
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:154
void operator()(THandlers &)
Definition: chain.hpp:83
void flush()
Definition: chain.hpp:118