1#ifndef OSMIUM_RELATIONS_MEMBERS_DATABASE_HPP
2#define OSMIUM_RELATIONS_MEMBERS_DATABASE_HPP
126 std::tie(other.member_id, other.member_num, other.relation_pos);
134 return a.member_id < b.member_id;
163 return std::count_if(range.begin(), range.end(), [](
const element& elem) {
164 return !elem.is_removed();
170 for (
auto& elem : range) {
171 elem.object_handle = handle;
199 std::size_t
size() const noexcept {
225 if (elem.is_removed()) {
227 }
else if (elem.object_handle.valid()) {
247 assert(
m_init_phase &&
"Can not call MembersDatabase::track() after MembersDatabase::prepare_for_lookup().");
249 m_elements.emplace_back(rel_handle.
pos(), member_id, member_num);
260 assert(
m_init_phase &&
"Can not call MembersDatabase::prepare_for_lookup() twice.");
274 assert(!
m_init_phase &&
"Call MembersDatabase::prepare_for_lookup() before calling remove().");
275 const auto range =
find(member_id);
287 for (
auto& elem : range) {
288 if (!elem.is_removed() && relation_id ==
m_relations_db[elem.relation_pos]->id()) {
306 assert(!
m_init_phase &&
"Call MembersDatabase::prepare_for_lookup() before calling get_object().");
307 const auto range =
find(
id);
311 const auto handle = range.begin()->object_handle;
312 if (handle.valid()) {
332 template <
typename TObject>
363 template <
typename TFunc>
364 bool add(
const TObject&
object, TFunc&& func) {
365 assert(!
m_init_phase &&
"Call MembersDatabase::prepare_for_lookup() before calling add().");
366 auto range =
find(
object.
id());
377 for (
auto& elem : range) {
378 assert(!elem.is_removed());
379 assert(elem.member_id ==
object.id());
382 assert(elem.member_num < rel_handle->members().size());
383 rel_handle.decrement_members();
385 if (rel_handle.has_all_members()) {
404 assert(!
m_init_phase &&
"Call MembersDatabase::prepare_for_lookup() before calling get().");
405 return static_cast<const TObject*
>(
get_object(
id));
Definition: item_stash.hpp:71
Definition: item_stash.hpp:57
T & get(handle_type handle) const
Definition: item_stash.hpp:294
void remove_item(handle_type handle)
Definition: item_stash.hpp:338
handle_type add_item(const osmium::memory::Item &item)
Definition: item_stash.hpp:251
Definition: object.hpp:64
Definition: members_database.hpp:62
void prepare_for_lookup()
Definition: members_database.hpp:259
std::vector< element > m_elements
Definition: members_database.hpp:138
std::size_t size() const noexcept
Definition: members_database.hpp:199
void track(RelationHandle &rel_handle, osmium::object_id_type member_id, std::size_t member_num)
Definition: members_database.hpp:246
std::vector< element >::const_iterator const_iterator
Definition: members_database.hpp:152
bool m_init_phase
Definition: members_database.hpp:148
static std::iterator_traits< iterator >::difference_type count_not_removed(const iterator_range< iterator > &range) noexcept
Definition: members_database.hpp:162
const osmium::OSMObject * get_object(osmium::object_id_type id) const
Definition: members_database.hpp:305
osmium::relations::RelationsDatabase & m_relations_db
Definition: members_database.hpp:143
void remove(osmium::object_id_type member_id, osmium::object_id_type relation_id)
Definition: members_database.hpp:273
osmium::ItemStash & m_stash
Definition: members_database.hpp:142
std::vector< element >::iterator iterator
Definition: members_database.hpp:151
MembersDatabaseCommon(osmium::ItemStash &stash, osmium::relations::RelationsDatabase &relations_db)
Definition: members_database.hpp:175
counts count() const noexcept
Definition: members_database.hpp:221
std::size_t used_memory() const noexcept
Definition: members_database.hpp:187
void add_object(const osmium::OSMObject &object, iterator_range< iterator > &range)
Definition: members_database.hpp:168
iterator_range< const_iterator > find(osmium::object_id_type id) const
Definition: members_database.hpp:158
iterator_range< iterator > find(osmium::object_id_type id)
Definition: members_database.hpp:154
Definition: members_database.hpp:333
MembersDatabase(osmium::ItemStash &stash, osmium::relations::RelationsDatabase &relation_db)
Definition: members_database.hpp:348
const TObject * get(osmium::object_id_type id) const
Definition: members_database.hpp:403
bool add(const TObject &object, TFunc &&func)
Definition: members_database.hpp:364
Definition: relations_database.hpp:208
std::size_t pos() const noexcept
Definition: relations_database.hpp:238
RelationsDatabase * relation_database() const noexcept
Definition: relations_database.hpp:225
void increment_members() noexcept
Definition: relations_database.hpp:288
Definition: relations_database.hpp:82
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
iterator_range< It > make_range(P &&p) noexcept
Definition: iterator.hpp:68
Definition: iterator.hpp:42
Definition: members_database.hpp:132
bool operator()(const element &a, const element &b) const noexcept
Definition: members_database.hpp:133
Definition: members_database.hpp:206
std::size_t available
The number of members tracked and found already.
Definition: members_database.hpp:210
std::size_t tracked
The number of members tracked and not found yet.
Definition: members_database.hpp:208
std::size_t removed
The number of members that were tracked, found and then removed because of a completed relation.
Definition: members_database.hpp:212
Definition: members_database.hpp:64
bool is_removed() const noexcept
Definition: members_database.hpp:116
void remove() noexcept
Definition: members_database.hpp:120
element(std::size_t rel_pos, osmium::object_id_type memb_id, std::size_t memb_num) noexcept
Definition: members_database.hpp:99
@ removed_value
Definition: members_database.hpp:71
element(osmium::object_id_type m_id) noexcept
Definition: members_database.hpp:110
std::size_t relation_pos
Definition: members_database.hpp:89
osmium::object_id_type member_id
Definition: members_database.hpp:79
bool operator<(const element &other) const noexcept
Definition: members_database.hpp:124
std::size_t member_num
Definition: members_database.hpp:84
osmium::ItemStash::handle_type object_handle
Definition: members_database.hpp:97