1#ifndef OSMIUM_VISITOR_HPP
2#define OSMIUM_VISITOR_HPP
51 template <
typename T,
typename U>
52 using ConstIfConst = std::conditional_t<std::is_const<T>::value, std::add_const_t<U>, 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>
101 inline void apply_item_impl(
const osmium::OSMEntity& item, THandler&& handler) {
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));
123 throw osmium::unknown_type{};
127 template <
typename THandler>
128 inline void apply_item_impl(osmium::OSMEntity& item, THandler&& handler) {
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));
150 throw osmium::unknown_type{};
154 template <
typename THandler>
155 inline void apply_item_impl(
const osmium::OSMObject& item, THandler&& handler) {
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));
174 throw osmium::unknown_type{};
178 template <
typename THandler>
179 inline void apply_item_impl(osmium::OSMObject& item, THandler&& handler) {
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));
198 throw osmium::unknown_type{};
202 template <
typename TFunc>
203 struct wrapper_handler : TFunc {
205 template <
typename T>
206 explicit wrapper_handler(T&& func) : TFunc(std::
forward<T>(func)) {
210 void operator()(
const osmium::memory::Item& )
const noexcept {
214 using TFunc::operator();
216 void osm_object(
const osmium::OSMObject& )
const noexcept {
219 void node(
const osmium::Node& node)
const {
224 void node(osmium::Node& node)
const {
228 void way(
const osmium::Way& way)
const {
233 void way(osmium::Way& way)
const {
237 void relation(
const osmium::Relation& relation)
const {
238 operator()(relation);
242 void relation(osmium::Relation& relation)
const {
243 operator()(relation);
246 void area(
const osmium::Area& area)
const {
251 void area(osmium::Area& area)
const {
255 void changeset(
const osmium::Changeset& changeset)
const {
256 operator()(changeset);
260 void changeset(osmium::Changeset& changeset)
const {
261 operator()(changeset);
264 void tag_list(
const osmium::TagList& )
const noexcept {
267 void way_node_list(
const osmium::WayNodeList& )
const noexcept {
273 void outer_ring(
const osmium::OuterRing& )
const noexcept {
276 void inner_ring(
const osmium::InnerRing& )
const noexcept {
282 void flush() const noexcept {
288 template <
typename T>
289 using is_handler = std::is_base_of<osmium::handler::Handler, std::remove_reference_t<T>>;
292 template <typename T, typename = std::enable_if_t<is_handler<T>::value>>
293 T make_handler(T&& func) {
294 return std::forward<T>(func);
298 template <typename T, typename = std::enable_if_t<!is_handler<T>::value>>
299 wrapper_handler<std::decay_t<T>> make_handler(T&& func) {
300 return wrapper_handler<std::decay_t<T>>(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)...);
item_type type() const noexcept
Definition item.hpp:171
@ forward
Linestring has same direction as way.
Definition factory.hpp:120
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
@ tag_list
Definition item_type.hpp:53
@ relation_member_list
Definition item_type.hpp:55
@ way_node_list
Definition item_type.hpp:54
@ changeset_discussion
Definition item_type.hpp:59
@ relation_member_list_with_full_members
Definition item_type.hpp:56
@ relation
Definition item_type.hpp:50
@ node
Definition item_type.hpp:48
@ changeset
Definition item_type.hpp:52
@ area
Definition item_type.hpp:51
@ undefined
Definition item_type.hpp:47
@ way
Definition item_type.hpp:49
@ outer_ring
Definition item_type.hpp:57
@ inner_ring
Definition item_type.hpp:58