Skip to content

Commit 4aa81eb

Browse files
committed
Use enum class for hstore options instead of macros
1 parent 6d7e4ef commit 4aa81eb

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

src/options.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,21 @@ options_t::options_t(int argc, char *argv[]) : options_t()
465465
extra_attributes = true;
466466
break;
467467
case 'k':
468-
if (hstore_mode != HSTORE_NONE) {
468+
if (hstore_mode != hstore_column::none) {
469469
throw std::runtime_error{"You can not specify both --hstore "
470470
"(-k) and --hstore-all (-j)\n"};
471471
}
472-
hstore_mode = HSTORE_NORM;
472+
hstore_mode = hstore_column::norm;
473473
break;
474474
case 208:
475475
hstore_match_only = true;
476476
break;
477477
case 'j':
478-
if (hstore_mode != HSTORE_NONE) {
478+
if (hstore_mode != hstore_column::none) {
479479
throw std::runtime_error{"You can not specify both --hstore "
480480
"(-k) and --hstore-all (-j)\n"};
481481
}
482-
hstore_mode = HSTORE_ALL;
482+
hstore_mode = hstore_column::all;
483483
break;
484484
case 'z':
485485
hstore_columns.emplace_back(optarg);
@@ -596,15 +596,15 @@ void options_t::check_options()
596596
throw std::runtime_error{"--drop only makes sense with --slim.\n"};
597597
}
598598

599-
if (hstore_mode == HSTORE_NONE && hstore_columns.empty() &&
599+
if (hstore_mode == hstore_column::none && hstore_columns.empty() &&
600600
hstore_match_only) {
601601
fprintf(stderr,
602602
"Warning: --hstore-match-only only makes sense with --hstore, "
603603
"--hstore-all, or --hstore-column; ignored.\n");
604604
hstore_match_only = false;
605605
}
606606

607-
if (enable_hstore_index && hstore_mode == HSTORE_NONE &&
607+
if (enable_hstore_index && hstore_mode == hstore_column::none &&
608608
hstore_columns.empty()) {
609609
fprintf(stderr, "Warning: --hstore-add-index only makes sense with "
610610
"hstore enabled.\n");

src/options.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
#include <string>
1212
#include <vector>
1313

14-
/* Variants for generation of hstore column */
15-
/* No hstore column */
16-
#define HSTORE_NONE 0
17-
/* create a hstore column for all tags which do not have an exclusive column */
18-
#define HSTORE_NORM 1
19-
/* create a hstore column for all tags */
20-
#define HSTORE_ALL 2
14+
/// Variants for generation of hstore column
15+
enum class hstore_column : char
16+
{
17+
/// no hstore column
18+
none = 0,
19+
/// create hstore column for all tags without exclusive column
20+
norm = 1,
21+
/// create hstore column for all tags
22+
all = 2
23+
};
2124

2225
/**
2326
* Database options, not specific to a table
@@ -80,7 +83,7 @@ class options_t
8083
std::string expire_tiles_filename{"dirty_tiles"};
8184

8285
/// add an additional hstore column with objects key/value pairs, and what type of hstore column
83-
int hstore_mode = HSTORE_NONE;
86+
hstore_column hstore_mode = hstore_column::none;
8487

8588
bool enable_hstore_index = false; ///< add an index on the hstore column
8689

src/output.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ parse_multi_single(pt::ptree const &conf,
7373
new_opts.tblsmain_index = conf.get("tablespace-index", "");
7474
new_opts.tblsmain_data = conf.get("tablespace-data", "");
7575

76-
override_if<int>(new_opts.hstore_mode, "enable-hstore", conf);
76+
if (conf.get<bool>("enable-hstore", false)) {
77+
new_opts.hstore_mode = hstore_column::norm;
78+
}
7779
override_if<bool>(new_opts.enable_hstore_index, "enable-hstore-index",
7880
conf);
7981
override_if<bool>(new_opts.enable_multi, "enable-multi", conf);

src/table.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
table_t::table_t(std::string const &name, std::string const &type,
1717
columns_t const &columns, hstores_t const &hstore_columns,
18-
int const srid, bool const append, int const hstore_mode,
18+
int const srid, bool const append, hstore_column hstore_mode,
1919
std::shared_ptr<db_copy_thread_t> const &copy_thread)
2020
: m_target(std::make_shared<db_target_descr_t>(name.c_str(), "osm_id")),
2121
m_type(type), m_srid(fmt::to_string(srid)), m_append(append),
2222
m_hstore_mode(hstore_mode), m_columns(columns),
2323
m_hstore_columns(hstore_columns), m_copy(copy_thread)
2424
{
2525
// if we dont have any columns
26-
if (m_columns.empty() && m_hstore_mode != HSTORE_ALL) {
26+
if (m_columns.empty() && m_hstore_mode != hstore_column::all) {
2727
throw std::runtime_error{
2828
"No columns provided for table {}"_format(name)};
2929
}
@@ -99,7 +99,7 @@ void table_t::start(std::string const &conninfo, std::string const &table_space)
9999
}
100100

101101
//add tags column
102-
if (m_hstore_mode != HSTORE_NONE) {
102+
if (m_hstore_mode != hstore_column::none) {
103103
sql += "\"tags\" hstore,";
104104
}
105105

@@ -163,7 +163,7 @@ void table_t::generate_copy_column_list()
163163
}
164164

165165
//add tags column and geom column
166-
if (m_hstore_mode != HSTORE_NONE) {
166+
if (m_hstore_mode != hstore_column::none) {
167167
m_target->rows += "tags,way";
168168
//or just the geom column
169169
} else {
@@ -264,7 +264,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
264264
if (enable_hstore_index) {
265265
fmt::print(stderr, "Creating hstore indexes on {}\n",
266266
m_target->name);
267-
if (m_hstore_mode != HSTORE_NONE) {
267+
if (m_hstore_mode != hstore_column::none) {
268268
m_sql_conn->exec(
269269
"CREATE INDEX ON {} USING GIN (tags) {}"_format(
270270
m_target->name, tablespace_clause(table_space_index)));
@@ -303,18 +303,18 @@ void table_t::write_row(osmid_t id, taglist_t const &tags,
303303
// used to remember which columns have been written out already.
304304
std::vector<bool> used;
305305

306-
if (m_hstore_mode != HSTORE_NONE) {
306+
if (m_hstore_mode != hstore_column::none) {
307307
used.assign(tags.size(), false);
308308
}
309309

310310
//get the regular columns' values
311-
write_columns(tags, m_hstore_mode == HSTORE_NORM ? &used : nullptr);
311+
write_columns(tags, m_hstore_mode == hstore_column::norm ? &used : nullptr);
312312

313313
//get the hstore columns' values
314314
write_hstore_columns(tags);
315315

316316
//get the key value pairs for the tags column
317-
if (m_hstore_mode != HSTORE_NONE) {
317+
if (m_hstore_mode != hstore_column::none) {
318318
write_tags_column(tags, used);
319319
}
320320

src/table.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class table_t
1919
public:
2020
table_t(std::string const &name, std::string const &type,
2121
columns_t const &columns, hstores_t const &hstore_columns,
22-
int const srid, bool const append, int const hstore_mode,
22+
int const srid, bool const append, hstore_column hstore_mode,
2323
std::shared_ptr<db_copy_thread_t> const &copy_thread);
2424
table_t(table_t const &other,
2525
std::shared_ptr<db_copy_thread_t> const &copy_thread);
@@ -81,7 +81,7 @@ class table_t
8181
std::unique_ptr<pg_conn_t> m_sql_conn;
8282
std::string m_srid;
8383
bool m_append;
84-
int m_hstore_mode;
84+
hstore_column m_hstore_mode;
8585
columns_t m_columns;
8686
hstores_t m_hstore_columns;
8787
std::string m_table_space;

src/tagtransform-c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool c_tagtransform_t::check_key(std::vector<taginfo> const &infos,
114114
// if we didn't find any tags that we wanted to export
115115
// and we aren't strictly adhering to the list
116116
if (!strict) {
117-
if (m_options->hstore_mode != HSTORE_NONE) {
117+
if (m_options->hstore_mode != hstore_column::none) {
118118
/* ... but if hstore_match_only is set then don't take this
119119
as a reason for keeping the object */
120120
if (!m_options->hstore_match_only) {

tests/test-output-pgsql-hstore-match-only.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TEST_CASE("hstore match only import")
1010
options_t options =
1111
testing::opt_t().slim().style("hstore-match-only.style");
1212
options.hstore_match_only = true;
13-
options.hstore_mode = HSTORE_NORM;
13+
options.hstore_mode = hstore_column::norm;
1414

1515
REQUIRE_NOTHROW(db.run_file(options, "hstore-match-only.osm"));
1616

0 commit comments

Comments
 (0)