Loading...
Searching...
No Matches
matcher.hpp
Go to the documentation of this file.
#ifndef OSMIUM_TAGS_MATCHER_HPP
#define OSMIUM_TAGS_MATCHER_HPP
/*
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2025 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <osmium/osm/tag.hpp>
#include <osmium/util/string_matcher.hpp>
#include <algorithm>
#include <type_traits>
#include <utility>
namespace osmium {
class TagMatcher {
osmium::StringMatcher m_key_matcher;
osmium::StringMatcher m_value_matcher;
bool m_has_value_matcher = false;
bool m_result = true;
public:
TagMatcher() :
m_key_matcher(osmium::StringMatcher::always_false{}),
m_value_matcher(osmium::StringMatcher::always_false{}) {
}
bool has_value_matcher() const noexcept {
return m_has_value_matcher;
}
template <typename TKey, typename X = std::enable_if_t<
std::is_convertible<TKey, osmium::StringMatcher>::value, void>>
explicit TagMatcher(TKey&& key_matcher) :
m_key_matcher(std::forward<TKey>(key_matcher)),
m_value_matcher(osmium::StringMatcher::always_true{}) {
}
template <typename TKey, typename TValue,
typename std::enable_if_t<std::is_convertible<TKey, osmium::StringMatcher>::value, int> = 0,
typename std::enable_if_t<std::is_convertible<TValue, osmium::StringMatcher>::value, int> = 0>
TagMatcher(TKey&& key_matcher, TValue&& value_matcher, bool invert = false) :
m_key_matcher(std::forward<TKey>(key_matcher)),
m_value_matcher(std::forward<TValue>(value_matcher)),
m_has_value_matcher(true),
m_result(!invert) {
}
bool operator()(const char* key, const char* value) const noexcept {
return m_key_matcher(key) &&
(m_value_matcher(value) == m_result);
}
bool operator()(const osmium::Tag& tag) const noexcept {
return operator()(tag.key(), tag.value());
}
bool operator()(const osmium::TagList& tags) const noexcept {
return std::any_of(tags.begin(), tags.end(), [this](const osmium::Tag& tag){
return operator()(tag);
});
}
}; // class TagMatcher
} // namespace osmium
#endif // OSMIUM_TAGS_MATCHER_HPP
osmium::StringMatcher
Definition string_matcher.hpp:62
osmium::TagList
Definition tag.hpp:119
osmium::TagMatcher
Definition matcher.hpp:48
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
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
std
Definition location.hpp:555
string_matcher.hpp
tag.hpp