Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
Public Types | Public Member Functions | Private Attributes | List of all members
osmium::TagsFilterBase< TResult > Class Template Reference

#include <tags_filter.hpp>

Public Types

using iterator = osmium::memory::CollectionFilterIterator< TagsFilterBase, const osmium::Tag >
 

Public Member Functions

 TagsFilterBase (const TResult default_result=TResult{})
 
void set_default_result (const TResult default_result) noexcept
 
TagsFilterBaseadd_rule (const TResult result, const TagMatcher &matcher)
 
template<typename... TArgs>
TagsFilterBaseadd_rule (const TResult result, TArgs &&... args)
 
TResult operator() (const osmium::Tag &tag) const noexcept
 
std::size_t count () const noexcept
 
bool empty () const noexcept
 

Private Attributes

std::vector< std::pair< TResult, TagMatcher > > m_rules
 
TResult m_default_result
 

Detailed Description

template<typename TResult>
class osmium::TagsFilterBase< TResult >

A TagsFilterBase is a list of rules (defined using TagMatchers) to check tags against. The first rule that matches sets the result.

Usually you want to use the TagsFilter class, which is simply a specialization with TResult=bool. But TResult can be any class that has a default constructor and a conversion to bool. The class should be small, because it is copied around in some places.

Here is an example matching any "highway" tag except "highway=motorway":

osmium::TagsFilter filter{false};
filter.add_rule(false, osmium::TagMatcher{"highway", "motorway"});
filter.add_rule(true, osmium::TagMatcher{"highway"});
osmium::Tag& tag = ...;
bool result = filter(tag);
Definition: matcher.hpp:48
Definition: tag.hpp:48
TagsFilterBase & add_rule(const TResult result, const TagMatcher &matcher)
Definition: tags_filter.hpp:100

Use this instead of the old osmium::tags::Filter.

Member Typedef Documentation

◆ iterator

template<typename TResult >
using osmium::TagsFilterBase< TResult >::iterator = osmium::memory::CollectionFilterIterator<TagsFilterBase, const osmium::Tag>

Constructor & Destructor Documentation

◆ TagsFilterBase()

template<typename TResult >
osmium::TagsFilterBase< TResult >::TagsFilterBase ( const TResult  default_result = TResult{})
inlineexplicit

Constructor.

Parameters
default_resultThe result the matching function will return if none of the rules matched.

Member Function Documentation

◆ add_rule() [1/2]

template<typename TResult >
TagsFilterBase & osmium::TagsFilterBase< TResult >::add_rule ( const TResult  result,
const TagMatcher matcher 
)
inline

Add a rule to the filter.

Parameters
resultThe result returned when this rule matches.
matcherThe TagMatcher for checking tags.
Returns
A reference to this filter for chaining.

◆ add_rule() [2/2]

template<typename TResult >
template<typename... TArgs>
TagsFilterBase & osmium::TagsFilterBase< TResult >::add_rule ( const TResult  result,
TArgs &&...  args 
)
inline

Add a rule to the filter.

Parameters
resultThe result returned when this rule matches.
argsArguments to construct a TagMatcher from that is used for checking tags.
Returns
A reference to this filter for chaining.

◆ count()

template<typename TResult >
std::size_t osmium::TagsFilterBase< TResult >::count ( ) const
inlinenoexcept

Return the number of rules in this filter.

Complexity: Constant.

◆ empty()

template<typename TResult >
bool osmium::TagsFilterBase< TResult >::empty ( ) const
inlinenoexcept

Is this filter empty, ie are there no rules defined?

Complexity: Constant.

◆ operator()()

template<typename TResult >
TResult osmium::TagsFilterBase< TResult >::operator() ( const osmium::Tag tag) const
inlinenoexcept

Matching function. Check the specified tag against the rules.

Parameters
tagA tag.
Returns
The result of the matching rule, or, if none of the rules matched, the default result.

◆ set_default_result()

template<typename TResult >
void osmium::TagsFilterBase< TResult >::set_default_result ( const TResult  default_result)
inlinenoexcept

Set the default result, the result the matching function will return if none of the rules matched.

Member Data Documentation

◆ m_default_result

template<typename TResult >
TResult osmium::TagsFilterBase< TResult >::m_default_result
private

◆ m_rules

template<typename TResult >
std::vector<std::pair<TResult, TagMatcher> > osmium::TagsFilterBase< TResult >::m_rules
private

The documentation for this class was generated from the following file: