Skip to content

Commit 7215cfa

Browse files
committed
Move internal linkage code into anonymous namespace
1 parent 706313c commit 7215cfa

File tree

7 files changed

+71
-63
lines changed

7 files changed

+71
-63
lines changed

src/flex-lua-geom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ geom::geometry_t *unpack_geometry(lua_State *lua_state, int n) noexcept
3636
return static_cast<geom::geometry_t *>(user_data);
3737
}
3838

39+
namespace {
40+
3941
/**
4042
* This function is called by Lua garbage collection when a geometry object
4143
* needs cleaning up. It calls the destructor of the C++ object. After that
@@ -51,8 +53,6 @@ int geom_gc(lua_State *lua_state) noexcept
5153
return 0;
5254
}
5355

54-
namespace {
55-
5656
// The following functions are called when their counterparts in Lua are
5757
// called on geometry objects.
5858

src/gen/gen-rivers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ gen_rivers_t::gen_rivers_t(pg_conn_t *connection, bool append, params_t *params)
4141
get_params().get_string("src_areas")));
4242
}
4343

44+
namespace {
45+
4446
/// The data for a graph edge in the waterway network.
4547
struct edge_t
4648
{
@@ -76,8 +78,6 @@ bool operator<(geom::point_t a, edge_t const &b) noexcept
7678
return a < b.points[0];
7779
}
7880

79-
namespace {
80-
8181
void follow_chain_and_set_width(
8282
edge_t const &edge, std::vector<edge_t> *edges,
8383
std::map<geom::point_t, uint8_t> const &node_order,

src/gen/raster.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
#include <string>
1818

19+
namespace {
20+
1921
template <typename T>
2022
void append(std::string *str, T value)
2123
{
2224
str->append(reinterpret_cast<char *>(&value), sizeof(T));
2325
}
2426

27+
} // anonymous namespace
28+
2529
void add_raster_header(std::string *wkb, wkb_raster_header const &data)
2630
{
2731
append(wkb, data.endianness);

src/output-flex.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,54 @@ void check_for_object(lua_State *lua_state, char const *const function_name)
334334
function_name);
335335
}
336336

337+
/**
338+
* Expects a Lua (hash) table on the stack, reads the field with name of the
339+
* 'type' parameter which must be either nil or a Lua (array) table, in which
340+
* case all (integer) ids in that table are reads into the 'ids' out
341+
* parameter.
342+
*/
343+
void get_object_ids(lua_State *lua_state, char const *const type, idlist_t *ids)
344+
{
345+
lua_getfield(lua_state, -1, type);
346+
int const ltype = lua_type(lua_state, -1);
347+
348+
if (ltype == LUA_TNIL) {
349+
lua_pop(lua_state, 1);
350+
return;
351+
}
352+
353+
if (ltype != LUA_TTABLE) {
354+
lua_pop(lua_state, 1);
355+
throw fmt_error(
356+
"Table returned from select_relation_members() contains '{}' "
357+
"field, but it isn't an array table.",
358+
type);
359+
}
360+
361+
if (!luaX_is_array(lua_state)) {
362+
lua_pop(lua_state, 1);
363+
throw fmt_error(
364+
"Table returned from select_relation_members() contains '{}' "
365+
"field, but it isn't an array table.",
366+
type);
367+
}
368+
369+
luaX_for_each(lua_state, [&]() {
370+
osmid_t const id = lua_tointeger(lua_state, -1);
371+
if (id == 0) {
372+
throw fmt_error(
373+
"Table returned from select_relation_members() contains "
374+
"'{}' field, which must contain an array of non-zero "
375+
"integer node ids.",
376+
type);
377+
}
378+
379+
ids->push_back(id);
380+
});
381+
382+
lua_pop(lua_state, 1);
383+
}
384+
337385
} // anonymous namespace
338386

339387
/**
@@ -899,54 +947,6 @@ void output_flex_t::pending_way(osmid_t id)
899947
get_mutex_and_call_lua_function(m_process_way, m_way_cache.get());
900948
}
901949

902-
/**
903-
* Expects a Lua (hash) table on the stack, reads the field with name of the
904-
* 'type' parameter which must be either nil or a Lua (array) table, in which
905-
* case all (integer) ids in that table are reads into the 'ids' out
906-
* parameter.
907-
*/
908-
void get_object_ids(lua_State *lua_state, char const *const type, idlist_t *ids)
909-
{
910-
lua_getfield(lua_state, -1, type);
911-
int const ltype = lua_type(lua_state, -1);
912-
913-
if (ltype == LUA_TNIL) {
914-
lua_pop(lua_state, 1);
915-
return;
916-
}
917-
918-
if (ltype != LUA_TTABLE) {
919-
lua_pop(lua_state, 1);
920-
throw fmt_error(
921-
"Table returned from select_relation_members() contains '{}' "
922-
"field, but it isn't an array table.",
923-
type);
924-
}
925-
926-
if (!luaX_is_array(lua_state)) {
927-
lua_pop(lua_state, 1);
928-
throw fmt_error(
929-
"Table returned from select_relation_members() contains '{}' "
930-
"field, but it isn't an array table.",
931-
type);
932-
}
933-
934-
luaX_for_each(lua_state, [&]() {
935-
osmid_t const id = lua_tointeger(lua_state, -1);
936-
if (id == 0) {
937-
throw fmt_error(
938-
"Table returned from select_relation_members() contains "
939-
"'{}' field, which must contain an array of non-zero "
940-
"integer node ids.",
941-
type);
942-
}
943-
944-
ids->push_back(id);
945-
});
946-
947-
lua_pop(lua_state, 1);
948-
}
949-
950950
void output_flex_t::select_relation_members()
951951
{
952952
if (!m_select_relation_members) {

tests/test-lua-utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <lua.hpp>
1515

16+
namespace {
17+
1618
// Run the Lua code in "code" and then execute the function "func".
1719
template <typename FUNC>
1820
void test_lua(lua_State *lua_state, char const *code, FUNC&& func) {
@@ -25,6 +27,8 @@ void test_lua(lua_State *lua_state, char const *code, FUNC&& func) {
2527
REQUIRE(lua_gettop(lua_state) == 0);
2628
}
2729

30+
} // anonymous namespace
31+
2832
TEST_CASE("check luaX_is_empty_table", "[NoDB]")
2933
{
3034
std::shared_ptr<lua_State> lua_state{

tests/test-output-flex-example-configs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ testing::db::import_t db;
2525

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

28-
} // anonymous namespace
29-
3028
std::vector<std::string> get_files() {
3129
// NOLINTNEXTLINE(concurrency-mt-unsafe)
3230
char const *env = std::getenv("EXAMPLE_FILES");
3331
REQUIRE(env);
3432
return osmium::split_string(env, ',', true);
3533
}
3634

35+
} // anonymous namespace
36+
3737
TEST_CASE("minimal test for flex example configs")
3838
{
3939
auto const files = get_files();

tests/test-output-flex-update.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ testing::db::import_t db;
1919

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

22+
// Return a string with the schema name prepended to the table name.
23+
std::string with_schema(char const *table_name, options_t const &options)
24+
{
25+
if (options.dbschema.empty()) {
26+
return {table_name};
27+
}
28+
return options.dbschema + "." + table_name;
29+
}
30+
2231
} // anonymous namespace
2332

2433
struct options_slim_default
@@ -72,15 +81,6 @@ END
7281
}
7382
};
7483

75-
// Return a string with the schema name prepended to the table name.
76-
std::string with_schema(char const *table_name, options_t const &options)
77-
{
78-
if (options.dbschema.empty()) {
79-
return {table_name};
80-
}
81-
return options.dbschema + "." + table_name;
82-
}
83-
8484
TEMPLATE_TEST_CASE("updating a node", "", options_slim_default,
8585
options_slim_expire, options_slim_schema)
8686
{

0 commit comments

Comments
 (0)