1 #ifndef OSMIUM_VISITOR_HPP 2 #define OSMIUM_VISITOR_HPP 43 #include <type_traits> 50 template <
typename T,
typename U>
53 template <
typename THandler,
typename TItem>
54 inline void apply_item_impl(TItem& item, THandler&& handler) {
55 switch (item.type()) {
59 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
60 std::forward<THandler>(handler).
node(
static_cast<ConstIfConst<TItem, osmium::Node>&
>(item));
63 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
64 std::forward<THandler>(handler).
way(
static_cast<ConstIfConst<TItem, osmium::Way>&
>(item));
67 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
68 std::forward<THandler>(handler).
relation(
static_cast<ConstIfConst<TItem, osmium::Relation>&
>(item));
71 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
72 std::forward<THandler>(handler).
area(
static_cast<ConstIfConst<TItem, osmium::Area>&
>(item));
75 std::forward<THandler>(handler).
changeset(
static_cast<ConstIfConst<TItem, osmium::Changeset>&
>(item));
78 std::forward<THandler>(handler).
tag_list(
static_cast<ConstIfConst<TItem, osmium::TagList>&
>(item));
81 std::forward<THandler>(handler).
way_node_list(
static_cast<ConstIfConst<TItem, osmium::WayNodeList>&
>(item));
85 std::forward<THandler>(handler).
relation_member_list(
static_cast<ConstIfConst<TItem, osmium::RelationMemberList>&
>(item));
88 std::forward<THandler>(handler).
outer_ring(
static_cast<ConstIfConst<TItem, osmium::OuterRing>&
>(item));
91 std::forward<THandler>(handler).
inner_ring(
static_cast<ConstIfConst<TItem, osmium::InnerRing>&
>(item));
94 std::forward<THandler>(handler).
changeset_discussion(
static_cast<ConstIfConst<TItem, osmium::ChangesetDiscussion>&
>(item));
99 template <
typename THandler>
101 switch (item.
type()) {
103 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
104 std::forward<THandler>(handler).
node(static_cast<const osmium::Node&>(item));
107 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
108 std::forward<THandler>(handler).
way(static_cast<const osmium::Way&>(item));
111 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
112 std::forward<THandler>(handler).
relation(static_cast<const osmium::Relation&>(item));
115 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
116 std::forward<THandler>(handler).
area(static_cast<const osmium::Area&>(item));
119 std::forward<THandler>(handler).
changeset(static_cast<const osmium::Changeset&>(item));
126 template <
typename THandler>
128 switch (item.
type()) {
130 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
131 std::forward<THandler>(handler).
node(static_cast<osmium::Node&>(item));
134 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
135 std::forward<THandler>(handler).
way(static_cast<osmium::Way&>(item));
138 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
139 std::forward<THandler>(handler).
relation(static_cast<osmium::Relation&>(item));
142 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
143 std::forward<THandler>(handler).
area(static_cast<osmium::Area&>(item));
146 std::forward<THandler>(handler).
changeset(static_cast<osmium::Changeset&>(item));
153 template <
typename THandler>
155 switch (item.
type()) {
157 std::forward<THandler>(handler).osm_object(item);
158 std::forward<THandler>(handler).
node(static_cast<const osmium::Node&>(item));
161 std::forward<THandler>(handler).osm_object(item);
162 std::forward<THandler>(handler).
way(static_cast<const osmium::Way&>(item));
165 std::forward<THandler>(handler).osm_object(item);
166 std::forward<THandler>(handler).
relation(static_cast<const osmium::Relation&>(item));
169 std::forward<THandler>(handler).osm_object(item);
170 std::forward<THandler>(handler).
area(static_cast<const osmium::Area&>(item));
177 template <
typename THandler>
179 switch (item.
type()) {
181 std::forward<THandler>(handler).osm_object(item);
182 std::forward<THandler>(handler).
node(static_cast<osmium::Node&>(item));
185 std::forward<THandler>(handler).osm_object(item);
186 std::forward<THandler>(handler).
way(static_cast<osmium::Way&>(item));
189 std::forward<THandler>(handler).osm_object(item);
190 std::forward<THandler>(handler).
relation(static_cast<osmium::Relation&>(item));
193 std::forward<THandler>(handler).osm_object(item);
194 std::forward<THandler>(handler).
area(static_cast<osmium::Area&>(item));
203 template <
typename TItem,
typename... THandlers>
204 inline void apply_item(TItem& item, THandlers&&... handlers) {
205 (void)std::initializer_list<int>{
206 (detail::apply_item_impl(item, std::forward<THandlers>(handlers)), 0)...
210 template <
typename... THandlers>
212 (void)std::initializer_list<int>{
213 (std::forward<THandlers>(handlers).flush(), 0)...
217 template <
typename TIterator,
typename... THandlers>
218 inline void apply(TIterator it, TIterator
end, THandlers&&... handlers) {
219 for (; it !=
end; ++it) {
220 apply_item(*it, std::forward<THandlers>(handlers)...);
225 template <
typename TContainer,
typename... THandlers>
226 inline void apply(TContainer& c, THandlers&&... handlers) {
229 apply(
begin(c),
end(c), std::forward<THandlers>(handlers)...);
232 template <
typename... THandlers>
234 apply(buffer.
cbegin(), buffer.
cend(), std::forward<THandlers>(handlers)...);
239 #endif // OSMIUM_VISITOR_HPP
Definition: item_type.hpp:195
type
Definition: entity_bits.hpp:63
t_const_iterator< T > cend() const
Definition: buffer.hpp:784
InputIterator< Reader > end(Reader &)
Definition: reader_iterator.hpp:47
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
void apply_item(TItem &item, THandlers &&... handlers)
Definition: visitor.hpp:204
InputIterator< Reader > begin(Reader &reader)
Definition: reader_iterator.hpp:43
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition: visitor.hpp:218
void apply_flush(THandlers &&... handlers)
Definition: visitor.hpp:211
Definition: buffer.hpp:97
t_const_iterator< T > cbegin() const
Definition: buffer.hpp:762
item_type type() const noexcept
Definition: item.hpp:171
Definition: object.hpp:64