Skip to content

Commit 0e2e9d6

Browse files
committed
Add infrastructure for asking outputs for their requirements
Outputs are now able to set the requirements they have based on their configuration. The requirements are queried and communicated to the middle which can change its configuration based on that.
1 parent ae20974 commit 0e2e9d6

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

src/middle.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "thread-pool.hpp"
1919

2020
class options_t;
21+
struct output_requirements;
2122

2223
/**
2324
* Interface for returning information about raw OSM input data from a cache.
@@ -107,6 +108,8 @@ struct middle_t
107108
virtual idlist_t get_rels_by_way(osmid_t) { return {}; }
108109

109110
virtual std::shared_ptr<middle_query_t> get_query_instance() = 0;
111+
112+
virtual void set_requirements(output_requirements const &) {}
110113
};
111114

112115
inline middle_t::~middle_t() = default;

src/options.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ struct database_options_t
4343
std::string conninfo() const;
4444
};
4545

46+
/**
47+
* Outputs can signal their requirements to the middle by setting these fields.
48+
*/
49+
struct output_requirements
50+
{
51+
/**
52+
* Need full node objects with tags, attributes (only if --extra-attributes
53+
* is set) and locations. If false, only node locations are needed.
54+
*/
55+
bool full_nodes = false;
56+
57+
/**
58+
* Need full way objects with tags, attributes (only if --extra-attributes
59+
* is set) and way nodes. If false, only way nodes are needed.
60+
*/
61+
bool full_ways = false;
62+
63+
/**
64+
* Need full relation objects with tags, attributes (only if
65+
* --extra-attributes is set) and members. If false, no data from relations
66+
* is needed.
67+
*/
68+
bool full_relations = false;
69+
};
70+
4671
/**
4772
* Structure for storing command-line and other options
4873
*/

src/osm2pgsql.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static void run(options_t const &options)
3535
auto output =
3636
output_t::create_output(middle->get_query_instance(), options);
3737

38+
middle->set_requirements(output->get_requirements());
39+
3840
auto dependency_manager = std::unique_ptr<dependency_manager_t>(
3941
options.with_forward_dependencies
4042
? new full_dependency_manager_t{middle}

src/output-flex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,13 @@ output_flex_t::output_flex_t(
14021402

14031403
if (!is_clone) {
14041404
init_lua(m_options.style);
1405+
1406+
// If the osm2pgsql.select_relation_members() Lua function is defined
1407+
// it means we need two-stage processing which in turn means we need
1408+
// the full ways stored in the middle.
1409+
if (m_select_relation_members) {
1410+
m_output_requirements.full_ways = true;
1411+
}
14051412
}
14061413

14071414
if (m_tables->empty()) {

src/output.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ class output_t
7777

7878
virtual void merge_expire_trees(output_t *other);
7979

80+
struct output_requirements const &get_requirements() const noexcept
81+
{
82+
return m_output_requirements;
83+
}
84+
8085
protected:
8186
std::shared_ptr<middle_query_t> m_mid;
8287
const options_t m_options;
88+
output_requirements m_output_requirements{};
8389
};
8490

8591
#endif // OSM2PGSQL_OUTPUT_HPP

tests/common-import.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class import_t
148148
auto output =
149149
output_t::create_output(middle->get_query_instance(), options);
150150

151+
middle->set_requirements(output->get_requirements());
152+
151153
auto dependency_manager = std::unique_ptr<dependency_manager_t>(
152154
options.with_forward_dependencies
153155
? new full_dependency_manager_t{middle}
@@ -183,6 +185,8 @@ class import_t
183185
auto output =
184186
output_t::create_output(middle->get_query_instance(), options);
185187

188+
middle->set_requirements(output->get_requirements());
189+
186190
auto dependency_manager = std::unique_ptr<dependency_manager_t>(
187191
new full_dependency_manager_t{middle});
188192

0 commit comments

Comments
 (0)