Loading...
Searching...
No Matches
tags_filter.hpp
Go to the documentation of this file.
#ifndef OSMIUM_TAGS_TAGS_FILTER_HPP
#define OSMIUM_TAGS_TAGS_FILTER_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/tags/matcher.hpp>
#include <utility>
#include <vector>
namespace osmium {
template <typename TResult>
class TagsFilterBase {
std::vector<std::pair<TResult, TagMatcher>> m_rules;
TResult m_default_result;
public:
using iterator = osmium::memory::CollectionFilterIterator<TagsFilterBase, const osmium::Tag>;
explicit TagsFilterBase(const TResult default_result = TResult{}) :
m_default_result(default_result) {
}
void set_default_result(const TResult default_result) noexcept {
m_default_result = default_result;
}
TagsFilterBase& add_rule(const TResult result, const TagMatcher& matcher) {
m_rules.emplace_back(result, matcher);
return *this;
}
template <typename... TArgs>
TagsFilterBase& add_rule(const TResult result, TArgs&&... args) {
m_rules.emplace_back(result, osmium::TagMatcher{std::forward<TArgs>(args)...});
return *this;
}
TResult operator()(const osmium::Tag& tag) const noexcept {
for (const auto& rule : m_rules) {
if (rule.second(tag)) {
return rule.first;
}
}
return m_default_result;
}
std::size_t count() const noexcept {
return m_rules.size();
}
bool empty() const noexcept {
return m_rules.empty();
}
}; // class TagsFilterBase
using TagsFilter = TagsFilterBase<bool>;
} // namespace osmium
#endif // OSMIUM_TAGS_TAGS_FILTER_HPP
osmium::TagMatcher
Definition matcher.hpp:48
osmium::Tag
Definition tag.hpp:48
osmium::TagsFilterBase
Definition tags_filter.hpp:66
osmium::TagsFilterBase::add_rule
TagsFilterBase & add_rule(const TResult result, TArgs &&... args)
Definition tags_filter.hpp:114
osmium::TagsFilterBase::m_default_result
TResult m_default_result
Definition tags_filter.hpp:69
osmium::TagsFilterBase::count
std::size_t count() const noexcept
Definition tags_filter.hpp:140
osmium::TagsFilterBase::empty
bool empty() const noexcept
Definition tags_filter.hpp:149
osmium::TagsFilterBase::set_default_result
void set_default_result(const TResult default_result) noexcept
Definition tags_filter.hpp:89
osmium::TagsFilterBase::operator()
TResult operator()(const osmium::Tag &tag) const noexcept
Definition tags_filter.hpp:126
osmium::TagsFilterBase::add_rule
TagsFilterBase & add_rule(const TResult result, const TagMatcher &matcher)
Definition tags_filter.hpp:100
osmium::TagsFilterBase::m_rules
std::vector< std::pair< TResult, TagMatcher > > m_rules
Definition tags_filter.hpp:68
osmium::TagsFilterBase::TagsFilterBase
TagsFilterBase(const TResult default_result=TResult{})
Definition tags_filter.hpp:81
osmium::memory::CollectionFilterIterator
Definition collection.hpp:117
matcher.hpp
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
tag.hpp