Libosmium  2.20.0
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
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/osm/tag.hpp>
38
39#include <algorithm>
40#include <type_traits>
41#include <utility>
42
43namespace osmium {
44
48 class TagMatcher {
49
52 bool m_has_value_matcher = false;
53 bool m_result = true;
54
55 public:
56
61 m_key_matcher(osmium::StringMatcher::always_false{}),
62 m_value_matcher(osmium::StringMatcher::always_false{}) {
63 }
64
65 bool has_value_matcher() const noexcept {
67 }
68
75 template <typename TKey, typename X = typename std::enable_if<
76 std::is_convertible<TKey, osmium::StringMatcher>::value, void>::type>
77 explicit TagMatcher(TKey&& key_matcher) :
78 m_key_matcher(std::forward<TKey>(key_matcher)),
79 m_value_matcher(osmium::StringMatcher::always_true{}) {
80 }
81
90 template <typename TKey, typename TValue,
91 typename std::enable_if<std::is_convertible<TKey, osmium::StringMatcher>::value, int>::type = 0,
92 typename std::enable_if<std::is_convertible<TValue, osmium::StringMatcher>::value, int>::type = 0>
93 TagMatcher(TKey&& key_matcher, TValue&& value_matcher, bool invert = false) :
94 m_key_matcher(std::forward<TKey>(key_matcher)),
95 m_value_matcher(std::forward<TValue>(value_matcher)),
97 m_result(!invert) {
98 }
99
105 bool operator()(const char* key, const char* value) const noexcept {
106 return m_key_matcher(key) &&
107 (m_value_matcher(value) == m_result);
108 }
109
115 bool operator()(const osmium::Tag& tag) const noexcept {
116 return operator()(tag.key(), tag.value());
117 }
118
124 bool operator()(const osmium::TagList& tags) const noexcept {
125 return std::any_of(tags.begin(), tags.end(), [this](const osmium::Tag& tag){
126 return operator()(tag);
127 });
128 }
129
130 }; // class TagMatcher
131
132} // namespace osmium
133
134#endif // OSMIUM_TAGS_MATCHER_HPP
Definition: string_matcher.hpp:86
Definition: tag.hpp:119
Definition: matcher.hpp:48
bool m_has_value_matcher
Definition: matcher.hpp:52
bool has_value_matcher() const noexcept
Definition: matcher.hpp:65
TagMatcher()
Definition: matcher.hpp:60
osmium::StringMatcher m_key_matcher
Definition: matcher.hpp:50
TagMatcher(TKey &&key_matcher)
Definition: matcher.hpp:77
bool m_result
Definition: matcher.hpp:53
TagMatcher(TKey &&key_matcher, TValue &&value_matcher, bool invert=false)
Definition: matcher.hpp:93
bool operator()(const char *key, const char *value) const noexcept
Definition: matcher.hpp:105
bool operator()(const osmium::TagList &tags) const noexcept
Definition: matcher.hpp:124
osmium::StringMatcher m_value_matcher
Definition: matcher.hpp:51
bool operator()(const osmium::Tag &tag) const noexcept
Definition: matcher.hpp:115
Definition: tag.hpp:48
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
Definition: location.hpp:555