Libosmium
Fast and flexible C++ library for working with OpenStreetMap data
Toggle main menu visibility
Loading...
Searching...
No Matches
include
osmium
tags
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-2026 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
>
37
#include <
osmium/util/string_matcher.hpp
>
38
39
#include <algorithm>
40
#include <type_traits>
41
#include <utility>
42
43
namespace
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
Generated by
1.17.0