1#ifndef OSMIUM_RELATIONS_COLLECTOR_HPP
2#define OSMIUM_RELATIONS_COLLECTOR_HPP
43#include <osmium/relations/detail/member_meta.hpp>
44#include <osmium/relations/detail/relation_meta.hpp>
97 template <
typename TCollector,
bool TNodes,
bool TWays,
bool TRelations>
202 return make_range(std::equal_range(mmv.begin(), mmv.end(), MemberMeta(
id)));
339 RelationMeta relation_meta{offset};
343 if (
static_cast<TCollector*
>(
this)->
keep_member(relation_meta, member)) {
345 relation_meta.increment_need_members();
353 if (relation_meta.has_all_members()) {
372 return std::count_if(range.
begin(), range.
end(), [](
const MemberMeta& mm) {
373 return !mm.removed();
396 for (
auto& member : range) {
397 member.set_buffer_offset(member_offset);
401 for (
auto& member : range) {
402 if (member.removed()) {
405 assert(member.member_id() ==
object.id());
406 assert(member.relation_pos() <
m_relations.size());
407 RelationMeta& relation_meta =
m_relations[member.relation_pos()];
408 assert(member.member_pos() <
get_relation(relation_meta).members().size());
409 relation_meta.got_one_member();
410 if (relation_meta.has_all_members()) {
411 const size_t relation_offset = member.relation_pos();
412 static_cast<TCollector*
>(
this)->complete_relation(relation_meta);
424 for (
const auto& member : relation.members()) {
425 if (member.ref() != 0) {
427 assert(!range.empty());
449 const uint64_t members = nmembers *
sizeof(MemberMeta);
450 const uint64_t relations_size =
m_relations.capacity() *
sizeof(RelationMeta);
454 std::cerr <<
" nR = m_relations.capacity() ........... = " << std::setw(12) <<
m_relations.capacity() <<
"\n";
455 std::cerr <<
" nMN = m_member_meta[NODE].capacity() ... = " << std::setw(12) <<
m_member_meta[0].capacity() <<
"\n";
456 std::cerr <<
" nMW = m_member_meta[WAY].capacity() .... = " << std::setw(12) <<
m_member_meta[1].capacity() <<
"\n";
457 std::cerr <<
" nMR = m_member_meta[RELATION].capacity() = " << std::setw(12) <<
m_member_meta[2].capacity() <<
"\n";
458 std::cerr <<
" nM = m_member_meta[*].capacity() ...... = " << std::setw(12) << nmembers <<
"\n";
460 std::cerr <<
" sRM = sizeof(RelationMeta) ............. = " << std::setw(12) <<
sizeof(RelationMeta) <<
"\n";
461 std::cerr <<
" sMM = sizeof(MemberMeta) ............... = " << std::setw(12) <<
sizeof(MemberMeta) <<
"\n\n";
463 std::cerr <<
" nR * sRM ............................... = " << std::setw(12) << relations_size <<
"\n";
464 std::cerr <<
" nM * sMM ............................... = " << std::setw(12) << members <<
"\n";
465 std::cerr <<
" relations_buffer_capacity .............. = " << std::setw(12) << relations_buffer_capacity <<
"\n";
466 std::cerr <<
" members_buffer_capacity ................ = " << std::setw(12) << members_buffer_capacity <<
"\n";
468 const uint64_t total = relations_size + members + relations_buffer_capacity + members_buffer_capacity;
470 std::cerr <<
" total .................................. = " << std::setw(12) << total <<
"\n";
471 std::cerr <<
" =======================================================\n";
473 return relations_buffer_capacity + members_buffer_capacity + relations_size + members;
501 assert(!range.empty());
502 return range.begin()->is_available();
516 assert(!range.empty());
517 assert(range.begin()->is_available());
518 return range.begin()->buffer_offset();
539 assert(!range.empty());
540 if (range.begin()->is_available()) {
541 return std::make_pair(
true, range.begin()->buffer_offset());
543 return std::make_pair(
false, 0);
546 template <
typename TIter>
548 HandlerPass1 handler_pass1{*
static_cast<TCollector*
>(
this)};
553 template <
typename TSource>
564 for (
auto& member : range) {
565 assert(member.buffer_offset() == old_offset);
566 member.set_buffer_offset(new_offset);
601 std::vector<const osmium::Relation*> incomplete_relations;
603 if (!relation_meta.has_all_members()) {
604 incomplete_relations.push_back(&
get_relation(relation_meta));
607 return incomplete_relations;
Definition: object.hpp:64
Definition: relation.hpp:56
Definition: relation.hpp:161
RelationMemberList & members()
Get a reference to the member list.
Definition: relation.hpp:179
Definition: check_order.hpp:87
void node(const osmium::Node &node)
Definition: check_order.hpp:98
void relation(const osmium::Relation &relation)
Definition: check_order.hpp:139
void way(const osmium::Way &way)
Definition: check_order.hpp:120
Definition: handler.hpp:71
void set_removed(const bool removed) noexcept
Definition: item.hpp:179
Definition: collector.hpp:103
TCollector & m_collector
Definition: collector.hpp:105
HandlerPass1(TCollector &collector) noexcept
Definition: collector.hpp:109
void relation(const osmium::Relation &relation)
Definition: collector.hpp:113
Definition: collector.hpp:126
void flush()
Definition: collector.hpp:164
osmium::handler::CheckOrder m_check_order
Definition: collector.hpp:128
HandlerPass2(TCollector &collector) noexcept
Definition: collector.hpp:133
void way(const osmium::Way &way)
Definition: collector.hpp:146
TCollector & m_collector
Definition: collector.hpp:129
void relation(const osmium::Relation &relation)
Definition: collector.hpp:155
void node(const osmium::Node &node)
Definition: collector.hpp:137
Definition: collector.hpp:98
osmium::memory::Buffer & members_buffer()
Definition: collector.hpp:484
callback_func_type m_callback
Definition: collector.hpp:194
const osmium::Relation & get_relation(size_t offset) const
Definition: collector.hpp:301
void clear_member_metas(const RelationMeta &relation_meta)
Definition: collector.hpp:422
Collector()
Definition: collector.hpp:210
HandlerPass2 & handler(const callback_func_type &callback=nullptr)
Definition: collector.hpp:479
void sort_member_meta()
Definition: collector.hpp:365
void add_relation(const osmium::Relation &relation)
Definition: collector.hpp:335
const std::vector< RelationMeta > & relations() const
Definition: collector.hpp:226
osmium::OSMObject & get_member(size_t offset) const
Definition: collector.hpp:320
std::vector< MemberMeta > & member_meta(const item_type type)
Definition: collector.hpp:218
size_t get_offset(osmium::item_type type, osmium::object_id_type id)
Definition: collector.hpp:514
uint64_t used_memory() const
Definition: collector.hpp:447
std::vector< RelationMeta > m_relations
Vector with all relations we are interested in.
Definition: collector.hpp:181
void way_not_in_any_relation(const osmium::Way &)
Definition: collector.hpp:274
void flush()
Definition: collector.hpp:298
callback_func_type callback()
Definition: collector.hpp:222
void relation_not_in_any_relation(const osmium::Relation &)
Definition: collector.hpp:284
const osmium::Relation & get_relation(const MemberMeta &member_meta) const
Definition: collector.hpp:316
@ initial_buffer_size
Definition: collector.hpp:197
mm_vector_type::iterator mm_iterator
Definition: collector.hpp:188
bool is_available(osmium::item_type type, osmium::object_id_type id)
Definition: collector.hpp:499
osmium::memory::Buffer m_members_buffer
Definition: collector.hpp:178
bool find_and_add_object(const osmium::OSMObject &object)
Definition: collector.hpp:384
std::pair< bool, size_t > get_availability_and_offset(osmium::item_type type, osmium::object_id_type id)
Definition: collector.hpp:537
bool keep_member(const RelationMeta &, const osmium::RelationMember &) const
Definition: collector.hpp:253
std::vector< const osmium::Relation * > get_incomplete_relations() const
Definition: collector.hpp:600
const osmium::Relation & get_relation(const RelationMeta &relation_meta) const
Definition: collector.hpp:309
bool keep_relation(const osmium::Relation &) const
Definition: collector.hpp:239
int m_count_complete
Definition: collector.hpp:191
std::function< void(osmium::memory::Buffer &&)> callback_func_type
Definition: collector.hpp:193
void read_relations(TIter begin, TIter end)
Definition: collector.hpp:547
static iterator_range< mm_iterator >::iterator::difference_type count_not_removed(const iterator_range< mm_iterator > &range)
Definition: collector.hpp:371
void moving_in_buffer(size_t old_offset, size_t new_offset)
Definition: collector.hpp:561
void node_not_in_any_relation(const osmium::Node &)
Definition: collector.hpp:264
HandlerPass2 m_handler_pass2
Definition: collector.hpp:172
void possibly_purge_removed_members()
Definition: collector.hpp:576
osmium::memory::Buffer m_relations_buffer
Definition: collector.hpp:175
std::vector< MemberMeta > mm_vector_type
Definition: collector.hpp:187
std::array< mm_vector_type, 3 > m_member_meta
Definition: collector.hpp:189
iterator_range< mm_iterator > find_member_meta(osmium::item_type type, osmium::object_id_type id)
Definition: collector.hpp:200
void read_relations(TSource &source)
Definition: collector.hpp:554
InputIterator< Reader > end(Reader &)
Definition: reader_iterator.hpp:47
InputIterator< Reader > begin(Reader &reader)
Definition: reader_iterator.hpp:43
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition: visitor.hpp:326
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
item_type
Definition: item_type.hpp:45
iterator_range< It > make_range(P &&p) noexcept
Definition: iterator.hpp:68
Definition: iterator.hpp:42
It begin() const noexcept
Definition: iterator.hpp:50
It end() const noexcept
Definition: iterator.hpp:54