Skip to content

Commit 7517b69

Browse files
committed
Move some more complex functions from .hpp into .cpp file
Only very simple accessor-type functions should be defined directly in .hpp file.
1 parent c4f3f49 commit 7517b69

2 files changed

Lines changed: 72 additions & 62 deletions

File tree

src/flex-table.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "pgsql-helper.hpp"
1515
#include "util.hpp"
1616

17+
#include <algorithm>
1718
#include <cassert>
1819
#include <string>
1920

@@ -64,6 +65,73 @@ std::string flex_table_t::full_tmp_name() const
6465
return qualified_name(schema(), name() + "_tmp");
6566
}
6667

68+
bool flex_table_t::has_id_column() const noexcept
69+
{
70+
if (m_columns.empty()) {
71+
return false;
72+
}
73+
return (m_columns[0].type() == table_column_type::id_type) ||
74+
(m_columns[0].type() == table_column_type::id_num);
75+
}
76+
77+
bool flex_table_t::has_hstore_column() const noexcept
78+
{
79+
auto const it = std::find_if(begin(), end(), [&](auto const &column) {
80+
return column.type() == table_column_type::hstore;
81+
});
82+
return it != end();
83+
}
84+
85+
bool flex_table_t::matches_type(osmium::item_type type) const noexcept
86+
{
87+
// This table takes any type -> okay
88+
if (m_id_type == osmium::item_type::undefined) {
89+
return true;
90+
}
91+
92+
// Type and table type match -> okay
93+
if (type == m_id_type) {
94+
return true;
95+
}
96+
97+
// Relations can be written as linestrings into way tables -> okay
98+
if (type == osmium::item_type::relation &&
99+
m_id_type == osmium::item_type::way) {
100+
return true;
101+
}
102+
103+
// Area tables can take ways or relations, but not nodes
104+
return m_id_type == osmium::item_type::area &&
105+
type != osmium::item_type::node;
106+
}
107+
108+
/// Map way/node/relation ID to id value used in database table column
109+
osmid_t flex_table_t::map_id(osmium::item_type type, osmid_t id) const noexcept
110+
{
111+
if (m_id_type == osmium::item_type::undefined) {
112+
if (has_multicolumn_id_index()) {
113+
return id;
114+
}
115+
116+
switch (type) {
117+
case osmium::item_type::node:
118+
return id;
119+
case osmium::item_type::way:
120+
return -id;
121+
case osmium::item_type::relation:
122+
return -id - 100000000000000000LL;
123+
default:
124+
assert(false);
125+
}
126+
}
127+
128+
if (m_id_type != osmium::item_type::relation &&
129+
type == osmium::item_type::relation) {
130+
return -id;
131+
}
132+
return id;
133+
}
134+
67135
flex_table_column_t &flex_table_t::add_column(std::string const &name,
68136
std::string const &type,
69137
std::string const &sql_type)

src/flex-table.hpp

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,7 @@ class flex_table_t
8484

8585
void set_id_type(osmium::item_type type) noexcept { m_id_type = type; }
8686

87-
bool has_id_column() const noexcept
88-
{
89-
if (m_columns.empty()) {
90-
return false;
91-
}
92-
return (m_columns[0].type() == table_column_type::id_type) ||
93-
(m_columns[0].type() == table_column_type::id_num);
94-
}
87+
bool has_id_column() const noexcept;
9588

9689
std::size_t num_columns() const noexcept { return m_columns.size(); }
9790

@@ -110,13 +103,7 @@ class flex_table_t
110103
return m_geom_column != std::numeric_limits<std::size_t>::max();
111104
}
112105

113-
bool has_hstore_column() const noexcept
114-
{
115-
auto const it = std::find_if(begin(), end(), [&](auto const &column) {
116-
return column.type() == table_column_type::hstore;
117-
});
118-
return it != end();
119-
}
106+
bool has_hstore_column() const noexcept;
120107

121108
/// Get the (first, if there are multiple) geometry column.
122109
flex_table_column_t const &geom_column() const noexcept
@@ -140,55 +127,10 @@ class flex_table_t
140127
std::string build_sql_create_id_index() const;
141128

142129
/// Does this table take objects of the specified type?
143-
bool matches_type(osmium::item_type type) const noexcept
144-
{
145-
// This table takes any type -> okay
146-
if (m_id_type == osmium::item_type::undefined) {
147-
return true;
148-
}
149-
150-
// Type and table type match -> okay
151-
if (type == m_id_type) {
152-
return true;
153-
}
154-
155-
// Relations can be written as linestrings into way tables -> okay
156-
if (type == osmium::item_type::relation &&
157-
m_id_type == osmium::item_type::way) {
158-
return true;
159-
}
160-
161-
// Area tables can take ways or relations, but not nodes
162-
return m_id_type == osmium::item_type::area &&
163-
type != osmium::item_type::node;
164-
}
130+
bool matches_type(osmium::item_type type) const noexcept;
165131

166132
/// Map way/node/relation ID to id value used in database table column
167-
osmid_t map_id(osmium::item_type type, osmid_t id) const noexcept
168-
{
169-
if (m_id_type == osmium::item_type::undefined) {
170-
if (has_multicolumn_id_index()) {
171-
return id;
172-
}
173-
174-
switch (type) {
175-
case osmium::item_type::node:
176-
return id;
177-
case osmium::item_type::way:
178-
return -id;
179-
case osmium::item_type::relation:
180-
return -id - 100000000000000000LL;
181-
default:
182-
assert(false);
183-
}
184-
}
185-
186-
if (m_id_type != osmium::item_type::relation &&
187-
type == osmium::item_type::relation) {
188-
return -id;
189-
}
190-
return id;
191-
}
133+
osmid_t map_id(osmium::item_type type, osmid_t id) const noexcept;
192134

193135
flex_table_column_t &add_column(std::string const &name,
194136
std::string const &type,

0 commit comments

Comments
 (0)