Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
osmium::relations::RelationsDatabase Class Reference

#include <relations_database.hpp>

Collaboration diagram for osmium::relations::RelationsDatabase:
Collaboration graph
[legend]

Classes

struct  element
 

Public Member Functions

 RelationsDatabase (osmium::ItemStash &stash)
 
std::size_t used_memory () const noexcept
 
std::size_t size () const noexcept
 
RelationHandle add (const osmium::Relation &relation)
 
RelationHandle operator[] (std::size_t pos) noexcept
 
std::size_t count_relations () const noexcept
 
template<typename TFunc >
void for_each_relation (TFunc &&func)
 

Private Member Functions

osmium::Relationget_relation (std::size_t pos)
 
std::size_t & members (std::size_t pos) noexcept
 
void remove (std::size_t pos)
 

Private Attributes

osmium::ItemStashm_stash
 
std::vector< elementm_elements
 

Friends

class RelationHandle
 

Detailed Description

The RelationsDatabase is used for bringing relations and their members together. It stores the relations in memory and keeps track of how many members are needed to "complete" the relation. It is intended to work together with the MembersDatabase template class and usually used by relations manager classes.

To access relations stored in the database a RelationHandle is used. It is returned from the add() function. The handle is used for all operations on the database contents, such as accessing the stored relation, incrementing the member count or removing a relation from the database.

From the handle a "position" can be accessed, which, together with the database object, can be turned into a handle again. The position alone is smaller than the handle, so it can be stored elsewhere more efficiently. Specifically this is used in the MembersDatabase.

auto handle = db.add(relation);
auto pos = handle.pos();
auto second_handle = db[pos];
Definition: item_stash.hpp:57
Definition: relations_database.hpp:82

Now the handle and second_handle refer to the same relation.

See the RelationHandle for information about what you can do with it.

Constructor & Destructor Documentation

◆ RelationsDatabase()

osmium::relations::RelationsDatabase::RelationsDatabase ( osmium::ItemStash stash)
inlineexplicit

Construct a RelationsDatabase.

Parameters
stashReference to an ItemStash object. All relations will be stored in this stash. It must be available until the RelationsDatabase is destroyed.

Member Function Documentation

◆ add()

RelationHandle osmium::relations::RelationsDatabase::add ( const osmium::Relation relation)
inline

Insert a relation into the database. The relation is copied into the stash.

Complexity: Amortized constant.

Parameters
relationThe relation to be copied into the database.
Returns
A handle to the relation.

◆ count_relations()

std::size_t osmium::relations::RelationsDatabase::count_relations ( ) const
inlinenoexcept

Return the number of non-removed relations in the database.

Complexity: Linear in the number of relations (as returned by size()).

◆ for_each_relation()

template<typename TFunc >
void osmium::relations::RelationsDatabase::for_each_relation ( TFunc &&  func)

Iterate over all (not-removed) relations in the database.

Template Parameters
TFuncFunction with type void(const RelationHandle&).
Parameters
funcCallback function which will be called for every not-removed relation with a RelationHandle.

◆ get_relation()

osmium::Relation & osmium::relations::RelationsDatabase::get_relation ( std::size_t  pos)
inlineprivate

◆ members()

std::size_t & osmium::relations::RelationsDatabase::members ( std::size_t  pos)
inlineprivatenoexcept

Access the number of members of the entry at the specified position. This returns a reference so it can be changed.

◆ operator[]()

RelationHandle osmium::relations::RelationsDatabase::operator[] ( std::size_t  pos)
inlinenoexcept

Return a handle to the relation at the specified position in the database.

Complexity: Constant.

◆ remove()

void osmium::relations::RelationsDatabase::remove ( std::size_t  pos)
inlineprivate

◆ size()

std::size_t osmium::relations::RelationsDatabase::size ( ) const
inlinenoexcept

The number of relations stored in the database. Includes relations marked as removed.

Complexity: Constant.

◆ used_memory()

std::size_t osmium::relations::RelationsDatabase::used_memory ( ) const
inlinenoexcept

Return an estimate of the number of bytes currently needed for the RelationsDatabase. This does NOT include the memory used in the stash. Used for debugging.

Complexity: Constant.

Friends And Related Function Documentation

◆ RelationHandle

friend class RelationHandle
friend

Member Data Documentation

◆ m_elements

std::vector<element> osmium::relations::RelationsDatabase::m_elements
private

◆ m_stash

osmium::ItemStash& osmium::relations::RelationsDatabase::m_stash
private

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