Skip to content

Commit d34b7a2

Browse files
authored
Merge pull request #1176 from joto/refactor-pending-processor
Refactor pending processor
2 parents a09e9f5 + 60e61f2 commit d34b7a2

14 files changed

+210
-299
lines changed

src/dependency-manager.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#include "dependency-manager.hpp"
3+
#include "middle.hpp"
34

45
void full_dependency_manager_t::node_changed(osmid_t id)
56
{
@@ -43,18 +44,15 @@ bool full_dependency_manager_t::has_pending() const noexcept
4344
return !m_ways_pending_tracker.empty() || !m_rels_pending_tracker.empty();
4445
}
4546

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

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

59-
proc.process_relations();
57+
return list;
6058
}

src/dependency-manager.hpp

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22
#define OSM2PGSQL_DEPENDENCY_MANAGER_HPP
33

44
#include "id-tracker.hpp"
5-
#include "middle.hpp"
65
#include "osmtypes.hpp"
76

87
#include <cassert>
98
#include <memory>
109

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-
};
10+
struct middle_t;
2111

2212
/**
2313
* The job of the dependency manager is to keep track of the dependencies
@@ -69,23 +59,24 @@ class dependency_manager_t
6959
virtual bool has_pending() const noexcept { return false; }
7060

7161
/**
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()
62+
* Get the list of pending way ids. After calling this, the internal
63+
* list is cleared.
7864
*/
79-
virtual void process_pending(pending_processor &) {}
65+
virtual idlist_t get_pending_way_ids() { return {}; }
66+
67+
/**
68+
* Get the list of pending relation ids. After calling this, the internal
69+
* list is cleared.
70+
*/
71+
virtual idlist_t get_pending_relation_ids() { return {}; }
8072
};
8173

8274
/**
8375
* The job of the dependency manager is to keep track of the dependencies
8476
* between OSM objects, that is nodes in ways and members of relations.
8577
*
8678
* 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.
79+
* the ids for later use.
8980
*/
9081
class full_dependency_manager_t : public dependency_manager_t
9182
{
@@ -111,49 +102,19 @@ class full_dependency_manager_t : public dependency_manager_t
111102

112103
bool has_pending() const noexcept override;
113104

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)
105+
idlist_t get_pending_way_ids() override
129106
{
130-
osmid_t id;
131-
while (id_tracker::is_valid(id = m_ways_pending_tracker.pop_mark())) {
132-
*it++ = id;
133-
}
107+
return get_ids(m_ways_pending_tracker);
134108
}
135109

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)
110+
idlist_t get_pending_relation_ids() override
149111
{
150-
osmid_t id;
151-
while (id_tracker::is_valid(id = m_rels_pending_tracker.pop_mark())) {
152-
*it++ = id;
153-
}
112+
return get_ids(m_rels_pending_tracker);
154113
}
155114

156115
private:
116+
static idlist_t get_ids(id_tracker &tracker);
117+
157118
std::shared_ptr<middle_t> m_object_store;
158119

159120
id_tracker m_ways_pending_tracker;

0 commit comments

Comments
 (0)