Libosmium: include/osmium/tags/matcher.hpp Source File

Libosmium Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
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-2026 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>
37#include <osmium/util/string_matcher.hpp>
38
39#include <algorithm>
40#include <type_traits>
41#include <utility>
42
43namespace osmium {
44
48 class TagMatcher {
49
50 osmium::StringMatcher m_key_matcher;
51 osmium::StringMatcher m_value_matcher;
52 bool m_has_value_matcher = false;
53 bool m_result = true;
54
55 public:
56
60 TagMatcher() :
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 {
66 return m_has_value_matcher;
67 }
68
75 template <typename TKey, typename X = std::enable_if_t<
76 std::is_convertible<TKey, osmium::StringMatcher>::value, void>>
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_t<std::is_convertible<TKey, osmium::StringMatcher>::value, int> = 0,
92 typename std::enable_if_t<std::is_convertible<TValue, osmium::StringMatcher>::value, int> = 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)),
96 m_has_value_matcher(true),
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
osmium::StringMatcher
Definition string_matcher.hpp:62
osmium::TagList
Definition tag.hpp:119
osmium::TagMatcher::m_has_value_matcher
bool m_has_value_matcher
Definition matcher.hpp:52
osmium::TagMatcher::has_value_matcher
bool has_value_matcher() const noexcept
Definition matcher.hpp:65
osmium::TagMatcher::TagMatcher
TagMatcher()
Definition matcher.hpp:60
osmium::TagMatcher::m_key_matcher
osmium::StringMatcher m_key_matcher
Definition matcher.hpp:50
osmium::TagMatcher::TagMatcher
TagMatcher(TKey &&key_matcher)
Definition matcher.hpp:77
osmium::TagMatcher::m_result
bool m_result
Definition matcher.hpp:53
osmium::TagMatcher::TagMatcher
TagMatcher(TKey &&key_matcher, TValue &&value_matcher, bool invert=false)
Definition matcher.hpp:93
osmium::TagMatcher::operator()
bool operator()(const char *key, const char *value) const noexcept
Definition matcher.hpp:105
osmium::TagMatcher::operator()
bool operator()(const osmium::TagList &tags) const noexcept
Definition matcher.hpp:124
osmium::TagMatcher::m_value_matcher
osmium::StringMatcher m_value_matcher
Definition matcher.hpp:51
osmium::TagMatcher::operator()
bool operator()(const osmium::Tag &tag) const noexcept
Definition matcher.hpp:115
osmium::Tag
Definition tag.hpp:48
osmium::tags
Code related to working with OSM tags.
Definition filter.hpp:47
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
std
Definition location.hpp:654
string_matcher.hpp
tag.hpp