Convert a bunch of C-style arrays to std::array
This commit is contained in:
parent
619ceabb9d
commit
ab0197343e
7 changed files with 48 additions and 42 deletions
|
@ -18,17 +18,18 @@
|
|||
#include "serialization/unicode_cast.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <set>
|
||||
|
||||
const unsigned short default_campaignd_port = 15015;
|
||||
|
||||
namespace {
|
||||
const std::string addon_type_strings[] {
|
||||
const std::array<std::string, ADDON_TYPES_COUNT> addon_type_strings {{
|
||||
"unknown", "core", "campaign", "scenario", "campaign_sp_mp", "campaign_mp",
|
||||
"scenario_mp", "map_pack", "era", "faction", "mod_mp", /*"gui", */ "media",
|
||||
"other", ""
|
||||
};
|
||||
"other"
|
||||
}};
|
||||
|
||||
// Reserved DOS device names on Windows XP and later.
|
||||
const std::set<std::string> dos_device_names = {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <boost/program_options/positional_options.hpp>
|
||||
#include <boost/program_options/value_semantic.hpp> // for value, etc
|
||||
#include <boost/program_options/variables_map.hpp> // for variables_map, etc
|
||||
|
||||
#include <array>
|
||||
#include <iostream> // for operator<<, basic_ostream, etc
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
@ -552,7 +554,7 @@ void commandline_options::parse_log_domains_(const std::string &domains_string,
|
|||
}
|
||||
|
||||
void commandline_options::parse_log_strictness (const std::string & severity ) {
|
||||
static lg::logger const *loggers[] { &lg::err(), &lg::warn(), &lg::info(), &lg::debug() };
|
||||
static const std::array<lg::logger const*, 4> loggers {{&lg::err(), &lg::warn(), &lg::info(), &lg::debug()}};
|
||||
for (const lg::logger * l : loggers ) {
|
||||
if (severity == l->get_name()) {
|
||||
lg::set_strict_severity(*l);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "team.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
|
@ -43,13 +44,13 @@ static lg::log_domain log_mp_connect_engine("mp/connect/engine");
|
|||
static lg::log_domain log_network("network");
|
||||
#define LOG_NW LOG_STREAM(info, log_network)
|
||||
|
||||
static const std::string controller_names[] {
|
||||
static const std::array<std::string, 5> controller_names {{
|
||||
"human",
|
||||
"human",
|
||||
"ai",
|
||||
"null",
|
||||
"reserved"
|
||||
};
|
||||
}};
|
||||
|
||||
namespace ng {
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "game_errors.hpp"
|
||||
#include "scripting/mapgen_lua_kernel.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
lua_map_generator::lua_map_generator(const config & cfg, const config* vars)
|
||||
|
@ -30,8 +31,8 @@ lua_map_generator::lua_map_generator(const config & cfg, const config* vars)
|
|||
, generator_data_(cfg)
|
||||
{
|
||||
lk_.load_core();
|
||||
const char* required[] {"id", "config_name", "create_map"};
|
||||
for (std::string req : required) {
|
||||
const std::array<std::string, 3> required {{"id", "config_name", "create_map"}};
|
||||
for(const std::string& req : required) {
|
||||
if (!cfg.has_attribute(req)) {
|
||||
if(req == "create_map" && cfg.has_attribute("create_scenario")) {
|
||||
// One of these is required, but not both
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "whiteboard/manager.hpp"
|
||||
#include "replay_recorder_base.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
@ -104,12 +105,12 @@ static void verify(const unit_map& units, const config& cfg) {
|
|||
u->write(u_cfg);
|
||||
|
||||
bool is_ok = true;
|
||||
static const std::string fields[] {"type","hitpoints","experience","side",""};
|
||||
for(const std::string* str = fields; str->empty() == false; ++str) {
|
||||
if (u_cfg[*str] != un[*str]) {
|
||||
errbuf << "ERROR IN FIELD '" << *str << "' for unit at "
|
||||
<< loc << " data source: '" << un[*str]
|
||||
<< "' local: '" << u_cfg[*str] << "'\n";
|
||||
static const std::array<std::string, 4> fields {{"type","hitpoints","experience","side"}};
|
||||
for(const std::string& field : fields) {
|
||||
if (u_cfg[field] != un[field]) {
|
||||
errbuf << "ERROR IN FIELD '" << field << "' for unit at "
|
||||
<< loc << " data source: '" << un[field]
|
||||
<< "' local: '" << u_cfg[field] << "'\n";
|
||||
is_ok = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <boost/regex.hpp>
|
||||
#include <boost/range/algorithm_ext/erase.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <locale>
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
|
@ -818,7 +819,7 @@ const config& unit_type::build_unit_cfg() const
|
|||
|
||||
// Remove "pure" unit_type attributes (attributes that do not get directly
|
||||
// copied to units; some do get copied, but under different keys).
|
||||
static char const* unit_type_attrs[] {
|
||||
static std::array<std::string, 25> unit_type_attrs {{
|
||||
"attacks",
|
||||
"base_ids",
|
||||
"die_sound",
|
||||
|
@ -829,7 +830,8 @@ const config& unit_type::build_unit_cfg() const
|
|||
"hitpoints",
|
||||
"id",
|
||||
"ignore_race_traits",
|
||||
"inherit", "movement",
|
||||
"inherit",
|
||||
"movement",
|
||||
"movement_type",
|
||||
"name",
|
||||
"num_traits",
|
||||
|
@ -843,9 +845,9 @@ const config& unit_type::build_unit_cfg() const
|
|||
"alignment",
|
||||
"advances_to",
|
||||
"do_not_list"
|
||||
};
|
||||
}};
|
||||
|
||||
for(const char* attr : unit_type_attrs) {
|
||||
for(const std::string& attr : unit_type_attrs) {
|
||||
unit_cfg_.remove_attribute(attr);
|
||||
}
|
||||
|
||||
|
@ -1175,7 +1177,7 @@ void unit_type_data::set_config(config& cfg)
|
|||
const std::string& ter_type = terrain["id"];
|
||||
config temp_cfg;
|
||||
|
||||
static const std::string terrain_info_tags[] {"movement", "vision", "jamming", "defense"};
|
||||
static const std::array<std::string, 4> terrain_info_tags {{"movement", "vision", "jamming", "defense"}};
|
||||
|
||||
for(const std::string& tag : terrain_info_tags) {
|
||||
if(!terrain.has_child(tag)) {
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <cassert> // for assert
|
||||
#include <cstdlib> // for rand
|
||||
#include <exception> // for exception
|
||||
|
@ -92,7 +93,7 @@ namespace
|
|||
static std::vector<const unit*> units_with_cache;
|
||||
|
||||
static const std::string leader_crown_path = "misc/leader-crown.png";
|
||||
static std::string internalized_attrs[] {
|
||||
static std::array<std::string, 60> internalized_attrs {{
|
||||
"type",
|
||||
"id",
|
||||
"name",
|
||||
|
@ -154,7 +155,7 @@ namespace
|
|||
"language_name",
|
||||
"image",
|
||||
"image_icon"
|
||||
};
|
||||
}};
|
||||
|
||||
struct internalized_attrs_sorter
|
||||
{
|
||||
|
@ -172,8 +173,8 @@ namespace
|
|||
config::const_attribute_iterator cur = cfg.begin();
|
||||
config::const_attribute_iterator end = cfg.end();
|
||||
|
||||
const std::string* cur_known = std::begin(internalized_attrs);
|
||||
const std::string* end_known = std::end(internalized_attrs);
|
||||
auto cur_known = internalized_attrs.begin();
|
||||
auto end_known = internalized_attrs.end();
|
||||
|
||||
while(cur_known != end_known) {
|
||||
if(cur == end) {
|
||||
|
@ -2669,7 +2670,7 @@ std::string get_checksum(const unit& u)
|
|||
config wcfg;
|
||||
u.write(unit_config);
|
||||
|
||||
const std::string main_keys[] {
|
||||
const std::array<std::string, 22> main_keys {{
|
||||
"advances_to",
|
||||
"alignment",
|
||||
"cost",
|
||||
|
@ -2691,28 +2692,26 @@ std::string get_checksum(const unit& u)
|
|||
"resting",
|
||||
"undead_variation",
|
||||
"upkeep",
|
||||
"zoc",
|
||||
""
|
||||
};
|
||||
"zoc"
|
||||
}};
|
||||
|
||||
for(int i = 0; !main_keys[i].empty(); ++i) {
|
||||
wcfg[main_keys[i]] = unit_config[main_keys[i]];
|
||||
for(const std::string& main_key : main_keys) {
|
||||
wcfg[main_key] = unit_config[main_key];
|
||||
}
|
||||
|
||||
const std::string attack_keys[] {
|
||||
const std::array<std::string, 5> attack_keys {{
|
||||
"name",
|
||||
"type",
|
||||
"range",
|
||||
"damage",
|
||||
"number",
|
||||
""
|
||||
};
|
||||
"number"
|
||||
}};
|
||||
|
||||
for(const config& att : unit_config.child_range("attack")) {
|
||||
config& child = wcfg.add_child("attack");
|
||||
|
||||
for(int i = 0; !attack_keys[i].empty(); ++i) {
|
||||
child[attack_keys[i]] = att[attack_keys[i]];
|
||||
for(const std::string& attack_key : attack_keys) {
|
||||
child[attack_key] = att[attack_key];
|
||||
}
|
||||
|
||||
for(const config& spec : att.child_range("specials")) {
|
||||
|
@ -2740,19 +2739,18 @@ std::string get_checksum(const unit& u)
|
|||
child.recursive_clear_value("name");
|
||||
}
|
||||
|
||||
const std::string child_keys[] {
|
||||
const std::array<std::string, 6> child_keys {{
|
||||
"advance_from",
|
||||
"defense",
|
||||
"movement_costs",
|
||||
"vision_costs",
|
||||
"jamming_costs",
|
||||
"resistance",
|
||||
""
|
||||
};
|
||||
"resistance"
|
||||
}};
|
||||
|
||||
for(int i = 0; !child_keys[i].empty(); ++i) {
|
||||
for(const config& c : unit_config.child_range(child_keys[i])) {
|
||||
wcfg.add_child(child_keys[i], c);
|
||||
for(const std::string& child_key : child_keys) {
|
||||
for(const config& c : unit_config.child_range(child_key)) {
|
||||
wcfg.add_child(child_key, c);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue