1 #ifndef OSMIUM_VISITOR_HPP 2 #define OSMIUM_VISITOR_HPP 44 #include <type_traits> 51 template <
typename T,
typename U>
54 template <
typename THandler,
typename TItem>
55 inline void apply_item_impl(TItem& item, THandler&& handler) {
56 switch (item.type()) {
60 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
61 std::forward<THandler>(handler).
node(
static_cast<ConstIfConst<TItem, osmium::Node>&
>(item));
64 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
65 std::forward<THandler>(handler).
way(
static_cast<ConstIfConst<TItem, osmium::Way>&
>(item));
68 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
69 std::forward<THandler>(handler).
relation(
static_cast<ConstIfConst<TItem, osmium::Relation>&
>(item));
72 std::forward<THandler>(handler).osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
73 std::forward<THandler>(handler).
area(
static_cast<ConstIfConst<TItem, osmium::Area>&
>(item));
76 std::forward<THandler>(handler).
changeset(
static_cast<ConstIfConst<TItem, osmium::Changeset>&
>(item));
79 std::forward<THandler>(handler).
tag_list(
static_cast<ConstIfConst<TItem, osmium::TagList>&
>(item));
82 std::forward<THandler>(handler).
way_node_list(
static_cast<ConstIfConst<TItem, osmium::WayNodeList>&
>(item));
86 std::forward<THandler>(handler).
relation_member_list(
static_cast<ConstIfConst<TItem, osmium::RelationMemberList>&
>(item));
89 std::forward<THandler>(handler).
outer_ring(
static_cast<ConstIfConst<TItem, osmium::OuterRing>&
>(item));
92 std::forward<THandler>(handler).
inner_ring(
static_cast<ConstIfConst<TItem, osmium::InnerRing>&
>(item));
95 std::forward<THandler>(handler).
changeset_discussion(
static_cast<ConstIfConst<TItem, osmium::ChangesetDiscussion>&
>(item));
100 template <
typename THandler>
102 switch (item.
type()) {
104 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
105 std::forward<THandler>(handler).
node(static_cast<const osmium::Node&>(item));
108 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
109 std::forward<THandler>(handler).
way(static_cast<const osmium::Way&>(item));
112 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
113 std::forward<THandler>(handler).
relation(static_cast<const osmium::Relation&>(item));
116 std::forward<THandler>(handler).osm_object(static_cast<const osmium::OSMObject&>(item));
117 std::forward<THandler>(handler).
area(static_cast<const osmium::Area&>(item));
120 std::forward<THandler>(handler).
changeset(static_cast<const osmium::Changeset&>(item));
127 template <
typename THandler>
129 switch (item.
type()) {
131 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
132 std::forward<THandler>(handler).
node(static_cast<osmium::Node&>(item));
135 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
136 std::forward<THandler>(handler).
way(static_cast<osmium::Way&>(item));
139 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
140 std::forward<THandler>(handler).
relation(static_cast<osmium::Relation&>(item));
143 std::forward<THandler>(handler).osm_object(static_cast<osmium::OSMObject&>(item));
144 std::forward<THandler>(handler).
area(static_cast<osmium::Area&>(item));
147 std::forward<THandler>(handler).
changeset(static_cast<osmium::Changeset&>(item));
154 template <
typename THandler>
156 switch (item.
type()) {
158 std::forward<THandler>(handler).osm_object(item);
159 std::forward<THandler>(handler).
node(static_cast<const osmium::Node&>(item));
162 std::forward<THandler>(handler).osm_object(item);
163 std::forward<THandler>(handler).
way(static_cast<const osmium::Way&>(item));
166 std::forward<THandler>(handler).osm_object(item);
167 std::forward<THandler>(handler).
relation(static_cast<const osmium::Relation&>(item));
170 std::forward<THandler>(handler).osm_object(item);
171 std::forward<THandler>(handler).
area(static_cast<const osmium::Area&>(item));
178 template <
typename THandler>
180 switch (item.
type()) {
182 std::forward<THandler>(handler).osm_object(item);
183 std::forward<THandler>(handler).
node(static_cast<osmium::Node&>(item));
186 std::forward<THandler>(handler).osm_object(item);
187 std::forward<THandler>(handler).
way(static_cast<osmium::Way&>(item));
190 std::forward<THandler>(handler).osm_object(item);
191 std::forward<THandler>(handler).
relation(static_cast<osmium::Relation&>(item));
194 std::forward<THandler>(handler).osm_object(item);
195 std::forward<THandler>(handler).
area(static_cast<osmium::Area&>(item));
202 template <
typename TFunc>
203 struct wrapper_handler : TFunc {
206 explicit wrapper_handler(T&& func) : TFunc(
std::
forward<T>(func)) {
214 using TFunc::operator();
236 operator()(relation);
240 operator()(relation);
252 operator()(changeset);
256 operator()(changeset);
277 void flush() const noexcept {
283 template <
typename T>
287 template <typename T, typename = typename std::enable_if<is_handler<T>::value>::type>
288 T make_handler(T&& func) {
289 return std::forward<T>(func);
293 template <typename T, typename = typename std::enable_if<!is_handler<T>::value>::type>
300 template <
typename TItem,
typename... THandlers>
301 inline void apply_item(TItem& item, THandlers&&... handlers) {
302 (void)std::initializer_list<int>{
303 (detail::apply_item_impl(item, std::forward<THandlers>(handlers)), 0)...
307 template <
typename... THandlers>
309 (void)std::initializer_list<int>{
310 (std::forward<THandlers>(handlers).flush(), 0)...
314 template <
typename TIterator,
typename... THandlers>
315 inline void apply_impl(TIterator it, TIterator
end, THandlers&&... handlers) {
316 for (; it !=
end; ++it) {
317 apply_item(*it, std::forward<THandlers>(handlers)...);
322 template <
typename TIterator,
typename... THandlers>
323 inline void apply(TIterator it, TIterator
end, THandlers&&... handlers) {
324 apply_impl(it, end, detail::make_handler<THandlers>(std::forward<THandlers>(handlers))...);
327 template <
typename TContainer,
typename... THandlers>
328 inline void apply(TContainer& c, THandlers&&... handlers) {
331 apply(
begin(c),
end(c), std::forward<THandlers>(handlers)...);
334 template <
typename... THandlers>
336 apply(buffer.
cbegin(), buffer.
cend(), std::forward<THandlers>(handlers)...);
341 #endif // OSMIUM_VISITOR_HPP
Definition: changeset.hpp:132
Definition: item_type.hpp:195
type
Definition: entity_bits.hpp:63
t_const_iterator< T > cend() const
Definition: buffer.hpp:789
InputIterator< Reader > end(Reader &)
Definition: reader_iterator.hpp:47
Definition: relation.hpp:168
Definition: location.hpp:550
Definition: relation.hpp:154
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:301
Linestring has same direction as way.
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:323
void apply_flush(THandlers &&... handlers)
Definition: visitor.hpp:308
Definition: buffer.hpp:97
t_const_iterator< T > cbegin() const
Definition: buffer.hpp:765
void apply_impl(TIterator it, TIterator end, THandlers &&... handlers)
Definition: visitor.hpp:315
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:148
item_type type() const noexcept
Definition: item.hpp:171
Definition: object.hpp:64