Libosmium  2.15.3
Fast and flexible C++ library for working with OpenStreetMap data
matcher.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_TAGS_MATCHER_HPP
2 #define OSMIUM_TAGS_MATCHER_HPP
3 
4 /*
5 
6 This file is part of Osmium (https://osmcode.org/libosmium).
7 
8 Copyright 2013-2019 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/osm/tag.hpp>
38 
39 #include <type_traits>
40 #include <utility>
41 
42 namespace osmium {
43 
47  class TagMatcher {
48 
51  bool m_result = true;
52 
53  public:
54 
59  m_key_matcher(osmium::StringMatcher::always_false{}),
61  }
62 
69  template <typename TKey, typename X = typename std::enable_if<
70  std::is_convertible<TKey, osmium::StringMatcher>::value, void>::type>
71  explicit TagMatcher(TKey&& key_matcher) :
72  m_key_matcher(std::forward<TKey>(key_matcher)),
73  m_value_matcher(osmium::StringMatcher::always_true{}) {
74  }
75 
84  template <typename TKey, typename TValue,
85  typename std::enable_if<std::is_convertible<TKey, osmium::StringMatcher>::value, int>::type = 0,
86  typename std::enable_if<std::is_convertible<TValue, osmium::StringMatcher>::value, int>::type = 0>
87  TagMatcher(TKey&& key_matcher, TValue&& value_matcher, bool invert = false) :
88  m_key_matcher(std::forward<TKey>(key_matcher)),
89  m_value_matcher(std::forward<TValue>(value_matcher)),
90  m_result(!invert) {
91  }
92 
98  bool operator()(const char* key, const char* value) const noexcept {
99  return m_key_matcher(key) &&
100  (m_value_matcher(value) == m_result);
101  }
102 
108  bool operator()(const osmium::Tag& tag) const noexcept {
109  return operator()(tag.key(), tag.value());
110  }
111 
117  bool operator()(const osmium::TagList& tags) const noexcept {
118  for (const auto& tag : tags) {
119  if (operator()(tag)) {
120  return true;
121  }
122  }
123  return false;
124  }
125 
126  }; // class TagMatcher
127 
128 } // namespace osmium
129 
130 #endif // OSMIUM_TAGS_MATCHER_HPP
TagMatcher()
Definition: matcher.hpp:58
Definition: tag.hpp:48
Definition: tag.hpp:119
type
Definition: entity_bits.hpp:63
bool operator()(const osmium::TagList &tags) const noexcept
Definition: matcher.hpp:117
Definition: location.hpp:550
TagMatcher(TKey &&key_matcher, TValue &&value_matcher, bool invert=false)
Definition: matcher.hpp:87
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
bool operator()(const char *key, const char *value) const noexcept
Definition: matcher.hpp:98
Definition: string_matcher.hpp:73
Definition: matcher.hpp:47
bool operator()(const osmium::Tag &tag) const noexcept
Definition: matcher.hpp:108
bool m_result
Definition: matcher.hpp:51
Definition: string_matcher.hpp:84
TagMatcher(TKey &&key_matcher)
Definition: matcher.hpp:71
osmium::StringMatcher m_value_matcher
Definition: matcher.hpp:50
osmium::StringMatcher m_key_matcher
Definition: matcher.hpp:49