Skip to content

Commit 0952b98

Browse files
authored
Merge pull request #1192 from joto/get-options-into-osmdata
Get options into osmdata
2 parents b7ca67c + 813d287 commit 0952b98

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/osm2pgsql.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ int main(int argc, char *argv[])
7373
need_dependencies ? new full_dependency_manager_t{middle}
7474
: new dependency_manager_t{});
7575

76-
osmdata_t osmdata{std::move(dependency_manager), middle, outputs};
76+
osmdata_t osmdata{std::move(dependency_manager), middle, outputs,
77+
options};
7778

7879
fmt::print(stderr, "Using projection SRS {} ({})\n",
7980
options.projection->target_srs(),

src/osmdata.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@
1313
#include "db-copy.hpp"
1414
#include "format.hpp"
1515
#include "middle.hpp"
16+
#include "options.hpp"
1617
#include "osmdata.hpp"
1718
#include "output.hpp"
1819
#include "util.hpp"
1920

2021
osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
2122
std::shared_ptr<middle_t> mid,
22-
std::vector<std::shared_ptr<output_t>> outs)
23+
std::vector<std::shared_ptr<output_t>> outs,
24+
options_t const &options)
2325
: m_dependency_manager(std::move(dependency_manager)), m_mid(std::move(mid)),
24-
m_outs(std::move(outs))
26+
m_outs(std::move(outs)), m_conninfo(options.database_options.conninfo()),
27+
m_num_procs(options.num_procs), m_append(options.append),
28+
m_droptemp(options.droptemp), m_parallel_indexing(options.parallel_indexing),
29+
m_with_extra_attrs(options.extra_attributes)
2530
{
2631
assert(m_dependency_manager);
2732
assert(m_mid);
2833
assert(!m_outs.empty());
29-
30-
// Get the "extra_attributes" option from the first output. We expect
31-
// all others to be the same.
32-
m_with_extra_attrs = m_outs[0]->get_options()->extra_attributes;
3334
}
3435

3536
/**
@@ -377,14 +378,11 @@ void osmdata_t::stop() const
377378
out->sync();
378379
}
379380

380-
// should be the same for all outputs
381-
auto const *opts = m_outs[0]->get_options();
382-
383381
// In append mode there might be dependent objects pending that we
384382
// need to process.
385-
if (opts->append && m_dependency_manager->has_pending()) {
386-
multithreaded_processor proc{opts->database_options.conninfo(), m_mid,
387-
m_outs, (std::size_t)opts->num_procs};
383+
if (m_append && m_dependency_manager->has_pending()) {
384+
multithreaded_processor proc{m_conninfo, m_mid, m_outs,
385+
(std::size_t)m_num_procs};
388386

389387
proc.process_ways(m_dependency_manager->get_pending_way_ids());
390388
proc.process_relations(
@@ -399,10 +397,9 @@ void osmdata_t::stop() const
399397
// Clustering, index creation, and cleanup.
400398
// All the intensive parts of this are long-running PostgreSQL commands
401399
{
402-
osmium::thread::Pool pool{opts->parallel_indexing ? opts->num_procs : 1,
403-
512};
400+
osmium::thread::Pool pool{m_parallel_indexing ? m_num_procs : 1, 512};
404401

405-
if (opts->droptemp) {
402+
if (m_droptemp) {
406403
// When dropping middle tables, make sure they are gone before
407404
// indexing starts.
408405
m_mid->stop(pool);
@@ -412,7 +409,7 @@ void osmdata_t::stop() const
412409
out->stop(&pool);
413410
}
414411

415-
if (!opts->droptemp) {
412+
if (!m_droptemp) {
416413
// When keeping middle tables, there is quite a large index created
417414
// which is better done after the output tables have been copied.
418415
// Note that --disable-parallel-indexing needs to be used to really

src/osmdata.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "dependency-manager.hpp"
88
#include "osmtypes.hpp"
99

10+
class options_t;
1011
class output_t;
1112
struct middle_t;
1213
struct slim_middle_t;
@@ -16,7 +17,8 @@ class osmdata_t
1617
public:
1718
osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
1819
std::shared_ptr<middle_t> mid,
19-
std::vector<std::shared_ptr<output_t>> outs);
20+
std::vector<std::shared_ptr<output_t>> outs,
21+
options_t const &options);
2022

2123
void start() const;
2224
void flush() const;
@@ -40,7 +42,14 @@ class osmdata_t
4042
std::unique_ptr<dependency_manager_t> m_dependency_manager;
4143
std::shared_ptr<middle_t> m_mid;
4244
std::vector<std::shared_ptr<output_t>> m_outs;
45+
46+
std::string m_conninfo;
47+
int m_num_procs;
48+
bool m_append;
49+
bool m_droptemp;
50+
bool m_parallel_indexing;
4351
bool m_with_extra_attrs;
52+
4453
};
4554

4655
#endif // OSM2PGSQL_OSMDATA_HPP

tests/common-import.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inline void parse_file(options_t const &options,
2727
std::vector<std::shared_ptr<output_t>> const &outs,
2828
char const *filename = nullptr)
2929
{
30-
osmdata_t osmdata{std::move(dependency_manager), mid, outs};
30+
osmdata_t osmdata{std::move(dependency_manager), mid, outs, options};
3131

3232
osmdata.start();
3333
parse_osmium_t parser{options.bbox, options.append, &osmdata};
@@ -91,7 +91,8 @@ class import_t
9191
need_dependencies ? new full_dependency_manager_t{middle}
9292
: new dependency_manager_t{});
9393

94-
osmdata_t osmdata{std::move(dependency_manager), middle, outputs};
94+
osmdata_t osmdata{std::move(dependency_manager), middle, outputs,
95+
options};
9596

9697
osmdata.start();
9798

0 commit comments

Comments
 (0)