Skip to content

Commit 90b674a

Browse files
committed
Use osmium::nwr_array in middle-pgsql
1 parent 989f490 commit 90b674a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/middle-pgsql.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void middle_pgsql_t::node_set(osmium::Node const &node)
340340
if (!m_options->flat_node_file.empty()) {
341341
m_persistent_cache->set(node.id(), node.location());
342342
} else {
343-
m_db_copy.new_line(m_tables[NODE_TABLE].copy_target());
343+
m_db_copy.new_line(m_tables(osmium::item_type::node).copy_target());
344344

345345
m_db_copy.add_columns(node.id(), node.location().y(),
346346
node.location().x());
@@ -381,7 +381,7 @@ void middle_pgsql_t::node_delete(osmid_t osm_id)
381381
if (!m_options->flat_node_file.empty()) {
382382
m_persistent_cache->set(osm_id, osmium::Location{});
383383
} else {
384-
m_db_copy.new_line(m_tables[NODE_TABLE].copy_target());
384+
m_db_copy.new_line(m_tables(osmium::item_type::node).copy_target());
385385
m_db_copy.delete_object(osm_id);
386386
}
387387
}
@@ -403,7 +403,7 @@ idlist_t middle_pgsql_t::get_rels_by_way(osmid_t osm_id)
403403

404404
void middle_pgsql_t::way_set(osmium::Way const &way)
405405
{
406-
m_db_copy.new_line(m_tables[WAY_TABLE].copy_target());
406+
m_db_copy.new_line(m_tables(osmium::item_type::way).copy_target());
407407

408408
m_db_copy.add_column(way.id());
409409

@@ -494,7 +494,7 @@ middle_query_pgsql_t::rel_way_members_get(osmium::Relation const &rel,
494494
void middle_pgsql_t::way_delete(osmid_t osm_id)
495495
{
496496
assert(m_options->append);
497-
m_db_copy.new_line(m_tables[WAY_TABLE].copy_target());
497+
m_db_copy.new_line(m_tables(osmium::item_type::way).copy_target());
498498
m_db_copy.delete_object(osm_id);
499499
}
500500

@@ -507,7 +507,7 @@ void middle_pgsql_t::relation_set(osmium::Relation const &rel)
507507
parts[osmium::item_type_to_nwr_index(m.type())].push_back(m.ref());
508508
}
509509

510-
m_db_copy.new_line(m_tables[REL_TABLE].copy_target());
510+
m_db_copy.new_line(m_tables(osmium::item_type::relation).copy_target());
511511

512512
// id, way offset, relation offset
513513
m_db_copy.add_columns(rel.id(), parts[0].size(),
@@ -568,30 +568,30 @@ void middle_pgsql_t::relation_delete(osmid_t osm_id)
568568
{
569569
assert(m_options->append);
570570

571-
m_db_copy.new_line(m_tables[REL_TABLE].copy_target());
571+
m_db_copy.new_line(m_tables(osmium::item_type::relation).copy_target());
572572
m_db_copy.delete_object(osm_id);
573573
}
574574

575575
void middle_pgsql_t::after_nodes()
576576
{
577577
m_db_copy.sync();
578578
if (m_options->flat_node_file.empty()) {
579-
auto const &table = m_tables[NODE_TABLE];
579+
auto const &table = m_tables(osmium::item_type::node);
580580
analyze_table(m_db_connection, table.schema(), table.name());
581581
}
582582
}
583583

584584
void middle_pgsql_t::after_ways()
585585
{
586586
m_db_copy.sync();
587-
auto const &table = m_tables[WAY_TABLE];
587+
auto const &table = m_tables(osmium::item_type::way);
588588
analyze_table(m_db_connection, table.schema(), table.name());
589589
}
590590

591591
void middle_pgsql_t::after_relations()
592592
{
593593
m_db_copy.sync();
594-
auto const &table = m_tables[REL_TABLE];
594+
auto const &table = m_tables(osmium::item_type::relation);
595595
analyze_table(m_db_connection, table.schema(), table.name());
596596

597597
// release the copy thread and its database connection
@@ -804,12 +804,13 @@ middle_pgsql_t::middle_pgsql_t(options_t const *options)
804804
log_debug("You don't have a bucket index. See manual for details.");
805805
}
806806

807-
m_tables[NODE_TABLE] =
807+
m_tables(osmium::item_type::node) =
808808
table_desc{*options, sql_for_nodes(options->flat_node_file.empty())};
809-
m_tables[WAY_TABLE] =
809+
m_tables(osmium::item_type::way) =
810810
table_desc{*options, sql_for_ways(has_bucket_index,
811811
options->way_node_index_id_shift)};
812-
m_tables[REL_TABLE] = table_desc{*options, sql_for_relations()};
812+
m_tables(osmium::item_type::relation) =
813+
table_desc{*options, sql_for_relations()};
813814
}
814815

815816
std::shared_ptr<middle_query_t>

src/middle-pgsql.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <memory>
1313

14+
#include <osmium/index/nwr_array.hpp>
15+
1416
#include "db-copy-mgr.hpp"
1517
#include "middle.hpp"
1618
#include "node-persistent-cache.hpp"
@@ -109,14 +111,6 @@ struct middle_pgsql_t : public middle_t
109111
std::shared_ptr<middle_query_t> get_query_instance() override;
110112

111113
private:
112-
enum middle_tables
113-
{
114-
NODE_TABLE = 0,
115-
WAY_TABLE,
116-
REL_TABLE,
117-
NUM_TABLES
118-
};
119-
120114
void node_set(osmium::Node const &node);
121115
void node_delete(osmid_t id);
122116

@@ -128,7 +122,7 @@ struct middle_pgsql_t : public middle_t
128122

129123
void buffer_store_tags(osmium::OSMObject const &obj, bool attrs);
130124

131-
table_desc m_tables[NUM_TABLES];
125+
osmium::nwr_array<table_desc> m_tables;
132126

133127
options_t const *m_options;
134128

0 commit comments

Comments
 (0)