Prefer std::array instead of plain C arrays

HEAD
Jochen Topf 2022-03-14 16:21:31 +01:00
parent 519183d58f
commit cdca1fb4a9
10 changed files with 35 additions and 16 deletions

View File

@ -8,6 +8,7 @@
*/
#include <algorithm>
#include <array>
#include <cstring>
#include <stdexcept>
@ -465,9 +466,9 @@ void gazetteer_style_t::copy_out(osmium::OSMObject const &o,
// osm_id
buffer->add_column(o.id());
// osm_type
char const osm_type[2] = {
std::array<char const, 2> const osm_type = {
(char)toupper(osmium::item_type_to_char(o.type())), '\0'};
buffer->add_column(osm_type);
buffer->add_column(osm_type.data());
// class
buffer->add_column(std::get<0>(tag));
// type

View File

@ -79,8 +79,9 @@ TRAMPOLINE(table_add_row, add_row)
TRAMPOLINE(table_columns, columns)
TRAMPOLINE(table_tostring, __tostring)
static char const osm2pgsql_table_name[] = "osm2pgsql.table";
static char const osm2pgsql_object_metatable[] = "osm2pgsql.object_metatable";
static char const *const osm2pgsql_table_name = "osm2pgsql.table";
static char const *const osm2pgsql_object_metatable =
"osm2pgsql.object_metatable";
prepared_lua_function_t::prepared_lua_function_t(lua_State *lua_state,
calling_context context,

View File

@ -10,6 +10,7 @@
#include <catch.hpp>
#include <algorithm>
#include <array>
#include <osmium/osm/crc.hpp>
#include <osmium/osm/crc_zlib.hpp>
@ -184,7 +185,8 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
SECTION("Set and retrieve a single relation with supporting ways")
{
idlist_t const nds[] = {{4, 5, 13, 14, 342}, {45, 90}, {30, 3, 45}};
std::array<idlist_t, 3> const nds = {
{{4, 5, 13, 14, 342}, {45, 90}, {30, 3, 45}}};
// set the node
mid->node(buffer.add_node("n1 x4.1 y12.8"));

View File

@ -12,6 +12,8 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
static char const *const conf_file = "test_output_flex_types.lua";
@ -205,8 +207,9 @@ TEST_CASE("Adding a function should always fail")
{
testing::opt_t const options = testing::opt_t().flex(conf_file);
std::string const types[] = {"ttext", "tbool", "tint2", "tint4", "tint8",
"treal", "thstr", "tdirn", "tsqlt"};
std::array<std::string, 9> const types = {"ttext", "tbool", "tint2",
"tint4", "tint8", "treal",
"thstr", "tdirn", "tsqlt"};
for (auto const &type : types) {
auto const line =
@ -252,8 +255,8 @@ TEST_CASE("Adding a table should fail except for hstore and json/jsonb")
{
testing::opt_t const options = testing::opt_t().flex(conf_file);
std::string const types[] = {"ttext", "tbool", "tint2", "tint4",
"tint8", "treal", "tdirn", "tsqlt"};
std::array<std::string, 8> const types = {
"ttext", "tbool", "tint2", "tint4", "tint8", "treal", "tdirn", "tsqlt"};
for (auto const &type : types) {
auto const line =

View File

@ -12,11 +12,13 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
static char const *const conf_file = "test_output_flex_way.lua";
static const char *const tdata[] = {
static std::array<char const *, 15> const tdata = {
"n10 v1 dV x10.0 y10.0",
"n11 v1 dV x10.0 y10.1",
"n12 v1 dV x10.1 y10.0",

View File

@ -12,11 +12,13 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
static char const *const conf_file = "test_output_flex_way.lua";
static const char *const tdata[] = {
static std::array<char const *, 14> const tdata = {
"n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1",
"n12 v1 dV x10.1 y10.0", "n13 v1 dV x10.1 y10.1",
"n14 v1 dV x10.2 y10.0", "n15 v1 dV x10.2 y10.1",

View File

@ -12,11 +12,13 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
static char const *const conf_file = "test_output_flex_way.lua";
static const char *const tdata[] = {
static std::array<char const *, 14> const tdata = {
"n10 v1 dV x10.0 y10.0", "n11 v1 dV x10.0 y10.1",
"n12 v1 dV x10.1 y10.0", "n13 v1 dV x10.1 y10.1",
"n14 v1 dV x10.2 y10.0", "n15 v1 dV x10.2 y10.1",

View File

@ -12,11 +12,13 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
static char const *const conf_file = "test_output_flex_way.lua";
static char const *const tdata[] = {
static std::array<char const *, 16> const tdata = {
"n10 v1 dV x10.0 y10.0",
"n11 v1 dV x10.0 y10.1",
"n12 v1 dV x10.1 y10.0",

View File

@ -12,11 +12,13 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
static char const *const conf_file = "test_output_flex_way.lua";
static const char *const tdata[] = {
static std::array<char const *, 16> const tdata = {
"n10 v1 dV x10.0 y10.0",
"n11 v1 dV x10.0 y10.1",
"n12 v1 dV x10.1 y10.0",

View File

@ -12,6 +12,8 @@
#include "common-import.hpp"
#include "common-options.hpp"
#include <array>
static testing::db::import_t db;
TEST_CASE("compute Z order")
@ -21,8 +23,8 @@ TEST_CASE("compute Z order")
auto conn = db.db().connect();
char const *expected[] = {"motorway", "trunk", "primary", "secondary",
"tertiary"};
std::array<char const *, 5> const expected = {
"motorway", "trunk", "primary", "secondary", "tertiary"};
for (unsigned i = 0; i < 5; ++i) {
auto const sql = "SELECT highway FROM osm2pgsql_test_line"