Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-readability-casting,-google-readability-todo,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-vararg,-llvm-include-order,-llvm-header-guard,-llvmlibc-*,-misc-include-cleaner,-misc-no-recursion,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-magic-numbers'
Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-boost-use-ranges,-bugprone-chained-comparison,-bugprone-easily-swappable-parameters,-cert-err58-cpp,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-readability-casting,-google-readability-todo,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-vararg,-llvm-include-order,-llvm-header-guard,-llvmlibc-*,-misc-include-cleaner,-misc-no-recursion,-modernize-use-nodiscard,-modernize-use-trailing-return-type,-readability-identifier-length,-readability-implicit-bool-conversion,-readability-math-missing-parentheses,-readability-named-parameter,-readability-magic-numbers'
#
# cppcoreguidelines-pro-type-cstyle-cast
# google-build-using-namespace
# google-readability-casting
# llvm-header-guard
# llvm-include-order
# hicpp-named-parameter
# readability-math-missing-parentheses
# readability-named-parameter
# Differ from our style guidelines
#
Expand All @@ -19,6 +20,12 @@ Checks: '*,-abseil-*,-altera-*,-android-cloexec-*,-bugprone-easily-swappable-par
# android-cloexec-*
# O_CLOEXEC isn't available on Windows
#
# boost-use-ranges
# Not applicable, we don't want to rely on more code from boost.
#
# bugprone-chained-comparison
# Triggerd by the Catch library in many places.
#
# bugprone-easily-swappable-parameters
# Can't always be avoided.
#
Expand Down
4 changes: 2 additions & 2 deletions src/flex-lua-geom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ geom::geometry_t *unpack_geometry(lua_State *lua_state, int n) noexcept
return static_cast<geom::geometry_t *>(user_data);
}

namespace {

/**
* This function is called by Lua garbage collection when a geometry object
* needs cleaning up. It calls the destructor of the C++ object. After that
Expand All @@ -51,8 +53,6 @@ int geom_gc(lua_State *lua_state) noexcept
return 0;
}

namespace {

// The following functions are called when their counterparts in Lua are
// called on geometry objects.

Expand Down
4 changes: 2 additions & 2 deletions src/gen/gen-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void gen_base_t::dbprepare(std::string_view stmt, std::string const &templ)
{
template_t sql_template{templ};
sql_template.set_params(get_params());
return connection().prepare(stmt, fmt::runtime(sql_template.render()));
connection().prepare(stmt, fmt::runtime(sql_template.render()));
}

void gen_base_t::dbprepare(std::string_view stmt, params_t const &tmp_params,
Expand All @@ -112,7 +112,7 @@ void gen_base_t::dbprepare(std::string_view stmt, params_t const &tmp_params,
template_t sql_template{templ};
sql_template.set_params(get_params());
sql_template.set_params(tmp_params);
return connection().prepare(stmt, fmt::runtime(sql_template.render()));
connection().prepare(stmt, fmt::runtime(sql_template.render()));
}

void gen_base_t::raster_table_preprocess(std::string const &table)
Expand Down
4 changes: 2 additions & 2 deletions src/gen/gen-rivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ gen_rivers_t::gen_rivers_t(pg_conn_t *connection, bool append, params_t *params)
get_params().get_string("src_areas")));
}

namespace {

/// The data for a graph edge in the waterway network.
struct edge_t
{
Expand Down Expand Up @@ -76,8 +78,6 @@ bool operator<(geom::point_t a, edge_t const &b) noexcept
return a < b.points[0];
}

namespace {

void follow_chain_and_set_width(
edge_t const &edge, std::vector<edge_t> *edges,
std::map<geom::point_t, uint8_t> const &node_order,
Expand Down
4 changes: 4 additions & 0 deletions src/gen/raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

#include <string>

namespace {

template <typename T>
void append(std::string *str, T value)
{
str->append(reinterpret_cast<char *>(&value), sizeof(T));
}

} // anonymous namespace

void add_raster_header(std::string *wkb, wkb_raster_header const &data)
{
append(wkb, data.endianness);
Expand Down
96 changes: 48 additions & 48 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,54 @@ void check_for_object(lua_State *lua_state, char const *const function_name)
function_name);
}

/**
* Expects a Lua (hash) table on the stack, reads the field with name of the
* 'type' parameter which must be either nil or a Lua (array) table, in which
* case all (integer) ids in that table are reads into the 'ids' out
* parameter.
*/
void get_object_ids(lua_State *lua_state, char const *const type, idlist_t *ids)
{
lua_getfield(lua_state, -1, type);
int const ltype = lua_type(lua_state, -1);

if (ltype == LUA_TNIL) {
lua_pop(lua_state, 1);
return;
}

if (ltype != LUA_TTABLE) {
lua_pop(lua_state, 1);
throw fmt_error(
"Table returned from select_relation_members() contains '{}' "
"field, but it isn't an array table.",
type);
}

if (!luaX_is_array(lua_state)) {
lua_pop(lua_state, 1);
throw fmt_error(
"Table returned from select_relation_members() contains '{}' "
"field, but it isn't an array table.",
type);
}

luaX_for_each(lua_state, [&]() {
osmid_t const id = lua_tointeger(lua_state, -1);
if (id == 0) {
throw fmt_error(
"Table returned from select_relation_members() contains "
"'{}' field, which must contain an array of non-zero "
"integer node ids.",
type);
}

ids->push_back(id);
});

lua_pop(lua_state, 1);
}

} // anonymous namespace

/**
Expand Down Expand Up @@ -899,54 +947,6 @@ void output_flex_t::pending_way(osmid_t id)
get_mutex_and_call_lua_function(m_process_way, m_way_cache.get());
}

/**
* Expects a Lua (hash) table on the stack, reads the field with name of the
* 'type' parameter which must be either nil or a Lua (array) table, in which
* case all (integer) ids in that table are reads into the 'ids' out
* parameter.
*/
void get_object_ids(lua_State *lua_state, char const *const type, idlist_t *ids)
{
lua_getfield(lua_state, -1, type);
int const ltype = lua_type(lua_state, -1);

if (ltype == LUA_TNIL) {
lua_pop(lua_state, 1);
return;
}

if (ltype != LUA_TTABLE) {
lua_pop(lua_state, 1);
throw fmt_error(
"Table returned from select_relation_members() contains '{}' "
"field, but it isn't an array table.",
type);
}

if (!luaX_is_array(lua_state)) {
lua_pop(lua_state, 1);
throw fmt_error(
"Table returned from select_relation_members() contains '{}' "
"field, but it isn't an array table.",
type);
}

luaX_for_each(lua_state, [&]() {
osmid_t const id = lua_tointeger(lua_state, -1);
if (id == 0) {
throw fmt_error(
"Table returned from select_relation_members() contains "
"'{}' field, which must contain an array of non-zero "
"integer node ids.",
type);
}

ids->push_back(id);
});

lua_pop(lua_state, 1);
}

void output_flex_t::select_relation_members()
{
if (!m_select_relation_members) {
Expand Down
4 changes: 4 additions & 0 deletions tests/test-lua-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <lua.hpp>

namespace {

// Run the Lua code in "code" and then execute the function "func".
template <typename FUNC>
void test_lua(lua_State *lua_state, char const *code, FUNC&& func) {
Expand All @@ -25,6 +27,8 @@ void test_lua(lua_State *lua_state, char const *code, FUNC&& func) {
REQUIRE(lua_gettop(lua_state) == 0);
}

} // anonymous namespace

TEST_CASE("check luaX_is_empty_table", "[NoDB]")
{
std::shared_ptr<lua_State> lua_state{
Expand Down
4 changes: 2 additions & 2 deletions tests/test-output-flex-example-configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ testing::db::import_t db;

char const *const data_file = "liechtenstein-2013-08-03.osm.pbf";

} // anonymous namespace

std::vector<std::string> get_files() {
// NOLINTNEXTLINE(concurrency-mt-unsafe)
char const *env = std::getenv("EXAMPLE_FILES");
REQUIRE(env);
return osmium::split_string(env, ',', true);
}

} // anonymous namespace

TEST_CASE("minimal test for flex example configs")
{
auto const files = get_files();
Expand Down
18 changes: 9 additions & 9 deletions tests/test-output-flex-update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ testing::db::import_t db;

char const *const conf_file = "test_output_flex.lua";

// Return a string with the schema name prepended to the table name.
std::string with_schema(char const *table_name, options_t const &options)
{
if (options.dbschema.empty()) {
return {table_name};
}
return options.dbschema + "." + table_name;
}

} // anonymous namespace

struct options_slim_default
Expand Down Expand Up @@ -72,15 +81,6 @@ END
}
};

// Return a string with the schema name prepended to the table name.
std::string with_schema(char const *table_name, options_t const &options)
{
if (options.dbschema.empty()) {
return {table_name};
}
return options.dbschema + "." + table_name;
}

TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
options_slim_expire, options_slim_schema)
{
Expand Down