osmium::relations::Collector< TCollector, TNodes, TWays, TRelations > Class Template Reference

`#include <collector.hpp>`

Collaboration diagram for osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >:
[legend]

## Classes

class | HandlerPass1
class | HandlerPass2

## Public Member Functions

| Collector ()
uint64_t | used_memory () const
HandlerPass2 & | handler (const callback_func_type &callback=nullptr)
osmium::memory::Buffer & | members_buffer ()
size_t | get_offset (osmium::item_type type, osmium::object_id_type id)
template<typename TIter >
void | read_relations (TIter begin, TIter end)
template<typename TSource >
void | read_relations (TSource &source)
void | moving_in_buffer (size_t old_offset, size_t new_offset)
void | possibly_purge_removed_members ()
std::vector< const osmium::Relation * > | get_incomplete_relations () const

## Protected Member Functions

std::vector< MemberMeta > & | member_meta (const item_type type)
callback_func_type | callback ()
const std::vector< RelationMeta > & | relations () const
bool | keep_relation (const osmium::Relation &) const
bool | keep_member (const osmium::relations::RelationMeta &, const osmium::RelationMember &) const
void | node_not_in_any_relation (const osmium::Node &)
void | way_not_in_any_relation (const osmium::Way &)
void | relation_not_in_any_relation (const osmium::Relation &)
void | flush ()
void | clean_assembled_relations ()
const osmium::Relation & | get_relation (size_t offset) const
const osmium::Relation & | get_relation (const RelationMeta &relation_meta) const
osmium::OSMObject & | get_member (size_t offset) const

## Private Types

typedef std::function< void(osmium::memory::Buffer &&)> | callback_func_type

## Private Member Functions

void | add_relation (const osmium::Relation &relation)
void | sort_member_meta ()
bool | find_and_add_object (const osmium::OSMObject &object)
void | clear_member_metas (const osmium::relations::RelationMeta &relation_meta)

## Private Attributes

HandlerPass2 | m_handler_pass2
osmium::memory::Buffer | m_relations_buffer
osmium::memory::Buffer | m_members_buffer
std::vector< RelationMeta > | m_relations
| Vector with all relations we are interested in. More...
std::vector< MemberMeta > | m_member_meta [3]
int | m_count_complete = 0
callback_func_type | m_callback

## Static Private Attributes

static constexpr size_t | initial_buffer_size = 1024 * 1024

## Detailed Description

### template<typename TCollector, bool TNodes, bool TWays, bool TRelations>
class osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >

The Collector class collects members of a relation. This is a generic base class that can be used to assemble all kinds of relations. It has numerous hooks you can implement in derived classes to customize its behaviour.

The collector provides two handlers (HandlerPass1 and HandlerPass2) for a first and second pass through an input file, respectively. In the first pass all relations we are interested in are stored in RelationMeta objects in the m_relations vector. All members we are interested in are stored in MemberMeta objects in the m_member_meta vectors. The MemberMeta objects also store the information where the relations containing those members are to be found.

Later the m_member_meta vectors are sorted according to the member ids so that a binary search (with std::equal_range) can be used in the second pass to find the parent relations for each node, way, or relation coming along. The member objects are stored together with their relation and once a relation is complete the complete_relation() method is called which you must overwrite in a derived class of Collector.

Template Parameters

  TCollector | Derived class of this class.
  TNodes | Are we interested in member nodes?
  TWays | Are we interested in member ways?
  TRelations | Are we interested in member relations?

## Member Typedef Documentation

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

typedef std::function<void(osmium::memory::Buffer&&)> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::callback_func_type

private

## Constructor & Destructor Documentation

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::Collector | ( |  | ) |

inline

Create an Collector.

## Member Function Documentation

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::add_relation | ( | const osmium::Relation & | relation | ) |

inline private

Tell the Collector that you are interested in this relation and want it kept until all members have been assembled and it is handed back to you.

The relation is copied and stored in a buffer inside the collector.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

callback_func_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::callback | ( |  | ) |

inline protected

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::clean_assembled_relations | ( |  | ) |

inline protected

This removes all relations that have already been assembled from the m_relations vector.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::clear_member_metas | ( | const osmium::relations::RelationMeta & | relation_meta | ) |

inline private

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::find_and_add_object | ( | const osmium::OSMObject & | object | ) |

inline private

Find this object in the member vectors and add it to all relations that need it.

Returns
  true if the member was added to at least one relation and false otherwise

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::flush | ( |  | ) |

inline protected

This method is called from the 2nd pass handler when all objects of types we are interested in have been seen.

Overwrite this method in a child class if you are interested in this.

Note that even after this call members might be missing if they were not in the input file! The derived class has to handle this case.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

std::vector<const osmium::Relation*> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_incomplete_relations | ( |  | ) | const

inline

Get a vector with pointers to all Relations that could not be completed, because members were missing in the input data.

Note that these pointers point into memory allocated and owned by the Collector object.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

osmium::OSMObject& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_member | ( | size_t | offset | ) | const

inline protected

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

size_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_offset | ( | osmium::item_type | type,
|  | osmium::object_id_type | id
| ) |  |

inline

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

const osmium::Relation& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation | ( | size_t | offset | ) | const

inline protected

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

const osmium::Relation& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation | ( | const RelationMeta & | relation_meta | ) | const

inline protected

Get the relation from a relation_meta.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

HandlerPass2& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::handler | ( | const callback_func_type & | callback = `nullptr` | ) |

inline

Return reference to second pass handler.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::keep_member | ( | const osmium::relations::RelationMeta & | ,
|  | const osmium::RelationMember & |
| ) |  | const

inline protected

This method is called for every member of every relation that should be kept. It should decide if the member is interesting or not and return true or false to signal that. Only interesting members are later added to the relation.

Overwrite this method in a child class. In the MultiPolygonCollector this is for instance used to only keep members of type way and ignore all others.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::keep_relation | ( | const osmium::Relation & |  | ) | const

inline protected

This method is called from the first pass handler for every relation in the input, to check whether it should be kept.

Overwrite this method in a child class to only add relations you are interested in, for instance depending on the type tag. Storing relations takes a lot of memory, so it makes sense to filter this as much as possible.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

std::vector<MemberMeta>& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::member_meta | ( | const item_type | type | ) |

inline protected

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

osmium::memory::Buffer& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::members_buffer | ( |  | ) |

inline

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::moving_in_buffer | ( | size_t | old_offset,
|  | size_t | new_offset
| ) |  |

inline

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::node_not_in_any_relation | ( | const osmium::Node & |  | ) |

inline protected

This method is called for all nodes that are not a member of any relation.

Overwrite this method in a child class if you are interested in this.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::possibly_purge_removed_members | ( |  | ) |

inline

Decide whether to purge removed members and then do it.

Currently the purging is done every thousand calls. This could probably be improved upon.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>
template<typename TIter >

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::read_relations | ( | TIter | begin,
|  | TIter | end
| ) |  |

inline

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>
template<typename TSource >

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::read_relations | ( | TSource & | source | ) |

inline

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::relation_not_in_any_relation | ( | const osmium::Relation & |  | ) |

inline protected

This method is called for all relations that are not a member of any relation.

Overwrite this method in a child class if you are interested in this.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

const std::vector<RelationMeta>& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::relations | ( |  | ) | const

inline protected

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::sort_member_meta | ( |  | ) |

inline private

Sort the vectors with the member infos so that we can do binary search on them.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

uint64_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::used_memory | ( |  | ) | const

inline

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::way_not_in_any_relation | ( | const osmium::Way & |  | ) |

inline protected

This method is called for all ways that are not a member of any relation.

Overwrite this method in a child class if you are interested in this.

## Member Data Documentation

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

constexpr size_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::initial_buffer_size = 1024 * 1024

static private

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

callback_func_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_callback

private

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

int osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_count_complete = 0

private

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

HandlerPass2 osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_handler_pass2

private

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

std::vector<MemberMeta> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_member_meta[3]

private

One vector each for nodes, ways, and relations containing all mappings from member ids to their relations.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

osmium::memory::Buffer osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_members_buffer

private

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

std::vector<RelationMeta> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_relations

private

Vector with all relations we are interested in.

template<typename TCollector, bool TNodes, bool TWays, bool TRelations>

osmium::memory::Buffer osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_relations_buffer

private

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

- osmium/relations/collector.hpp