Skip to content

Commit 65a9317

Browse files
committed
Make osmid_t a real class
1 parent 3e5daee commit 65a9317

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

src/idlist.hpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,55 @@
1818

1919
#include "osmtypes.hpp"
2020

21+
#include <cassert>
2122
#include <vector>
2223

23-
struct idlist_t : public std::vector<osmid_t>
24+
class idlist_t
2425
{
25-
// Get all constructors from std::vector
26-
using vector<osmid_t>::vector;
26+
public:
27+
using value_type = osmid_t;
2728

28-
// Even though we got all constructors from std::vector we need this on
29-
// some compilers/libraries for some reason.
3029
idlist_t() = default;
3130

32-
};
31+
idlist_t(std::initializer_list<osmid_t> ids) : m_list(ids) {}
32+
33+
bool empty() const noexcept { return m_list.empty(); }
34+
35+
std::size_t size() const noexcept { return m_list.size(); }
36+
37+
auto begin() const noexcept { return m_list.begin(); }
38+
39+
auto end() const noexcept { return m_list.end(); }
40+
41+
osmid_t operator[](std::size_t n) const noexcept { return m_list[n]; }
42+
43+
void clear() { m_list.clear(); }
44+
45+
void push_back(osmid_t id) { m_list.push_back(id); }
46+
47+
void reserve(std::size_t size) { m_list.reserve(size); }
48+
49+
osmid_t pop_id()
50+
{
51+
assert(!m_list.empty());
52+
auto const id = m_list.back();
53+
m_list.pop_back();
54+
return id;
55+
}
56+
57+
friend bool operator==(idlist_t const &lhs, idlist_t const &rhs) noexcept
58+
{
59+
return lhs.m_list == rhs.m_list;
60+
}
61+
62+
friend bool operator!=(idlist_t const &lhs, idlist_t const &rhs) noexcept
63+
{
64+
return !(lhs == rhs);
65+
}
66+
67+
private:
68+
std::vector<osmid_t> m_list;
69+
70+
}; // class idlist_t
3371

3472
#endif // OSM2PGSQL_IDLIST_HPP

src/osmdata.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ class multithreaded_processor
244244

245245
std::lock_guard<std::mutex> const lock{*mutex};
246246
if (!queue->empty()) {
247-
id = queue->back();
248-
queue->pop_back();
247+
id = queue->pop_id();
249248
}
250249

251250
return id;

tests/test-middle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11181118

11191119
REQUIRE(dependency_manager.has_pending());
11201120
idlist_t const way_ids = dependency_manager.get_pending_way_ids();
1121-
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20}));
1121+
REQUIRE(way_ids == idlist_t{20});
11221122

11231123
check_way(mid, way20);
11241124
check_way_nodes(mid, way20.id(), {&node10a, &node11});
@@ -1153,7 +1153,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11531153

11541154
REQUIRE(dependency_manager.has_pending());
11551155
idlist_t const way_ids = dependency_manager.get_pending_way_ids();
1156-
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20, 22}));
1156+
REQUIRE(way_ids == idlist_t{20, 22});
11571157

11581158
check_way(mid, way20);
11591159
check_way_nodes(mid, way20.id(), {&node10a, &node11});
@@ -1265,7 +1265,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12651265
REQUIRE(dependency_manager.has_pending());
12661266
idlist_t const rel_ids = dependency_manager.get_pending_relation_ids();
12671267

1268-
REQUIRE_THAT(rel_ids, Catch::Equals<osmid_t>({30}));
1268+
REQUIRE(rel_ids == idlist_t{30});
12691269
check_relation(mid, rel30);
12701270
}
12711271

@@ -1286,9 +1286,9 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12861286

12871287
REQUIRE(dependency_manager.has_pending());
12881288
idlist_t const way_ids = dependency_manager.get_pending_way_ids();
1289-
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20}));
1289+
REQUIRE(way_ids == idlist_t{20});
12901290
idlist_t const rel_ids = dependency_manager.get_pending_relation_ids();
1291-
REQUIRE_THAT(rel_ids, Catch::Equals<osmid_t>({31}));
1291+
REQUIRE(rel_ids == idlist_t{31});
12921292
check_relation(mid, rel31);
12931293
}
12941294
}

0 commit comments

Comments
 (0)