Libosmium 2.22.0 Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
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 (https://osmcode.org/libosmium).
7
8 Copyright 2013-2025 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 <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
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>
68 class ChainHandler : public osmium::handler::Handler {
69
70 using handlers_type = std::tuple<THandler&...>;
71 handlers_type m_handlers;
72
73 template <int N, int SIZE, typename THandlers>
74 struct call_flush {
75 void operator()(THandlers& handlers) {
76 std::get<N>(handlers).flush();
77 call_flush<N + 1, SIZE, THandlers>()(handlers);
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
86 OSMIUM_CHAIN_HANDLER_CALL(node, Node)
87 OSMIUM_CHAIN_HANDLER_CALL(way, Way)
88 OSMIUM_CHAIN_HANDLER_CALL(relation, Relation)
89 OSMIUM_CHAIN_HANDLER_CALL(changeset, Changeset)
90 OSMIUM_CHAIN_HANDLER_CALL(area, Area)
91
92 public:
93
94 explicit ChainHandler(THandler&... handlers) :
95 m_handlers(handlers...) {
96 }
97
98 void node(osmium::Node& node) {
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
106 void relation(osmium::Relation& relation) {
107 call_relation<0, sizeof...(THandler), handlers_type>()(m_handlers, relation);
108 }
109
110 void changeset(osmium::Changeset& changeset) {
111 call_changeset<0, sizeof...(THandler), handlers_type>()(m_handlers, changeset);
112 }
113
114 void area(osmium::Area& area) {
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
OSMIUM_CHAIN_HANDLER_CALL
#define OSMIUM_CHAIN_HANDLER_CALL(_func_, _type_)
Definition chain.hpp:40
osmium::Area
Definition area.hpp:125
osmium::Changeset
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition changeset.hpp:146
osmium::Node
Definition node.hpp:48
osmium::Relation
Definition relation.hpp:161
osmium::Way
Definition way.hpp:72
osmium::handler::ChainHandler
Definition chain.hpp:68
osmium::handler::ChainHandler::relation
void relation(osmium::Relation &relation)
Definition chain.hpp:106
osmium::handler::ChainHandler::way
void way(osmium::Way &way)
Definition chain.hpp:102
osmium::handler::ChainHandler::changeset
void changeset(osmium::Changeset &changeset)
Definition chain.hpp:110
osmium::handler::ChainHandler::ChainHandler
ChainHandler(THandler &... handlers)
Definition chain.hpp:94
osmium::handler::ChainHandler::node
void node(osmium::Node &node)
Definition chain.hpp:98
osmium::handler::ChainHandler::m_handlers
handlers_type m_handlers
Definition chain.hpp:71
osmium::handler::ChainHandler::handlers_type
std::tuple< THandler &... > handlers_type
Definition chain.hpp:70
osmium::handler::ChainHandler::area
void area(osmium::Area &area)
Definition chain.hpp:114
osmium::handler::ChainHandler::flush
void flush()
Definition chain.hpp:118
osmium::handler::Handler
Definition handler.hpp:71
handler.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::item_type::relation
@ relation
osmium::item_type::node
@ node
osmium::item_type::changeset
@ changeset
osmium::item_type::way
@ way
osmium::handler::ChainHandler::call_flush< SIZE, SIZE, THandlers >::operator()
void operator()(THandlers &)
Definition chain.hpp:83
osmium::handler::ChainHandler::call_flush
Definition chain.hpp:74
osmium::handler::ChainHandler::call_flush::operator()
void operator()(THandlers &handlers)
Definition chain.hpp:75