Skip to content

Commit e602c5c

Browse files
committed
Disentangle processor from dependency manager
1 parent a9a10e6 commit e602c5c

File tree

4 files changed

+38
-85
lines changed

4 files changed

+38
-85
lines changed

src/dependency-manager.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@ bool full_dependency_manager_t::has_pending() const noexcept
4343
return !m_ways_pending_tracker.empty() || !m_rels_pending_tracker.empty();
4444
}
4545

46-
void full_dependency_manager_t::process_pending(pending_processor &proc)
47-
{
48-
osmid_t id;
49-
while (id_tracker::is_valid(id = m_ways_pending_tracker.pop_mark())) {
50-
proc.enqueue_way(id);
51-
}
46+
idlist_t full_dependency_manager_t::get_ids(id_tracker& tracker) {
47+
idlist_t list;
48+
list.reserve(tracker.size());
5249

53-
proc.process_ways();
54-
55-
while (id_tracker::is_valid(id = m_rels_pending_tracker.pop_mark())) {
56-
proc.enqueue_relation(id);
50+
osmid_t id;
51+
while (id_tracker::is_valid(id = tracker.pop_mark())) {
52+
list.push_back(id);
5753
}
5854

59-
proc.process_relations();
55+
return list;
6056
}

src/dependency-manager.hpp

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88
#include <cassert>
99
#include <memory>
1010

11-
struct pending_processor
12-
{
13-
virtual ~pending_processor() = default;
14-
15-
virtual void enqueue_way(osmid_t id) = 0;
16-
virtual void enqueue_relation(osmid_t id) = 0;
17-
18-
virtual void process_ways() = 0;
19-
virtual void process_relations() = 0;
20-
};
21-
2211
/**
2312
* The job of the dependency manager is to keep track of the dependencies
2413
* between OSM objects, that is nodes in ways and members of relations.
@@ -69,23 +58,24 @@ class dependency_manager_t
6958
virtual bool has_pending() const noexcept { return false; }
7059

7160
/**
72-
* Process all pending objects.
73-
*
74-
* \param pf Processor that we should feed the objects to and that
75-
* will handle the actual processing.
76-
*
77-
* \post !has_pending()
61+
* Get the list of pending way ids. After calling this, the internal
62+
* list is cleared.
7863
*/
79-
virtual void process_pending(pending_processor &) {}
64+
virtual idlist_t get_pending_way_ids() { return {}; }
65+
66+
/**
67+
* Get the list of pending relation ids. After calling this, the internal
68+
* list is cleared.
69+
*/
70+
virtual idlist_t get_pending_relation_ids() { return {}; }
8071
};
8172

8273
/**
8374
* The job of the dependency manager is to keep track of the dependencies
8475
* between OSM objects, that is nodes in ways and members of relations.
8576
*
8677
* Whenever an OSM object changes, this class is notified and remembers
87-
* the ids for later use. Later on the class can be told to process the
88-
* ids it has remembered.
78+
* the ids for later use.
8979
*/
9080
class full_dependency_manager_t : public dependency_manager_t
9181
{
@@ -111,49 +101,19 @@ class full_dependency_manager_t : public dependency_manager_t
111101

112102
bool has_pending() const noexcept override;
113103

114-
void process_pending(pending_processor &proc) override;
115-
116-
/**
117-
* Get access to the pending way ids. This is for debugging only.
118-
*
119-
* Note that the list of pending way ids will be empty after calling
120-
* this.
121-
*
122-
* \tparam TOutputIterator Some output iterator type, for instance
123-
* created with std::back_inserter(some vector).
124-
* \param it output iterator to which all ids should be written. *it
125-
* must be of type osmid_t.
126-
*/
127-
template <typename TOutputIterator>
128-
void get_pending_way_ids(TOutputIterator &&it)
104+
idlist_t get_pending_way_ids() override
129105
{
130-
osmid_t id;
131-
while (id_tracker::is_valid(id = m_ways_pending_tracker.pop_mark())) {
132-
*it++ = id;
133-
}
106+
return get_ids(m_ways_pending_tracker);
134107
}
135108

136-
/**
137-
* Get access to the pending relation ids. This is for debugging only.
138-
*
139-
* Note that the list of pending relation ids will be empty after calling
140-
* this.
141-
*
142-
* \tparam TOutputIterator Some output iterator type, for instance
143-
* created with std::back_inserter(some vector).
144-
* \param it output iterator to which all ids should be written. *it
145-
* must be of type osmid_t.
146-
*/
147-
template <typename TOutputIterator>
148-
void get_pending_relation_ids(TOutputIterator &&it)
109+
idlist_t get_pending_relation_ids() override
149110
{
150-
osmid_t id;
151-
while (id_tracker::is_valid(id = m_rels_pending_tracker.pop_mark())) {
152-
*it++ = id;
153-
}
111+
return get_ids(m_rels_pending_tracker);
154112
}
155113

156114
private:
115+
idlist_t get_ids(id_tracker& tracker);
116+
157117
std::shared_ptr<middle_t> m_object_store;
158118

159119
id_tracker m_ways_pending_tracker;

src/osmdata.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void osmdata_t::flush() const
162162

163163
namespace {
164164

165-
struct pending_threaded_processor : public pending_processor
165+
struct pending_threaded_processor
166166
{
167167
using output_vec_t = std::vector<std::shared_ptr<output_t>>;
168168
using pending_queue_t = idlist_t;
@@ -244,10 +244,6 @@ struct pending_threaded_processor : public pending_processor
244244
}
245245
}
246246

247-
void enqueue_way(osmid_t id) override { m_queue.push_back(id); }
248-
249-
void enqueue_relation(osmid_t id) override { m_queue.push_back(id); }
250-
251247
template <typename FUNCTION>
252248
void process_queue(char const *type, FUNCTION &&function)
253249
{
@@ -301,10 +297,15 @@ struct pending_threaded_processor : public pending_processor
301297
}
302298
}
303299

304-
void process_ways() override { process_queue("way", do_ways); }
300+
void process_ways(idlist_t &&list)
301+
{
302+
m_queue = std::move(list);
303+
process_queue("way", do_ways);
304+
}
305305

306-
void process_relations() override
306+
void process_relations(idlist_t &&list)
307307
{
308+
m_queue = std::move(list);
308309
process_queue("relation", do_rels);
309310

310311
// Collect expiry tree information from all clones and merge it back
@@ -357,7 +358,8 @@ void osmdata_t::stop() const
357358
if (opts->append && m_dependency_manager->has_pending()) {
358359
pending_threaded_processor ptp(m_mid, m_outs, opts->num_procs);
359360

360-
m_dependency_manager->process_pending(ptp);
361+
ptp.process_ways(m_dependency_manager->get_pending_way_ids());
362+
ptp.process_relations(m_dependency_manager->get_pending_relation_ids());
361363
}
362364

363365
for (auto &out : m_outs) {

tests/test-middle.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10711071
mid->flush();
10721072

10731073
REQUIRE(dependency_manager.has_pending());
1074-
idlist_t way_ids;
1075-
dependency_manager.get_pending_way_ids(std::back_inserter(way_ids));
1074+
idlist_t const way_ids = dependency_manager.get_pending_way_ids();
10761075
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20}));
10771076

10781077
check_way(mid, way20);
@@ -1104,8 +1103,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11041103
mid->flush();
11051104

11061105
REQUIRE(dependency_manager.has_pending());
1107-
idlist_t way_ids;
1108-
dependency_manager.get_pending_way_ids(std::back_inserter(way_ids));
1106+
idlist_t const way_ids = dependency_manager.get_pending_way_ids();
11091107
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20, 22}));
11101108

11111109
check_way(mid, way20);
@@ -1207,8 +1205,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12071205
mid->flush();
12081206

12091207
REQUIRE(dependency_manager.has_pending());
1210-
idlist_t rel_ids;
1211-
dependency_manager.get_pending_relation_ids(std::back_inserter(rel_ids));
1208+
idlist_t const rel_ids = dependency_manager.get_pending_relation_ids();
12121209

12131210
REQUIRE_THAT(rel_ids, Catch::Equals<osmid_t>({30}));
12141211
check_relation(mid, rel30);
@@ -1228,11 +1225,9 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12281225
mid->flush();
12291226

12301227
REQUIRE(dependency_manager.has_pending());
1231-
idlist_t way_ids;
1232-
dependency_manager.get_pending_way_ids(std::back_inserter(way_ids));
1228+
idlist_t const way_ids = dependency_manager.get_pending_way_ids();
12331229
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20}));
1234-
idlist_t rel_ids;
1235-
dependency_manager.get_pending_relation_ids(std::back_inserter(rel_ids));
1230+
idlist_t const rel_ids = dependency_manager.get_pending_relation_ids();
12361231
REQUIRE_THAT(rel_ids, Catch::Equals<osmid_t>({31}));
12371232
check_relation(mid, rel31);
12381233
}

0 commit comments

Comments
 (0)