Libosmium  2.14.2
Fast and flexible C++ library for working with OpenStreetMap data
Public Types | Public Member Functions | Private Attributes | List of all members
osmium::TagsFilter Class Reference

#include <tags_filter.hpp>

Public Types

using iterator = boost::filter_iterator< TagsFilter, osmium::TagList::const_iterator >
 

Public Member Functions

 TagsFilter (bool default_result=false)
 
void set_default_result (bool default_result) noexcept
 
TagsFilteradd_rule (bool result, const TagMatcher &matcher)
 
template<typename... TArgs>
TagsFilteradd_rule (bool result, TArgs &&... args)
 
bool operator() (const osmium::Tag &tag) const noexcept
 
size_t count () const noexcept
 
bool empty () const noexcept
 

Private Attributes

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

Detailed Description

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

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);

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

Member Typedef Documentation

◆ iterator

Constructor & Destructor Documentation

◆ TagsFilter()

osmium::TagsFilter::TagsFilter ( bool  default_result = false)
inlineexplicit

Constructor.

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

Member Function Documentation

◆ add_rule() [1/2]

TagsFilter& osmium::TagsFilter::add_rule ( bool  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... TArgs>
TagsFilter& osmium::TagsFilter::add_rule ( bool  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()

size_t osmium::TagsFilter::count ( ) const
inlinenoexcept

Return the number of rules in this filter.

Complexity: Constant.

◆ empty()

bool osmium::TagsFilter::empty ( ) const
inlinenoexcept

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

Complexity: Constant.

◆ operator()()

bool osmium::TagsFilter::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()

void osmium::TagsFilter::set_default_result ( bool  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

bool osmium::TagsFilter::m_default_result
private

◆ m_rules

std::vector<std::pair<bool, TagMatcher> > osmium::TagsFilter::m_rules
private

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