1#ifndef OSMIUM_VISITOR_HPP
2#define OSMIUM_VISITOR_HPP
51 template <
typename T,
typename U>
52 using ConstIfConst =
typename std::conditional<std::is_const<T>::value,
typename std::add_const<U>::type, U>::type;
54 template <
typename THandler,
typename TItem>
55 inline void apply_item_impl(TItem& item, THandler&& handler) {
56 switch (item.type()) {
60 handler.osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
61 handler.node(
static_cast<ConstIfConst<TItem, osmium::Node>&
>(item));
64 handler.osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
65 handler.way(
static_cast<ConstIfConst<TItem, osmium::Way>&
>(item));
68 handler.osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
69 handler.relation(
static_cast<ConstIfConst<TItem, osmium::Relation>&
>(item));
72 handler.osm_object(
static_cast<ConstIfConst<TItem, osmium::OSMObject>&
>(item));
73 handler.area(
static_cast<ConstIfConst<TItem, osmium::Area>&
>(item));
76 handler.changeset(
static_cast<ConstIfConst<TItem, osmium::Changeset>&
>(item));
79 handler.tag_list(
static_cast<ConstIfConst<TItem, osmium::TagList>&
>(item));
82 handler.way_node_list(
static_cast<ConstIfConst<TItem, osmium::WayNodeList>&
>(item));
86 handler.relation_member_list(
static_cast<ConstIfConst<TItem, osmium::RelationMemberList>&
>(item));
89 handler.outer_ring(
static_cast<ConstIfConst<TItem, osmium::OuterRing>&
>(item));
92 handler.inner_ring(
static_cast<ConstIfConst<TItem, osmium::InnerRing>&
>(item));
95 handler.changeset_discussion(
static_cast<ConstIfConst<TItem, osmium::ChangesetDiscussion>&
>(item));
100 template <
typename THandler>
102 switch (item.
type()) {
109 handler.way(
static_cast<const osmium::Way&
>(item));
127 template <
typename THandler>
129 switch (item.
type()) {
154 template <
typename THandler>
156 switch (item.
type()) {
158 handler.osm_object(item);
162 handler.osm_object(item);
163 handler.way(
static_cast<const osmium::Way&
>(item));
166 handler.osm_object(item);
170 handler.osm_object(item);
178 template <
typename THandler>
180 switch (item.
type()) {
182 handler.osm_object(item);
186 handler.osm_object(item);
190 handler.osm_object(item);
194 handler.osm_object(item);
202 template <
typename TFunc>
203 struct wrapper_handler : TFunc {
205 template <
typename T>
206 explicit wrapper_handler(T&& func) : TFunc(
std::
forward<T>(func)) {
214 using TFunc::operator();
282 void flush() const noexcept {
288 template <
typename T>
289 using is_handler = std::is_base_of<osmium::handler::Handler, typename std::remove_reference<T>::type>;
292 template <typename T, typename = typename std::enable_if<is_handler<T>::value>::type>
293 T make_handler(T&& func) {
294 return std::forward<T>(func);
298 template <typename T, typename = typename std::enable_if<!is_handler<T>::value>::type>
299 wrapper_handler<typename std::decay<T>::type> make_handler(T&& func) {
300 return wrapper_handler<typename std::decay<T>::type>(std::forward<T>(func));
305 template <
typename TItem,
typename... THandlers>
306 inline void apply_item(TItem& item, THandlers&&... handlers) {
307 (void)std::initializer_list<int>{
308 (detail::apply_item_impl(item, std::forward<THandlers>(handlers)), 0)...};
311 template <
typename... THandlers>
313 (void)std::initializer_list<int>{
314 (std::forward<THandlers>(handlers).flush(), 0)...};
317 template <
typename TIterator,
typename... THandlers>
318 inline void apply_impl(TIterator it, TIterator end, THandlers&&... handlers) {
319 for (; it != end; ++it) {
325 template <
typename TIterator,
typename... THandlers>
326 inline void apply(TIterator it, TIterator end, THandlers&&... handlers) {
327 apply_impl(it, end, detail::make_handler<THandlers>(std::forward<THandlers>(handlers))...);
330 template <
typename TContainer,
typename... THandlers>
331 inline void apply(TContainer& c, THandlers&&... handlers) {
334 apply(begin(c), end(c), std::forward<THandlers>(handlers)...);
337 template <
typename... THandlers>
338 inline void apply(
const osmium::memory::Buffer& buffer, THandlers&&... handlers) {
339 apply(buffer.cbegin(), buffer.cend(), std::forward<THandlers>(handlers)...);
Definition changeset.hpp:130
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition changeset.hpp:146
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition entity.hpp:64
Definition relation.hpp:147
Definition relation.hpp:161
item_type type() const noexcept
Definition item.hpp:171
@ forward
Linestring has same direction as way.
@ area
Definition entity_bits.hpp:72
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
void apply_item(TItem &item, THandlers &&... handlers)
Definition visitor.hpp:306
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition visitor.hpp:326
void apply_flush(THandlers &&... handlers)
Definition visitor.hpp:312
void apply_impl(TIterator it, TIterator end, THandlers &&... handlers)
Definition visitor.hpp:318
@ relation_member_list_with_full_members
Definition location.hpp:555
Definition item_type.hpp:197