Add lots of const's to the code

This commit is contained in:
Jochen Topf
2023-01-05 20:22:26 +01:00
parent 3d4bb81cbb
commit 45aa0b3100
21 changed files with 55 additions and 52 deletions

View File

@ -60,7 +60,7 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
auto const pos = column.find(',');
assert(pos != std::string::npos);
std::string type = column.substr(0, pos);
std::string const type = column.substr(0, pos);
fmt::format_to(std::back_inserter(sql),
") AS t (osm_type, osm_id) WHERE"
@ -106,7 +106,7 @@ void db_copy_thread_t::add_buffer(std::unique_ptr<db_cmd_t> &&buffer)
void db_copy_thread_t::sync_and_wait()
{
std::promise<void> barrier;
std::future<void> sync = barrier.get_future();
std::future<void> const sync = barrier.get_future();
add_buffer(std::make_unique<db_cmd_sync_t>(std::move(barrier)));
sync.wait();
}

View File

@ -69,7 +69,7 @@ static std::string lowercase(std::string const &str)
{
std::string result;
for (char c : str) {
for (char const c : str) {
result +=
static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
}

View File

@ -480,7 +480,7 @@ void gazetteer_style_t::copy_out(osmium::OSMObject const &o,
buffer->add_column(std::get<1>(tag));
// names
if (std::get<2>(tag) & SF_MAIN_NAMED_KEY) {
DomainMatcher m{std::get<0>(tag)};
DomainMatcher const m{std::get<0>(tag)};
buffer->new_hash();
for (auto const &t : o.tags()) {
char const *const k = m(t);
@ -562,7 +562,7 @@ void gazetteer_style_t::copy_out(osmium::OSMObject const &o,
"osm_changeset", o.changeset());
}
if (m_metadata_fields.timestamp() && o.timestamp()) {
std::string timestamp = o.timestamp().to_iso();
std::string const timestamp = o.timestamp().to_iso();
buffer->add_hash_elem_noescape("osm_timestamp",
timestamp.c_str());
}

View File

@ -180,7 +180,7 @@ prepare_input_files(std::vector<std::string> const &input_files,
std::vector<osmium::io::File> files;
for (auto const &filename : input_files) {
osmium::io::File file{filename, input_format};
osmium::io::File const file{filename, input_format};
if (file.format() == osmium::io::file_format::unknown) {
if (input_format.empty()) {

View File

@ -99,7 +99,7 @@ void middle_pgsql_t::table_desc::build_index(std::string const &conninfo) const
// Use a temporary connection here because we might run in a separate
// thread context.
pg_conn_t db_connection{conninfo};
pg_conn_t const db_connection{conninfo};
log_info("Building index on table '{}'", name());
db_connection.exec(m_create_fw_dep_indexes);
@ -191,9 +191,9 @@ void pgsql_parse_members(char const *string, osmium::memory::Buffer *buffer,
osmium::builder::RelationMemberListBuilder builder{*buffer, obuilder};
while (*string != '}') {
char type = string[0];
char const type = string[0];
char *endp = nullptr;
osmid_t id = std::strtoll(string + 1, &endp, 10);
osmid_t const id = std::strtoll(string + 1, &endp, 10);
// String points to the comma */
string = decode_to_delimiter(endp + 1, &role);
builder.add_member(osmium::char_to_item_type(type), id, role);

View File

@ -33,7 +33,7 @@
*/
static void show_memory_usage()
{
osmium::MemoryUsage mem;
osmium::MemoryUsage const mem;
if (mem.peak() != 0) {
log_debug("Overall memory usage: peak={}MByte current={}MByte",
mem.peak(), mem.current());
@ -80,7 +80,7 @@ static void run(options_t const &options)
void check_db(options_t const &options)
{
pg_conn_t db_connection{options.conninfo};
pg_conn_t const db_connection{options.conninfo};
init_database_capabilities(db_connection);

View File

@ -1123,7 +1123,7 @@ void output_flex_t::call_lua_function(prepared_lua_function_t func,
void output_flex_t::get_mutex_and_call_lua_function(
prepared_lua_function_t func, osmium::OSMObject const &object)
{
std::lock_guard<std::mutex> guard{lua_mutex};
std::lock_guard<std::mutex> const guard{lua_mutex};
call_lua_function(func, object);
}
@ -1148,7 +1148,7 @@ void output_flex_t::select_relation_members()
return;
}
std::lock_guard<std::mutex> guard{lua_mutex};
std::lock_guard<std::mutex> const guard{lua_mutex};
call_lua_function(m_select_relation_members, m_relation_cache.get());
// If the function returned nil there is nothing to be marked.

View File

@ -49,7 +49,7 @@ void output_gazetteer_t::start()
if (!get_options()->append) {
int const srid = get_options()->projection->target_srs();
pg_conn_t conn{get_options()->conninfo};
pg_conn_t const conn{get_options()->conninfo};
/* Drop any existing table */
conn.exec("DROP TABLE IF EXISTS place CASCADE");

View File

@ -442,7 +442,7 @@ output_pgsql_t::output_pgsql_t(std::shared_ptr<middle_query_t> const &mid,
for (std::size_t i = 0; i < m_tables.size(); ++i) {
//figure out the columns this table needs
columns_t columns = exlist.normal_columns(
columns_t const columns = exlist.normal_columns(
(i == t_point) ? osmium::item_type::node : osmium::item_type::way);
//figure out what name we are using for this and what type

View File

@ -37,7 +37,8 @@ void create_geom_check_trigger(pg_conn_t *db_connection,
std::string const &table,
std::string const &condition)
{
std::string func_name = qualified_name(schema, table + "_osm2pgsql_valid");
std::string const func_name =
qualified_name(schema, table + "_osm2pgsql_valid");
db_connection->exec("CREATE OR REPLACE FUNCTION {}()\n"
"RETURNS TRIGGER AS $$\n"
@ -63,7 +64,8 @@ void drop_geom_check_trigger(pg_conn_t *db_connection,
std::string const &schema,
std::string const &table)
{
std::string func_name = qualified_name(schema, table + "_osm2pgsql_valid");
std::string const func_name =
qualified_name(schema, table + "_osm2pgsql_valid");
db_connection->exec(R"(DROP TRIGGER "{}" ON {})",
table + "_osm2pgsql_valid",

View File

@ -63,7 +63,7 @@ private:
std::string const source = "epsg:{}"_format(from);
std::string const target = "epsg:{}"_format(to);
std::unique_ptr<PJ, pj_deleter_t> trans{proj_create_crs_to_crs(
std::unique_ptr<PJ, pj_deleter_t> const trans{proj_create_crs_to_crs(
m_context.get(), source.c_str(), target.c_str(), nullptr)};
if (!trans) {

View File

@ -53,7 +53,7 @@ static void add_z_order(taglist_t *tags, bool *roads)
int z_order = 0;
int l = layer ? (int)strtol(layer->c_str(), nullptr, 10) : 0;
int const l = layer ? (int)strtol(layer->c_str(), nullptr, 10) : 0;
z_order = 100 * l;
*roads = false;

View File

@ -32,7 +32,7 @@ static osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
TEST_CASE("DomainMatcher: name", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{"bridge"};
DomainMatcher const matcher{"bridge"};
auto const &tag = fill_buffer(&buffer, "bridge:name", "Golden Gate Bridge");
char const *result = matcher(tag);
@ -44,7 +44,7 @@ TEST_CASE("DomainMatcher: name", "[NoDB]")
TEST_CASE("DomainMatcher: name with language", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{"bridge"};
DomainMatcher const matcher{"bridge"};
auto const &tag =
fill_buffer(&buffer, "bridge:name:en", "The Bridge on the River Kwai");
@ -57,7 +57,7 @@ TEST_CASE("DomainMatcher: name with language", "[NoDB]")
TEST_CASE("DomainMatcher: no :name", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{"bridge"};
DomainMatcher const matcher{"bridge"};
auto const &tag = fill_buffer(&buffer, "bridge_name", "A Bridge Too Far");
char const *result = matcher(tag);
@ -68,7 +68,7 @@ TEST_CASE("DomainMatcher: no :name", "[NoDB]")
TEST_CASE("DomainMatcher: empty matcher", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{""};
DomainMatcher const matcher{""};
auto const &tag =
fill_buffer(&buffer, "bridge:name", "Tacoma Narrows Bridge");
@ -80,7 +80,7 @@ TEST_CASE("DomainMatcher: empty matcher", "[NoDB]")
TEST_CASE("DomainMatcher: names", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{"bridge"};
DomainMatcher const matcher{"bridge"};
auto const &tag =
fill_buffer(&buffer, "bridge:names", "Seven Bridges of Königsberg");
@ -92,7 +92,7 @@ TEST_CASE("DomainMatcher: names", "[NoDB]")
TEST_CASE("DomainMatcher: not matching", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{"bridge"};
DomainMatcher const matcher{"bridge"};
auto const &tag = fill_buffer(&buffer, "the_bridge_tag", "Pont du Gard");
char const *result = matcher(tag);
@ -103,7 +103,7 @@ TEST_CASE("DomainMatcher: not matching", "[NoDB]")
TEST_CASE("DomainMatcher: empty tag", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
DomainMatcher matcher{"bridge"};
DomainMatcher const matcher{"bridge"};
auto const &tag = fill_buffer(&buffer, "", "London Bridge");
char const *result = matcher(tag);

View File

@ -45,7 +45,7 @@ private:
TEST_CASE("check index with single column", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("geom", "geometry", "");
@ -68,7 +68,7 @@ TEST_CASE("check index with single column", "[NoDB]")
TEST_CASE("check index with multiple columns", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("a", "int", "");
@ -90,7 +90,7 @@ TEST_CASE("check index with multiple columns", "[NoDB]")
TEST_CASE("check unique index", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "int", "");
@ -112,7 +112,7 @@ TEST_CASE("check unique index", "[NoDB]")
TEST_CASE("check index with tablespace from table", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.set_index_tablespace("foo");
@ -134,7 +134,7 @@ TEST_CASE("check index with tablespace from table", "[NoDB]")
TEST_CASE("check index with tablespace", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "int", "");
@ -156,7 +156,7 @@ TEST_CASE("check index with tablespace", "[NoDB]")
TEST_CASE("check index with expression and where clause", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "text", "");
@ -178,7 +178,7 @@ TEST_CASE("check index with expression and where clause", "[NoDB]")
TEST_CASE("check index with include", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "int", "");
@ -201,7 +201,7 @@ TEST_CASE("check index with include", "[NoDB]")
TEST_CASE("check index with include as array", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "int", "");
@ -224,7 +224,7 @@ TEST_CASE("check index with include as array", "[NoDB]")
TEST_CASE("check index with empty include array", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "int", "");
@ -247,7 +247,7 @@ TEST_CASE("check index with empty include array", "[NoDB]")
TEST_CASE("check multiple indexes", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("a", "int", "");
@ -270,7 +270,7 @@ TEST_CASE("check multiple indexes", "[NoDB]")
TEST_CASE("check various broken index configs", "[NoDB]")
{
test_framework tf;
test_framework const tf;
flex_table_t table{"test_table"};
table.add_column("col", "text", "");

View File

@ -95,7 +95,7 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
options_slim_with_schema, options_ram_optimized)
{
options_t const options = TestType::options(db);
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
auto conn = db.connect();
auto const num_tables =
@ -345,7 +345,7 @@ TEMPLATE_TEST_CASE("middle: add, delete and update node", "",
options_t options = TestType::options(db);
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// Prepare a buffer with some nodes which we will add and change.
test_buffer_t buffer;
@ -539,7 +539,7 @@ TEMPLATE_TEST_CASE("middle: add, delete and update way", "",
options_t options = TestType::options(db);
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// Create some ways we'll use for the tests.
test_buffer_t buffer;
@ -689,7 +689,7 @@ TEMPLATE_TEST_CASE("middle: add way with attributes", "", options_slim_default,
SECTION("With attributes") { options.extra_attributes = true; }
SECTION("No attributes") { options.extra_attributes = false; }
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// Create some ways we'll use for the tests.
test_buffer_t buffer;
@ -772,7 +772,7 @@ TEMPLATE_TEST_CASE("middle: add, delete and update relation", "",
options_t options = TestType::options(db);
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// Create some relations we'll use for the tests.
test_buffer_t buffer;
@ -918,7 +918,7 @@ TEMPLATE_TEST_CASE("middle: add relation with attributes", "",
SECTION("With attributes") { options.extra_attributes = true; }
SECTION("No attributes") { options.extra_attributes = false; }
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// Create some relations we'll use for the tests.
test_buffer_t buffer;
@ -967,7 +967,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
options_t options = TestType::options(db);
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// create some nodes and ways we'll use for the tests
test_buffer_t buffer;
@ -1104,7 +1104,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
options_t options = TestType::options(db);
testing::cleanup::file_t flatnode_cleaner{options.flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{options.flat_node_file};
// create some nodes, ways, and relations we'll use for the tests
test_buffer_t buffer;

View File

@ -73,7 +73,8 @@ TEST_CASE("Projection setup")
option_params.push_back("foo");
options_t options{(int)option_params.size(), (char **)option_params.data()};
options_t const options{(int)option_params.size(),
(char **)option_params.data()};
if (!proj_name.empty()) {
CHECK(options.projection->target_desc() == proj_name);

View File

@ -51,7 +51,7 @@ TEST_CASE("with three input files")
TEST_CASE("should use newest version of any object")
{
options_t options = testing::opt_t().slim().flex(conf_file);
options_t const options = testing::opt_t().slim().flex(conf_file);
REQUIRE_NOTHROW(
db.run_import(options, {"n10 v1 dV x10.0 y10.0 Ta=10.1\n"

View File

@ -35,7 +35,7 @@ struct options_slim_latlon
TEMPLATE_TEST_CASE("liechtenstein regression", "", options_slim_default,
options_slim_latlon)
{
options_t options = TestType::options();
options_t const options = TestType::options();
REQUIRE_NOTHROW(db.run_file(options, "liechtenstein-2013-08-03.osm.pbf"));

View File

@ -16,7 +16,7 @@ static testing::db::import_t db;
TEST_CASE("default projection")
{
options_t options = testing::opt_t().slim();
options_t const options = testing::opt_t().slim();
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_area.osm"));
@ -33,7 +33,7 @@ TEST_CASE("default projection")
TEST_CASE("latlon projection")
{
options_t options = testing::opt_t().slim().srs(PROJ_LATLONG);
options_t const options = testing::opt_t().slim().srs(PROJ_LATLONG);
REQUIRE_NOTHROW(db.run_file(options, "test_output_pgsql_area.osm"));

View File

@ -268,7 +268,7 @@ TEST_CASE("parse xml file with extra args")
TEST_CASE("invalid location")
{
options_t options = testing::opt_t();
options_t const options = testing::opt_t();
auto const middle = std::make_shared<counting_middle_t>(false);
auto const output = std::make_shared<counting_output_t>(options);

View File

@ -35,7 +35,7 @@ static void delete_location(node_persistent_cache *cache, osmid_t id)
TEST_CASE("Persistent cache", "[NoDB]")
{
std::string const flat_node_file = "test_middle_flat.flat.nodes.bin";
testing::cleanup::file_t flatnode_cleaner{flat_node_file};
testing::cleanup::file_t const flatnode_cleaner{flat_node_file};
// create a new cache
{