Libosmium  2.15.6
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-2020 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_has_value_matcher = false;
52  bool m_result = true;
53 
54  public:
55 
60  m_key_matcher(osmium::StringMatcher::always_false{}),
62  }
63 
64  bool has_value_matcher() const noexcept {
65  return m_has_value_matcher;
66  }
67 
74  template <typename TKey, typename X = typename std::enable_if<
75  std::is_convertible<TKey, osmium::StringMatcher>::value, void>::type>
76  explicit TagMatcher(TKey&& key_matcher) :
77  m_key_matcher(std::forward<TKey>(key_matcher)),
78  m_value_matcher(osmium::StringMatcher::always_true{}) {
79  }
80 
89  template <typename TKey, typename TValue,
90  typename std::enable_if<std::is_convertible<TKey, osmium::StringMatcher>::value, int>::type = 0,
91  typename std::enable_if<std::is_convertible<TValue, osmium::StringMatcher>::value, int>::type = 0>
92  TagMatcher(TKey&& key_matcher, TValue&& value_matcher, bool invert = false) :
93  m_key_matcher(std::forward<TKey>(key_matcher)),
94  m_value_matcher(std::forward<TValue>(value_matcher)),
95  m_has_value_matcher(true),
96  m_result(!invert) {
97  }
98 
104  bool operator()(const char* key, const char* value) const noexcept {
105  return m_key_matcher(key) &&
106  (m_value_matcher(value) == m_result);
107  }
108 
114  bool operator()(const osmium::Tag& tag) const noexcept {
115  return operator()(tag.key(), tag.value());
116  }
117 
123  bool operator()(const osmium::TagList& tags) const noexcept {
124  for (const auto& tag : tags) {
125  if (operator()(tag)) {
126  return true;
127  }
128  }
129  return false;
130  }
131 
132  }; // class TagMatcher
133 
134 } // namespace osmium
135 
136 #endif // OSMIUM_TAGS_MATCHER_HPP
osmium::TagMatcher::TagMatcher
TagMatcher()
Definition: matcher.hpp:59
string_matcher.hpp
tag.hpp
osmium::Tag
Definition: tag.hpp:48
osmium::TagMatcher::m_result
bool m_result
Definition: matcher.hpp:52
osmium::TagMatcher::operator()
bool operator()(const osmium::Tag &tag) const noexcept
Definition: matcher.hpp:114
osmium::TagMatcher::TagMatcher
TagMatcher(TKey &&key_matcher, TValue &&value_matcher, bool invert=false)
Definition: matcher.hpp:92
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
osmium::TagMatcher::m_has_value_matcher
bool m_has_value_matcher
Definition: matcher.hpp:51
osmium::TagMatcher::m_key_matcher
osmium::StringMatcher m_key_matcher
Definition: matcher.hpp:49
osmium::TagMatcher::TagMatcher
TagMatcher(TKey &&key_matcher)
Definition: matcher.hpp:76
std
Definition: location.hpp:551
osmium::TagMatcher::operator()
bool operator()(const char *key, const char *value) const noexcept
Definition: matcher.hpp:104
osmium::TagList
Definition: tag.hpp:119
osmium::TagMatcher
Definition: matcher.hpp:47
osmium::StringMatcher
Definition: string_matcher.hpp:73
osmium::TagMatcher::operator()
bool operator()(const osmium::TagList &tags) const noexcept
Definition: matcher.hpp:123
osmium::TagMatcher::has_value_matcher
bool has_value_matcher() const noexcept
Definition: matcher.hpp:64
osmium::StringMatcher::always_false
Definition: string_matcher.hpp:84
osmium::osm_entity_bits::type
type
Definition: entity_bits.hpp:63
osmium::TagMatcher::m_value_matcher
osmium::StringMatcher m_value_matcher
Definition: matcher.hpp:50