diff --git a/.clang-tidy b/.clang-tidy index 60dff1777..232c134f8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -108,8 +108,8 @@ CheckOptions: value: "@todo;@fixme;exception ignored on purpose" - key: readability-identifier-naming.ClassCase value: lower_case - - key: readability-identifier-naming.ClassSuffix - value: _t +# - key: readability-identifier-naming.ClassSuffix +# value: _t - key: readability-identifier-naming.PrivateMemberPrefix value: m_ - key: readability-identifier-naming.StructCase diff --git a/src/domain-matcher.hpp b/src/domain-matcher.hpp deleted file mode 100644 index 726230627..000000000 --- a/src/domain-matcher.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef OSM2PGSQL_DOMAIN_MATCHER_HPP -#define OSM2PGSQL_DOMAIN_MATCHER_HPP - -/** - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This file is part of osm2pgsql (https://osm2pgsql.org/). - * - * Copyright (C) 2006-2025 by the osm2pgsql developer community. - * For a full list of authors see the git log. - */ - -#include - -#include - -/** - * Returns the tag specific name, if applicable. - * - * OSM tags may contain name tags that refer to one of the other tags - * in the tag set. For example, the name of a bridge is tagged as - * bridge:name=Foo to not confuse it with the name of the highway - * going over the bridge. This matcher checks if a tag is such a name tag - * for the given tag key and returns the name key without the prefix - * if it matches. - */ -class DomainMatcher -{ -public: - explicit DomainMatcher(char const *cls) noexcept - : m_domain(cls), m_len(std::strlen(cls)) - {} - - char const *operator()(osmium::Tag const &t) const noexcept - { - if (std::strncmp(t.key(), m_domain, m_len) == 0 && - std::strncmp(t.key() + m_len, ":name", 5) == 0 && - (t.key()[m_len + 5] == '\0' || t.key()[m_len + 5] == ':')) { - return t.key() + m_len + 1; - } - - return nullptr; - } - -private: - char const *m_domain; - size_t m_len; -}; - -#endif // OSM2PGSQL_DOMAIN_MATCHER_HPP diff --git a/src/table.cpp b/src/table.cpp index a3dddfb69..06a3bb676 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -359,10 +359,10 @@ void table_t::task_wait() // This is legacy code which will be removed anyway. /* Escape data appropriate to the type */ -void table_t::escape_type(std::string const &value, ColumnType flags) +void table_t::escape_type(std::string const &value, column_type_t flags) { switch (flags) { - case ColumnType::INT: { + case column_type_t::INT: { // For integers we take the first number, or the average if it's a-b long long from = 0; long long to = 0; @@ -387,7 +387,7 @@ void table_t::escape_type(std::string const &value, ColumnType flags) } break; } - case ColumnType::REAL: + case column_type_t::REAL: /* try to "repair" real values as follows: * assume "," to be a decimal mark which need to be replaced by "." * like int4 take the first number, or the average if it's a-b @@ -421,7 +421,7 @@ void table_t::escape_type(std::string const &value, ColumnType flags) } break; } - case ColumnType::TEXT: + case column_type_t::TEXT: m_copy.add_column(value); break; } diff --git a/src/table.hpp b/src/table.hpp index 1dcfe1fbf..fbc06290b 100644 --- a/src/table.hpp +++ b/src/table.hpp @@ -66,7 +66,7 @@ class table_t std::vector const &used); void write_hstore_columns(taglist_t const &tags); - void escape_type(std::string const &value, ColumnType flags); + void escape_type(std::string const &value, column_type_t flags); void generate_copy_column_list(); diff --git a/src/taginfo-impl.hpp b/src/taginfo-impl.hpp index 8534e9086..484e5df8a 100644 --- a/src/taginfo-impl.hpp +++ b/src/taginfo-impl.hpp @@ -36,15 +36,15 @@ enum column_flags : unsigned int // NOLINT(performance-enum-size) /* Table columns, representing key= tags */ struct taginfo { - ColumnType column_type() const + column_type_t column_type() const { if (flags & FLAG_INT_TYPE) { - return ColumnType::INT; + return column_type_t::INT; } if (flags & FLAG_REAL_TYPE) { - return ColumnType::REAL; + return column_type_t::REAL; } - return ColumnType::TEXT; + return column_type_t::TEXT; } std::string name; diff --git a/src/taginfo.hpp b/src/taginfo.hpp index 75977541e..69d080a6c 100644 --- a/src/taginfo.hpp +++ b/src/taginfo.hpp @@ -14,24 +14,24 @@ #include #include -enum class ColumnType : std::uint8_t +enum class column_type_t : std::uint8_t { INT, REAL, TEXT }; -struct Column +struct column_t { - Column(std::string n, std::string tn, ColumnType t) + column_t(std::string n, std::string tn, column_type_t t) : name(std::move(n)), type_name(std::move(tn)), type(t) {} std::string name; std::string type_name; - ColumnType type; + column_type_t type; }; -using columns_t = std::vector; +using columns_t = std::vector; #endif // OSM2PGSQL_TAGINFO_HPP diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b946be34..14f312cd2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,7 +41,6 @@ target_compile_features(catch_main_lib PUBLIC cxx_std_17) set_test(test-check-input LABELS NoDB) set_test(test-db-copy-mgr) set_test(test-db-copy-thread) -set_test(test-domain-matcher LABELS NoDB) set_test(test-expire-from-geometry LABELS NoDB) set_test(test-expire-tiles LABELS NoDB) set_test(test-flex-indexes LABELS NoDB) diff --git a/tests/test-domain-matcher.cpp b/tests/test-domain-matcher.cpp deleted file mode 100644 index f6356c5e3..000000000 --- a/tests/test-domain-matcher.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/** - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This file is part of osm2pgsql (https://osm2pgsql.org/). - * - * Copyright (C) 2006-2025 by the osm2pgsql developer community. - * For a full list of authors see the git log. - */ - -#include - -#include "domain-matcher.hpp" - -#include -#include -#include - -#include - -namespace { - -osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key, - char const *value) -{ - { - osmium::builder::TagListBuilder builder{*buffer}; - builder.add_tag(key, value); - } - buffer->commit(); - - return *buffer->get(0).begin(); -} - -} // anonymous namespace - -TEST_CASE("DomainMatcher: name", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{"bridge"}; - - auto const &tag = fill_buffer(&buffer, "bridge:name", "Golden Gate Bridge"); - char const *result = matcher(tag); - - REQUIRE(result); - REQUIRE(std::strcmp(result, "name") == 0); -} - -TEST_CASE("DomainMatcher: name with language", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{"bridge"}; - - auto const &tag = - fill_buffer(&buffer, "bridge:name:en", "The Bridge on the River Kwai"); - char const *result = matcher(tag); - - REQUIRE(result); - REQUIRE(std::strcmp(result, "name:en") == 0); -} - -TEST_CASE("DomainMatcher: no :name", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{"bridge"}; - - auto const &tag = fill_buffer(&buffer, "bridge_name", "A Bridge Too Far"); - char const *result = matcher(tag); - - REQUIRE_FALSE(result); -} - -TEST_CASE("DomainMatcher: empty matcher", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{""}; - - auto const &tag = - fill_buffer(&buffer, "bridge:name", "Tacoma Narrows Bridge"); - char const *result = matcher(tag); - - REQUIRE_FALSE(result); -} - -TEST_CASE("DomainMatcher: names", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{"bridge"}; - - auto const &tag = - fill_buffer(&buffer, "bridge:names", "Seven Bridges of Königsberg"); - char const *result = matcher(tag); - - REQUIRE_FALSE(result); -} - -TEST_CASE("DomainMatcher: not matching", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{"bridge"}; - - auto const &tag = fill_buffer(&buffer, "the_bridge_tag", "Pont du Gard"); - char const *result = matcher(tag); - - REQUIRE_FALSE(result); -} - -TEST_CASE("DomainMatcher: empty tag", "[NoDB]") -{ - osmium::memory::Buffer buffer{1024}; - DomainMatcher const matcher{"bridge"}; - - auto const &tag = fill_buffer(&buffer, "", "London Bridge"); - char const *result = matcher(tag); - - REQUIRE_FALSE(result); -} diff --git a/tests/test-output-pgsql-style-file.cpp b/tests/test-output-pgsql-style-file.cpp index 268354d89..38eec63d8 100644 --- a/tests/test-output-pgsql-style-file.cpp +++ b/tests/test-output-pgsql-style-file.cpp @@ -66,7 +66,7 @@ TEST_CASE("Parse style file with single node entry") REQUIRE(ex.name == "access"); REQUIRE(ex.type == "text"); REQUIRE(ex.flags == column_flags::FLAG_LINEAR); - REQUIRE(ex.column_type() == ColumnType::TEXT); + REQUIRE(ex.column_type() == column_type_t::TEXT); } TEST_CASE("Parse style file with a few valid entries") @@ -85,12 +85,12 @@ TEST_CASE("Parse style file with a few valid entries") for (auto const &node : nodes) { REQUIRE(node.type == "text"); - REQUIRE(node.column_type() == ColumnType::TEXT); + REQUIRE(node.column_type() == column_type_t::TEXT); } for (auto const &way : ways) { REQUIRE(way.type == "text"); - REQUIRE(way.column_type() == ColumnType::TEXT); + REQUIRE(way.column_type() == column_type_t::TEXT); } REQUIRE(nodes[0].flags == column_flags::FLAG_LINEAR); @@ -123,14 +123,14 @@ TEST_CASE("Parse style file with missing fields") for (auto const &node : nodes) { REQUIRE(node.type == "text"); - REQUIRE(node.column_type() == ColumnType::TEXT); + REQUIRE(node.column_type() == column_type_t::TEXT); } REQUIRE(nodes[0].flags == column_flags::FLAG_LINEAR); REQUIRE(nodes[1].flags == 0); for (auto const &way : ways) { REQUIRE(way.type == "text"); - REQUIRE(way.column_type() == ColumnType::TEXT); + REQUIRE(way.column_type() == column_type_t::TEXT); } REQUIRE(ways[0].flags == column_flags::FLAG_POLYGON); REQUIRE(ways[1].flags == 0); @@ -153,17 +153,17 @@ TEST_CASE("Parse style file with way_area") REQUIRE(nodes[0].type == "text"); REQUIRE(nodes[0].flags == (column_flags::FLAG_POLYGON | column_flags::FLAG_NOCOLUMN)); - REQUIRE(nodes[0].column_type() == ColumnType::TEXT); + REQUIRE(nodes[0].column_type() == column_type_t::TEXT); REQUIRE(ways[0].type == "text"); REQUIRE(ways[0].flags == (column_flags::FLAG_POLYGON | column_flags::FLAG_NOCOLUMN)); - REQUIRE(ways[0].column_type() == ColumnType::TEXT); + REQUIRE(ways[0].column_type() == column_type_t::TEXT); REQUIRE(ways[1].type == "real"); REQUIRE(ways[1].flags == 0); REQUIRE(ways[1].column_type() == - ColumnType::TEXT); // Special case for way_area! + column_type_t::TEXT); // Special case for way_area! } TEST_CASE("Parse style file with different data types") @@ -183,30 +183,30 @@ TEST_CASE("Parse style file with different data types") REQUIRE(nodes[0].name == "name"); REQUIRE(nodes[0].type == "text"); REQUIRE(nodes[0].flags == column_flags::FLAG_LINEAR); - REQUIRE(nodes[0].column_type() == ColumnType::TEXT); + REQUIRE(nodes[0].column_type() == column_type_t::TEXT); REQUIRE(nodes[1].name == "population"); REQUIRE(nodes[1].type == "integer"); REQUIRE(nodes[1].flags == (column_flags::FLAG_POLYGON | column_flags::FLAG_INT_TYPE)); - REQUIRE(nodes[1].column_type() == ColumnType::INT); + REQUIRE(nodes[1].column_type() == column_type_t::INT); REQUIRE(ways[0].name == "name"); REQUIRE(ways[0].type == "text"); REQUIRE(ways[0].flags == column_flags::FLAG_LINEAR); - REQUIRE(ways[0].column_type() == ColumnType::TEXT); + REQUIRE(ways[0].column_type() == column_type_t::TEXT); REQUIRE(ways[1].name == "width"); REQUIRE(ways[1].type == "real"); REQUIRE(ways[1].flags == (column_flags::FLAG_LINEAR | column_flags::FLAG_REAL_TYPE)); - REQUIRE(ways[1].column_type() == ColumnType::REAL); + REQUIRE(ways[1].column_type() == column_type_t::REAL); REQUIRE(ways[2].name == "population"); REQUIRE(ways[2].type == "integer"); REQUIRE(ways[2].flags == (column_flags::FLAG_POLYGON | column_flags::FLAG_INT_TYPE)); - REQUIRE(ways[2].column_type() == ColumnType::INT); + REQUIRE(ways[2].column_type() == column_type_t::INT); } TEST_CASE("Parse style file with invalid data types") @@ -225,5 +225,5 @@ TEST_CASE("Parse style file with invalid data types") REQUIRE(ways[0].name == "highway"); REQUIRE(ways[0].type == "foo"); REQUIRE(ways[0].flags == column_flags::FLAG_LINEAR); - REQUIRE(ways[0].column_type() == ColumnType::TEXT); + REQUIRE(ways[0].column_type() == column_type_t::TEXT); }