Modified WML attributes so that they are stored with...

...smaller effective types when they are not translatable.

This patch considerably reduces the memory footprint of WML and speeds it up.

It should not change any WML behavior, except for a few corner cases
detailled below:

- "off" is no longer a synonym for "no" (it wasn't used anyway),

- _"42" is no longer an integer,

- untranslatable "true" and "false" are stored as booleans, hence
  displayed as "yes" and "no",

- "042" is now understood as octal notation (hence 34) rather than decimal,

- hexadecimal notation "0x42" is now recognized.
This commit is contained in:
Guillaume Melquiond 2010-05-24 08:01:31 +00:00
parent 0e858d86db
commit 76c34a23d3
82 changed files with 489 additions and 564 deletions

View File

@ -71,7 +71,7 @@ static void add_lines(std::vector<std::string> &res, config const &c) {
}
foreach (const config &entry, c.child_range("entry")) {
res.push_back("- "+ entry["name"]);
res.push_back("- "+ entry["name"].str());
}
}

View File

@ -882,7 +882,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit &u, const map_lo
strcmp(opp.undead_variation().c_str(), "null") && !resources::game_map->is_village(opp_loc);
if (plagues) {
plague_type = (*plague_specials.cfgs.front().first)["type"];
plague_type = (*plague_specials.cfgs.front().first)["type"].str();
if (plague_type.empty())
plague_type = u.type_id();
}
@ -1229,9 +1229,9 @@ bool attack::perform_hit(bool attacker_turn, statistics::attack_context &stats)
const config *ran_results = get_random_results();
if (ran_results)
{
int results_chance = atoi((*ran_results)["chance"].c_str());
bool results_hits = (*ran_results)["hits"] == "yes";
int results_damage = atoi((*ran_results)["damage"].c_str());
int results_chance = (*ran_results)["chance"];
bool results_hits = (*ran_results)["hits"].to_bool();
int results_damage = (*ran_results)["damage"];
if (results_chance != attacker.cth_)
{
@ -2336,7 +2336,7 @@ size_t move_unit(move_unit_spectator *move_spectator,
std::vector<std::pair<const config *, map_location> >::const_iterator hide_it = hides.cfgs.begin();
// we only use the first valid alert message
for(;hide_it != hides.cfgs.end() && !ambushed_string.empty(); ++hide_it) {
ambushed_string = (*hide_it->first)["alert"];
ambushed_string = (*hide_it->first)["alert"].str();
}
}
}

View File

@ -142,20 +142,20 @@ void ai_composite::play_turn(){
}
const std::string& ai_composite::get_id() const
std::string ai_composite::get_id() const
{
return cfg_["id"];
}
const std::string& ai_composite::get_name() const
std::string ai_composite::get_name() const
{
return cfg_["name"];
}
const std::string& ai_composite::get_engine() const
std::string ai_composite::get_engine() const
{
return cfg_["engine"];
}

View File

@ -109,13 +109,9 @@ public:
virtual ai_context& get_ai_context();
const std::string& get_id() const;
const std::string& get_name() const;
const std::string& get_engine() const;
virtual std::string get_id() const;
virtual std::string get_name() const;
virtual std::string get_engine() const;
protected:

View File

@ -64,25 +64,6 @@ void aspect::on_create()
{
}
const std::string& aspect::get_id() const
{
return id_;
}
const std::string& aspect::get_name() const
{
return name_;
}
const std::string& aspect::get_engine() const
{
return engine_;
}
bool aspect::redeploy(const config &cfg, const std::string& /*id*/)
{
if (invalidate_on_turn_start_) {
@ -107,9 +88,9 @@ bool aspect::redeploy(const config &cfg, const std::string& /*id*/)
invalidate_on_tod_change_ = utils::string_bool(cfg["invalidate_on_tod_change"],true);
invalidate_on_gamestate_change_ = utils::string_bool(cfg["invalidate_on_gamestate_change"]);
invalidate_on_minor_gamestate_change_ = utils::string_bool(cfg["invalidate_on_minor_gamestate_change"]);
engine_ = cfg["engine"];
name_ = cfg["name"];
id_ = cfg["id"];
engine_ = cfg["engine"].str();
name_ = cfg["name"].str();
id_ = cfg["id"].str();
DBG_AI_ASPECT << "redeploying aspect: engine=["<<engine_<<"], name=["<<name_<<"], id=["<<id_<<"]"<< std::endl;
if (invalidate_on_turn_start_) {
manager::add_turn_started_observer(this);

View File

@ -98,15 +98,14 @@ public:
return true;
}
virtual std::string get_name() const
{ return name_; }
const std::string& get_name() const;
const std::string& get_id() const;
const std::string& get_engine() const;
virtual std::string get_id() const
{ return id_; }
virtual std::string get_engine() const
{ return engine_; }
static lg::log_domain& log();

View File

@ -64,9 +64,9 @@ public:
{
}
virtual const std::string& get_id() const = 0;
virtual const std::string& get_name() const = 0;
virtual const std::string& get_engine() const = 0;
virtual std::string get_id() const = 0;
virtual std::string get_name() const = 0;
virtual std::string get_engine() const = 0;
virtual ~component() {};
virtual component* get_child(const path_element &child);
virtual std::vector<component*> get_children(const std::string &type);

View File

@ -118,21 +118,6 @@ std::string engine::evaluate(const std::string& /*str*/)
return "evaluate command is not implemented by this engine";
}
const std::string& engine::get_name() const
{
return name_;
}
const std::string& engine::get_engine() const
{
return engine_;
}
void engine::set_ai_context(ai_context * /*context*/)
{
//do nothing
@ -146,12 +131,6 @@ config engine::to_config() const
return cfg;
}
const std::string& engine::get_id() const
{
return id_;
}
readonly_context& engine::get_readonly_context()
{
return ai_;

View File

@ -82,10 +82,6 @@ public:
//do not override that method in subclasses which cannot evaluate formulas
virtual std::string evaluate(const std::string& str);
virtual const std::string& get_name() const;
readonly_context& get_readonly_context();
/**
@ -100,10 +96,14 @@ public:
virtual config to_config() const;
virtual const std::string& get_id() const;
virtual std::string get_id() const
{ return id_; }
virtual std::string get_engine() const
{ return engine_; }
virtual const std::string& get_engine() const;
virtual std::string get_name() const
{ return name_; }
protected:
readonly_context &ai_;

View File

@ -138,8 +138,7 @@ private:
engine_lua::engine_lua( readonly_context &context, const config &cfg )
: engine(context,cfg)
, lua_ai_context_(resources::lua_kernel->create_lua_ai_context(
cfg["code"].c_str()
, this))
cfg["code"].str().c_str(), this))
{
name_ = "lua";
}

View File

@ -62,22 +62,17 @@ config goal::to_config() const
return cfg_;
}
const std::string& goal::get_id() const
std::string goal::get_id() const
{
return cfg_["id"];
}
const std::string& goal::get_name() const
std::string goal::get_name() const
{
return cfg_["id"];
}
const std::string& goal::get_engine() const
std::string goal::get_engine() const
{
return cfg_["engine"];
}

View File

@ -65,15 +65,9 @@ public:
bool active() const;
const std::string& get_id() const;
const std::string& get_name() const;
const std::string& get_engine() const;
virtual std::string get_id() const;
virtual std::string get_name() const;
virtual std::string get_engine() const;
bool redeploy(const config &cfg);

View File

@ -106,7 +106,7 @@ public:
//if the id is not empty, try to delete all with this id
if (!cfg["id"].empty()) {
path_element with_same_id;
with_same_id.id=cfg["id"];
with_same_id.id = cfg["id"].str();
with_same_id.property = property_;
with_same_id.position=-1;
handle_delete(with_same_id);

View File

@ -79,31 +79,11 @@ double candidate_action::get_max_score() const
return max_score_;
}
const std::string& candidate_action::get_name() const
{
return name_;
}
const std::string& candidate_action::get_type() const
{
return type_;
}
const std::string& candidate_action::get_id() const
{
return id_;
}
const std::string& candidate_action::get_engine() const
{
return engine_;
}
config candidate_action::to_config() const
{
config cfg;

View File

@ -104,19 +104,19 @@ public:
/**
* Get the name of the candidate action (useful for debug purposes)
*/
const std::string& get_name() const;
virtual std::string get_name() const
{ return name_; }
/**
* Get the type of the candidate action (useful for debug purposes)
*/
const std::string& get_type() const;
virtual std::string get_id() const
{ return id_; }
const std::string& get_id() const;
const std::string& get_engine() const;
virtual std::string get_engine() const
{ return engine_; }
int get_recursion_count() const;

View File

@ -72,21 +72,17 @@ config stage::to_config() const
return cfg;
}
const std::string& stage::get_id() const
std::string stage::get_id() const
{
return cfg_["id"];
}
const std::string& stage::get_engine() const
std::string stage::get_engine() const
{
return cfg_["engine"];
}
const std::string& stage::get_name() const
std::string stage::get_name() const
{
return cfg_["name"];
}

View File

@ -77,16 +77,9 @@ public:
*/
virtual config to_config() const;
virtual const std::string& get_id() const;
virtual const std::string& get_name() const;
virtual const std::string& get_engine() const;
virtual std::string get_id() const;
virtual std::string get_name() const;
virtual std::string get_engine() const;
protected:
/**

View File

@ -107,7 +107,7 @@ void configuration::init(const config &game_config)
description desc;
desc.id=id;
desc.text=ai_configuration["description"];
desc.text = ai_configuration["description"].str();
desc.cfg=ai_configuration;
ai_configurations_.insert(std::make_pair(id,desc));
@ -132,7 +132,7 @@ void configuration::add_era_ai_from_config(const config &era)
description desc;
desc.id=id;
desc.text=ai_configuration["description"];
desc.text = ai_configuration["description"].str();
desc.cfg=ai_configuration;
era_ai_configurations_.insert(std::make_pair(id,desc));

View File

@ -642,7 +642,7 @@ double move_leader_to_goals_phase::evaluate()
return BAD_SCORE;
}
id_ = goal["id"];
id_ = goal["id"].str();
if (leader->get_location() == dst_) {
//goal already reached
if (auto_remove_ && !id_.empty()) {

View File

@ -43,7 +43,7 @@ void fallback_to_other_ai::on_create()
{
config ai_cfg = cfg_.child_or_empty("ai");
//@todo 1.9.3 backward-compatability hack - try to update the old default ai config. remove in 1.9.3
config::proxy_string ai_algorithm = ai_cfg["ai_algorithm"];
std::string ai_algorithm = ai_cfg["ai_algorithm"];
if ((ai_algorithm.empty()) || (ai_algorithm=="default_ai")) {
if (configuration::parse_side_config(get_side(),cfg_,ai_cfg)) {
fallback_ai_ = manager::create_transient_ai("", ai_cfg, this);

View File

@ -747,9 +747,9 @@ void terrain_builder::parse_config(const config &cfg, bool local)
if(!br["x"].empty() && !br["y"].empty())
pbr.location_constraints =
map_location(atoi(br["x"].c_str()) - 1, atoi(br["y"].c_str()) - 1);
map_location(br["x"].to_int() - 1, br["y"].to_int() - 1);
pbr.probability = br["probability"].empty() ? -1 : atoi(br["probability"].c_str());
pbr.probability = br["probability"].empty() ? -1 : br["probability"].to_int();
// Mapping anchor indices to anchor locations.
anchormap anchors;
@ -764,10 +764,10 @@ void terrain_builder::parse_config(const config &cfg, bool local)
// of terrain constraints, if it does not exist.
map_location loc;
if (!tc["x"].empty()) {
loc.x = atoi(tc["x"].c_str());
loc.x = tc["x"];
}
if (!tc["y"].empty()) {
loc.y = atoi(tc["y"].c_str());
loc.y = tc["y"];
}
if (!tc["loc"].empty()) {
std::vector<std::string> sloc = utils::split(tc["loc"]);
@ -780,7 +780,7 @@ void terrain_builder::parse_config(const config &cfg, bool local)
add_constraints(pbr.constraints, loc, tc, br);
}
if (!tc["pos"].empty()) {
int pos = atoi(tc["pos"].c_str());
int pos = tc["pos"];
if(anchors.find(pos) == anchors.end()) {
WRN_NG << "Invalid anchor!\n";
continue;

View File

@ -461,7 +461,7 @@ namespace {
LOG_CS << "sending campaign '" << req["name"] << "' to " << network::ip_address(sock) << (gzipped?" using gzip":"");
config &campaign = campaigns().find_child("campaign", "name", req["name"]);
if (!campaign) {
network::send_data(construct_error("Add-on '" + req["name"] + "'not found."), sock, gzipped);
network::send_data(construct_error("Add-on '" + req["name"].str() + "'not found."), sock, gzipped);
} else {
if (gzipped)
{
@ -660,7 +660,7 @@ namespace {
//erase the campaign
write_file(campaign["filename"], std::string());
remove(campaign["filename"].c_str());
remove(campaign["filename"].str().c_str());
config::child_itors itors = campaigns().child_range("campaign");
for (size_t index = 0; itors.first != itors.second;

View File

@ -314,16 +314,15 @@ void cave_map_generator::place_passage(const passage& p)
}
const size_t windiness = atoi(p.cfg["windiness"].c_str());
const double laziness = std::max<double>(1.0,atof(p.cfg["laziness"].c_str()));
int windiness = p.cfg["windiness"];
double laziness = std::max<double>(1.0, p.cfg["laziness"].to_double());
passage_path_calculator calc(map_,wall_,laziness,windiness);
pathfind::plain_route rt = a_star_search(p.src, p.dst, 10000.0, &calc, width_, height_);
const size_t width = std::max<size_t>(1,atoi(p.cfg["width"].c_str()));
const size_t jagged = atoi(p.cfg["jagged"].c_str());
int width = std::max<int>(1, p.cfg["width"].to_int());
int jagged = p.cfg["jagged"];
for(std::vector<map_location>::const_iterator i = rt.steps.begin(); i != rt.steps.end(); ++i) {
std::set<map_location> locs;

View File

@ -26,29 +26,76 @@
#include "serialization/string_utils.hpp"
#include "util.hpp"
#include <cstdlib>
#include <cstring>
#include <deque>
static lg::log_domain log_config("config");
#define ERR_CF LOG_STREAM(err, log_config)
config::proxy_string &config::proxy_string::operator=(bool b)
bool config::attribute_value::empty() const
{
real_str_ = b ? "yes" : "no";
if (boost::get<const boost::blank>(&value)) return true;
if (const std::string *p = boost::get<const std::string>(&value)) return p->empty();
return false;
}
bool config::attribute_value::to_bool(bool def) const
{
if (const bool *p = boost::get<const bool>(&value)) return *p;
return def;
}
int config::attribute_value::to_int(int def) const
{
if (const int *p = boost::get<const int>(&value)) return *p;
return def;
}
double config::attribute_value::to_double(double def) const
{
if (const double *p = boost::get<const double>(&value)) return *p;
return def;
}
std::string config::attribute_value::str() const
{
static std::string s_yes("yes"), s_no("no");
if (const std::string *p = boost::get<const std::string>(&value)) return *p;
if (const t_string *p = boost::get<const t_string>(&value)) return p->str();
if (const bool *p = boost::get<const bool>(&value)) return *p ? s_yes : s_no;
if (const int *p = boost::get<const int>(&value)) return str_cast(*p);
if (const double *p = boost::get<const double>(&value)) return str_cast(*p);
return std::string();
}
t_string config::attribute_value::t_str() const
{
if (const t_string *p = boost::get<const t_string>(&value)) return *p;
return str();
}
config::attribute_value &config::attribute_value::operator=(const std::string &v)
{
if (v.empty()) { value = v; return *this; }
if (v == "yes" || v == "true") return *this = true;
if (v == "no" || v == "false") return *this = false;
char *eptr;
int i = strtol(v.c_str(), &eptr, 0);
if (*eptr == '\0') return *this = i;
double d = strtod(v.c_str(), &eptr);
if (*eptr == '\0') return *this = d;
value = v;
return *this;
}
config::proxy_string &config::proxy_string::operator=(int v)
config::attribute_value &config::attribute_value::operator=(const t_string &v)
{
real_str_ = str_cast(v);
if (!v.translatable()) return *this = v.str();
value = v;
return *this;
}
int config::proxy_string::to_int(int def) const
{
return lexical_cast_default(real_str_.c_str(), def);
}
config config::invalid;
const char* config::diff_track_attribute = "__diff_track";
@ -118,8 +165,8 @@ void config::append(const config& cfg)
add_child(value.key, value.cfg);
}
for(string_map::const_iterator j = cfg.values.begin(); j != cfg.values.end(); ++j) {
values[j->first] = j->second;
foreach (const attribute &v, cfg.values) {
values[v.first] = v.second;
}
}
@ -370,22 +417,14 @@ void config::remove_child(const std::string& key, size_t index)
delete res;
}
const t_string& config::operator[](const std::string& key) const
{
return get_attribute(key);
}
const t_string& config::get_attribute(const std::string& key) const
const config::attribute_value &config::operator[](const std::string &key) const
{
check_valid();
const string_map::const_iterator i = values.find(key);
if(i != values.end()) {
return i->second;
} else {
static const t_string empty_string;
return empty_string;
}
const attribute_map::const_iterator i = values.find(key);
if (i != values.end()) return i->second;
static const attribute_value empty_attribute;
return empty_attribute;
}
void config::merge_attributes(const config &cfg)
@ -393,10 +432,8 @@ void config::merge_attributes(const config &cfg)
check_valid(cfg);
assert(this != &cfg);
for (string_map::const_iterator i = cfg.values.begin(),
i_end = cfg.values.end(); i != i_end; ++i)
{
values[i->first] = i->second;
foreach (const attribute &v, cfg.values) {
values[v.first] = v.second;
}
}
@ -580,9 +617,9 @@ void config::get_diff(const config& c, config& res) const
config* inserts = NULL;
string_map::const_iterator i;
attribute_map::const_iterator i;
for(i = values.begin(); i != values.end(); ++i) {
const string_map::const_iterator j = c.values.find(i->first);
const attribute_map::const_iterator j = c.values.find(i->first);
if(j == c.values.end() || (i->second != j->second && i->second != "")) {
if(inserts == NULL) {
inserts = &res.add_child("insert");
@ -595,7 +632,7 @@ void config::get_diff(const config& c, config& res) const
config* deletes = NULL;
for(i = c.values.begin(); i != c.values.end(); ++i) {
const string_map::const_iterator itor = values.find(i->first);
const attribute_map::const_iterator itor = values.find(i->first);
if(itor == values.end() || itor->second == "") {
if(deletes == NULL) {
deletes = &res.add_child("delete");
@ -782,10 +819,7 @@ void config::merge_with(const config& c)
std::map<std::string, unsigned> visitations;
// Merge attributes first
string_map::const_iterator attrib_it, attrib_end = c.values.end();
for(attrib_it = c.values.begin(); attrib_it != attrib_end; ++attrib_it) {
values[attrib_it->first] = attrib_it->second;
}
merge_attributes(c);
// Now merge shared tags
all_children_iterator::Itor i, i_end = ordered_children.end();
@ -815,24 +849,7 @@ bool config::matches(const config &filter) const
check_valid(filter);
// First match values. all values should match.
for(string_map::const_iterator j = filter.values.begin(); j != filter.values.end(); ++j) {
if(!this->values.count(j->first)) return false;
const t_string& test_val = this->values.find(j->first)->second;
if(test_val != j->second) {
const std::string& boolcheck = j->second.base_str();
if(boolcheck == "yes" || boolcheck == "true" || boolcheck == "on") {
if(!utils::string_bool(test_val.base_str(), false)) {
return false;
}
} else if(boolcheck == "no" || boolcheck == "false" || boolcheck == "off") {
if(utils::string_bool(test_val.base_str(), true)) {
return false;
}
} else {
return false;
}
}
}
if (values != filter.values) return false;
// Now, match the kids
foreach (const any_child &i, filter.all_children_range())
@ -899,29 +916,16 @@ std::string config::hash() const
hash_str[hash_length] = 0;
i = 0;
for(string_map::const_iterator val = values.begin(); val != values.end(); ++val) {
if(val->first.size() && val->second.size()) {
for(c = val->first.begin(); c != val->first.end(); ++c) {
if(utils::portable_isspace(*c)) {
continue;
}
hash_str[i] ^= *c;
++i;
if(i == hash_length) {
i = 0;
}
}
const std::string &base_str = val->second.base_str();
for(c = base_str.begin(); c != base_str.end(); ++c) {
if(utils::portable_isspace(*c)) {
continue;
}
hash_str[i] ^= *c;
++i;
if(i == hash_length) {
i = 0;
}
}
foreach (const attribute &val, values)
{
for (c = val.first.begin(); c != val.first.end(); ++c) {
hash_str[i] ^= *c;
if (++i == hash_length) i = 0;
}
std::string base_str = val.second.t_str().base_str();
for (c = base_str.begin(); c != base_str.end(); ++c) {
hash_str[i] ^= *c;
if (++i == hash_length) i = 0;
}
}

View File

@ -34,6 +34,7 @@
#include <ostream>
#include <string>
#include <vector>
#include <boost/variant.hpp>
#include "game_errors.hpp"
#include "tstring.hpp"
@ -145,7 +146,57 @@ public:
typedef std::pair<child_iterator,child_iterator> child_itors;
typedef std::pair<const_child_iterator,const_child_iterator> const_child_itors;
typedef string_map::value_type attribute;
/**
* Variant for storing WML attributes.
* The most efficient type is used when assigning a value. For instance,
* strings "yes", "no", "true", "false" will be detected and stored as boolean.
* @note The blank variant is only used when querying missing attributes.
* It is not stored in config objects.
*/
class attribute_value
{
typedef boost::variant<boost::blank, bool, int, double, std::string, t_string> value_type;
value_type value;
public:
attribute_value &operator=(const attribute_value &other)
{ value = other.value; return *this; }
attribute_value &operator=(bool v)
{ value = v; return *this; }
attribute_value &operator=(int v)
{ value = v; return *this; }
attribute_value &operator=(double v)
{ value = v; return *this; }
attribute_value &operator=(const char *v)
{ return *this = std::string(v); }
attribute_value &operator=(const std::string &v);
attribute_value &operator=(const t_string &v);
bool to_bool(bool def = false) const;
int to_int(int def = 0) const;
double to_double(double def = 0.) const;
bool empty() const;
std::string str() const;
t_string t_str() const;
operator int() const { return to_int(); }
operator std::string() const { return str(); }
operator t_string() const { return t_str(); }
bool operator==(const attribute_value &other) const
{ return value == other.value; }
bool operator!=(const attribute_value &other) const
{ return !(value == other.value); }
inline friend std::ostream& operator<<(std::ostream &os, const attribute_value &v)
{ return os << v.str(); }
};
typedef std::map<std::string, attribute_value> attribute_map;
typedef attribute_map::value_type attribute;
struct const_attribute_iterator
{
@ -154,7 +205,7 @@ public:
typedef int difference_type;
typedef const attribute *pointer;
typedef const attribute &reference;
typedef string_map::const_iterator Itor;
typedef attribute_map::const_iterator Itor;
explicit const_attribute_iterator(const Itor &i): i_(i) {}
const_attribute_iterator &operator++() { ++i_; return *this; }
@ -170,40 +221,6 @@ public:
Itor i_;
};
class proxy_string
{
t_string &real_str_;
public:
proxy_string(config &owner, const std::string &key)
: real_str_(owner.values[key]) {}
proxy_string &operator=(const proxy_string &other)
{ return this->operator=(other.real_str_); }
proxy_string &operator=(bool);
proxy_string &operator=(int);
proxy_string& operator=(const char *str)
{ real_str_ = str; return *this; }
proxy_string& operator=(const std::string &str)
{ real_str_ = str; return *this; }
proxy_string& operator=(const t_string &str)
{ real_str_ = str; return *this; }
int to_int(int def = 0) const;
bool empty() const { return real_str_.empty(); }
const std::string &str() const { return real_str_.str(); }
const t_string &t_str() const { return real_str_; }
operator int() const { return to_int(); }
operator std::string() const { return real_str_.str(); }
operator t_string() const { return real_str_; }
inline friend std::ostream& operator<<(std::ostream &os, const proxy_string &str)
{ return os << str.real_str_; }
};
typedef std::pair<const_attribute_iterator,const_attribute_iterator> const_attr_itors;
child_itors child_range(const std::string& key);
@ -232,9 +249,9 @@ public:
config& add_child(const std::string& key, const config& val);
config& add_child_at(const std::string& key, const config& val, size_t index);
proxy_string operator[](const std::string& key)
{ return proxy_string(*this, key); }
const t_string& operator[](const std::string& key) const;
attribute_value &operator[](const std::string &key)
{ return values[key]; }
const attribute_value &operator[](const std::string &key) const;
/**
* Returns a reference to the first child with the given @a key.
@ -242,7 +259,6 @@ public:
*/
config &child_or_add(const std::string &key);
const t_string& get_attribute(const std::string& key) const;
bool has_attribute(const std::string &key) const;
void remove_attribute(const std::string &key);
void merge_attributes(const config &);
@ -394,7 +410,7 @@ public:
private:
/** All the attributes of this node. */
string_map values;
attribute_map values;
/** A list of all children of this node. */
child_map children;

View File

@ -377,8 +377,8 @@ void save_preview_pane::draw_contents()
if(map_data.empty()) {
const config &scenario = game_config_->find_child(summary["campaign_type"], "id", summary["scenario"]);
if (scenario && !scenario.find_child("side", "shroud", "yes")) {
map_data = scenario["map_data"];
if (map_data.empty() && !scenario["map"].empty()) {
map_data = scenario["map_data"].str();
if (map_data.empty() && scenario.has_attribute("map")) {
try {
map_data = read_map(scenario["map"]);
} catch(io_exception& e) {

View File

@ -34,7 +34,7 @@ static bool is_valid_terrain(t_translation::t_terrain c) {
}
terrain_group::terrain_group(const config& cfg, display& gui):
id(cfg["id"]), name(cfg["name"]),
id(cfg["id"]), name(cfg["name"].t_str()),
button(gui.video(), "", gui::button::TYPE_CHECK, cfg["icon"]),
core(utils::string_bool(cfg["core"], false))
{

View File

@ -1128,12 +1128,12 @@ bool game_controller::new_campaign()
}
const config &campaign = campaigns[campaign_num];
state_.classification().campaign = campaign["id"];
state_.classification().abbrev = campaign["abbrev"];
state_.classification().campaign = campaign["id"].str();
state_.classification().abbrev = campaign["abbrev"].str();
// we didn't specify in the command line the scenario to be started
if (jump_to_campaign_.scenario_id_.empty())
state_.classification().scenario = campaign["first_scenario"];
state_.classification().scenario = campaign["first_scenario"].str();
else
{
config scenario;
@ -1150,8 +1150,8 @@ bool game_controller::new_campaign()
}
state_.classification().scenario = jump_to_campaign_.scenario_id_;
}
state_.classification().end_text = campaign["end_text"];
state_.classification().end_text_duration = lexical_cast_default<unsigned int>(campaign["end_text_duration"]);
state_.classification().end_text = campaign["end_text"].str();
state_.classification().end_text_duration = campaign["end_text_duration"];
const std::string difficulty_descriptions = campaign["difficulty_descriptions"];
std::vector<std::string> difficulty_options = utils::split(difficulty_descriptions, ';');
@ -1194,7 +1194,7 @@ bool game_controller::new_campaign()
cache_.add_define(difficulties[difficulty]);
}
state_.classification().campaign_define = campaign["define"];
state_.classification().campaign_define = campaign["define"].str();
state_.classification().campaign_xtra_defines = utils::split(campaign["extra_defines"]);
return true;

View File

@ -151,66 +151,63 @@ namespace game_config
const config& v = *cfg;
base_income = lexical_cast_default<int>(v["base_income"], 2);
village_income = lexical_cast_default<int>(v["village_income"], 1);
poison_amount = lexical_cast_default<int>(v["poison_amount"], 8);
rest_heal_amount = lexical_cast_default<int>(v["rest_heal_amount"], 2);
recall_cost = lexical_cast_default<int>(v["recall_cost"], 20);
kill_experience = lexical_cast_default<int>(v["kill_experience"], 8);
lobby_refresh = lexical_cast_default<unsigned>(v["lobby_refresh"], 2000);
base_income = v["base_income"].to_int(2);
village_income = v["village_income"].to_int(1);
poison_amount = v["poison_amount"].to_int(8);
rest_heal_amount = v["rest_heal_amount"].to_int(2);
recall_cost = v["recall_cost"].to_int(20);
kill_experience = v["kill_experience"].to_int(8);
lobby_refresh = v["lobby_refresh"].to_int(2000);
game_icon = v["icon"];
game_title = v["title"];
game_logo = v["logo"];
title_music = v["title_music"];
lobby_music = v["lobby_music"];
game_icon = v["icon"].str();
game_title = v["title"].str();
game_logo = v["logo"].str();
title_music = v["title_music"].str();
lobby_music = v["lobby_music"].str();
title_logo_x = lexical_cast_default<int>(v["logo_x"]);
title_logo_y = lexical_cast_default<int>(v["logo_y"]);
title_buttons_x = lexical_cast_default<int>(v["buttons_x"]);
title_buttons_y = lexical_cast_default<int>(v["buttons_y"]);
title_buttons_padding = lexical_cast_default<int>(v["buttons_padding"]);
title_logo_x = v["logo_x"];
title_logo_y = v["logo_y"];
title_buttons_x = v["buttons_x"];
title_buttons_y = v["buttons_y"];
title_buttons_padding = v["buttons_padding"];
title_tip_x = lexical_cast_default<int>(v["tip_x"]);
title_tip_width = lexical_cast_default<int>(v["tip_width"]);
title_tip_padding = lexical_cast_default<int>(v["tip_padding"]);
title_tip_x = v["tip_x"].to_int();
title_tip_width = v["tip_width"].to_int();
title_tip_padding = v["tip_padding"].to_int();
energy_image = v["energy_image"];
moved_ball_image = v["moved_ball_image"];
unmoved_ball_image = v["unmoved_ball_image"];
partmoved_ball_image = v["partmoved_ball_image"];
enemy_ball_image = v["enemy_ball_image"];
ally_ball_image = v["ally_ball_image"];
flag_image = v["flag_image"];
flag_icon_image = v["flag_icon_image"];
energy_image = v["energy_image"].str();
moved_ball_image = v["moved_ball_image"].str();
unmoved_ball_image = v["unmoved_ball_image"].str();
partmoved_ball_image = v["partmoved_ball_image"].str();
enemy_ball_image = v["enemy_ball_image"].str();
ally_ball_image = v["ally_ball_image"].str();
flag_image = v["flag_image"].str();
flag_icon_image = v["flag_icon_image"].str();
hp_bar_scaling = lexical_cast_default<double>(v["hp_bar_scaling"]);
xp_bar_scaling = lexical_cast_default<double>(v["xp_bar_scaling"]);
foot_speed_prefix = utils::split(v["footprint_prefix"]);
foot_teleport_enter = v["footprint_teleport_enter"];
foot_teleport_exit = v["footprint_teleport_exit"];
foot_teleport_enter = v["footprint_teleport_enter"].str();
foot_teleport_exit = v["footprint_teleport_exit"].str();
terrain_mask_image = v["terrain_mask_image"];
grid_image = v["grid_image"];
unreachable_image = v["unreachable_image"];
terrain_mask_image = v["terrain_mask_image"].str();
grid_image = v["grid_image"].str();
unreachable_image = v["unreachable_image"].str();
observer_image = v["observer_image"];
tod_bright_image = v["tod_bright_image"];
tod_dark_image = v["tod_dark_image"];
observer_image = v["observer_image"].str();
tod_bright_image = v["tod_bright_image"].str();
tod_dark_image = v["tod_dark_image"].str();
level_image = v["level_image"];
ellipsis_image = v["ellipsis_image"];
default_victory_music = v["default_victory_music"];
default_defeat_music = v["default_defeat_music"];
level_image = v["level_image"].str();
ellipsis_image = v["ellipsis_image"].str();
default_victory_music = v["default_victory_music"].str();
default_defeat_music = v["default_defeat_music"].str();
add_color_info(v);
flag_rgb = v["flag_rgb"];
if( !flag_rgb.size()){
flag_rgb="flag_green";
}
if (v.has_attribute("flag_rgb")) flag_rgb = v["flag_rgb"].str();
red_green_scale = string2rgb(v["red_green_scale"]);
if (red_green_scale.empty()) {
@ -225,8 +222,8 @@ namespace game_config
foreach (const config &server, v.child_range("server"))
{
server_info sinf;
sinf.name = server["name"];
sinf.address = server["address"];
sinf.name = server["name"].str();
sinf.address = server["address"].str();
server_list.push_back(sinf);
}
}

View File

@ -438,7 +438,7 @@ namespace game_events {
foreach (const vconfig &values, variables)
{
const std::string name = values["name"];
const std::string& value = resources::state_of_game->get_variable_const(name);
std::string value = resources::state_of_game->get_variable_const(name);
const double num_value = atof(value.c_str());
@ -1192,7 +1192,7 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
game_state *state_of_game = resources::state_of_game;
const std::string name = cfg["name"];
config::proxy_string var = state_of_game->get_variable(name);
config::attribute_value &var = state_of_game->get_variable(name);
const t_string &literal = cfg.get_config()["literal"]; // no $var substitution
if(literal.empty() == false) {
@ -2657,7 +2657,7 @@ WML_HANDLER_FUNCTION(while, event_info, cfg)
WML_HANDLER_FUNCTION(switch, event_info, cfg)
{
const std::string var_name = cfg["variable"];
const std::string &var = resources::state_of_game->get_variable_const(var_name);
std::string var = resources::state_of_game->get_variable_const(var_name);
bool not_found = true;
// execute all cases where the value matches
@ -3005,7 +3005,7 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
replay::process_error("input expected but none found\n");
return;
}
text_input_result = (*action)["text"];
text_input_result = (*action)["text"].str();
}
}

View File

@ -288,8 +288,8 @@ const std::vector<game_config::server_info>& server_list()
pref_servers.insert(pref_servers.begin(), game_servers.begin(), game_servers.end());
foreach (const config &server, get_prefs()->child_range("server")) {
game_config::server_info sinf;
sinf.name = server["name"];
sinf.address = server["address"];
sinf.name = server["name"].str();
sinf.address = server["address"].str();
pref_servers.push_back(sinf);
}
}

View File

@ -952,7 +952,7 @@ void preferences_dialog::process_event()
advanced_slider_.hide(hide_int);
advanced_slider_label_.hide(hide_int);
if(value.empty()) {
value = pref["default"];
value = pref["default"].str();
}
if (pref["type"] == "boolean") {
advanced_button_.set_width(0);
@ -1019,7 +1019,7 @@ void preferences_dialog::set_advanced_menu()
std::ostringstream str;
std::string field = preferences::get(adv["field"]);
if(field.empty()) {
field = adv["default"];
field = adv["default"].str();
}
if(field == "yes") {
@ -1165,7 +1165,7 @@ void preferences_dialog::set_selection(int index)
const bool hide_advanced = tab_ != ADVANCED_TAB;
advanced_.hide(hide_advanced);
const std::string adv_type = get_advanced_pref() != NULL ? (*get_advanced_pref())["type"] : "";
std::string adv_type = get_advanced_pref() != NULL ? (*get_advanced_pref())["type"].str() : "";
const bool hide_advanced_bool = hide_advanced || adv_type != "boolean";
const bool hide_advanced_int = hide_advanced || adv_type != "int";
advanced_button_.hide(hide_advanced_bool);

View File

@ -80,7 +80,7 @@ game_classification::game_classification(const config& cfg):
label(cfg["label"]),
parent(cfg["parent"]),
version(cfg["version"]),
campaign_type(cfg["campaign_type"].empty() ? "scenario" : cfg["campaign_type"]),
campaign_type(cfg["campaign_type"].empty() ? "scenario" : cfg["campaign_type"].str()),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
campaign(cfg["campaign"]),
@ -91,7 +91,7 @@ game_classification::game_classification(const config& cfg):
completion(cfg["completion"]),
end_text(cfg["end_text"]),
end_text_duration(lexical_cast_default<unsigned int>(cfg["end_text_duration"])),
difficulty(cfg["difficulty"].empty() ? "NORMAL" : cfg["difficulty"])
difficulty(cfg["difficulty"].empty() ? "NORMAL" : cfg["difficulty"].str())
{}
game_classification::game_classification(const game_classification& gc):
@ -428,16 +428,16 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
if (side["canrecruit"] == "yes")
{
leader = side["id"];
leader_image = side["image"];
leader = side["id"].str();
leader_image = side["image"].str();
break;
}
foreach (const config &u, side.child_range("unit"))
{
if (utils::string_bool(u["canrecruit"], false)) {
leader = u["id"];
leader_image = u["image"];
leader = u["id"].str();
leader_image = u["image"].str();
break;
}
}
@ -462,7 +462,7 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
}
}
config::proxy_string game_state::get_variable(const std::string& key)
config::attribute_value &game_state::get_variable(const std::string& key)
{
return variable_info(key, true, variable_info::TYPE_SCALAR).as_scalar();
}
@ -471,7 +471,7 @@ t_string game_state::get_variable_const(const std::string& key) const
{
variable_info to_get(key, false, variable_info::TYPE_SCALAR);
if(!to_get.is_valid) {
config::proxy_string to_return = temporaries[key];
config::attribute_value &to_return = temporaries[key];
if (key.size() > 7 && key.substr(key.size()-7) == ".length") {
// length is a special attribute, so guarantee its correctness
to_return = "0";
@ -960,7 +960,7 @@ void game_state::set_menu_items(const config::const_child_itors &menu_items)
clear_wmi(wml_menu_items);
foreach (const config &item, menu_items)
{
const std::string &id = item["id"].base_str();
std::string id = item["id"];
wml_menu_item*& mref = wml_menu_items[id];
if(mref == NULL) {
mref = new wml_menu_item(id, &item);
@ -1021,7 +1021,7 @@ wml_menu_item::wml_menu_item(const std::string& id, const config* cfg) :
}
name = temp.str();
if(cfg != NULL) {
image = (*cfg)["image"];
image = (*cfg)["image"].str();
description = (*cfg)["description"];
needs_select = utils::string_bool((*cfg)["needs_select"], false);
if (const config &c = cfg->child("show_if")) show_if = c;

View File

@ -96,7 +96,7 @@ public:
// Variable access
config::proxy_string get_variable(const std::string &varname);
config::attribute_value &get_variable(const std::string &varname);
virtual t_string get_variable_const(const std::string& varname) const;
config& get_variable_cfg(const std::string& varname);

View File

@ -257,7 +257,7 @@ report generate_report(TYPE type,
str << span_color(u->xp_color()) << u->experience()
<< '/' << u->max_experience() << naps;
tooltip << _("Experience Modifier: ") << ((level["experience_modifier"] != "") ? level["experience_modifier"] : "100") << "%";
tooltip << _("Experience Modifier: ") << (!level["experience_modifier"].empty() ? level["experience_modifier"].str() : "100") << '%';
return report(str.str(), "", tooltip.str());
}
case UNIT_ADVANCEMENT_OPTIONS: {

View File

@ -99,7 +99,7 @@ tresolution_definition_::tresolution_definition_(const config& cfg)
tcontrol_definition::tcontrol_definition(const config& cfg)
: id(cfg["id"])
, description(cfg["description"])
, description(cfg["description"].t_str())
, resolutions()
{
/*WIKI

View File

@ -218,8 +218,8 @@ const std::string& twindow_builder::read(const config& cfg)
*
*/
id_ = cfg["id"];
description_ = cfg["description"];
id_ = cfg["id"].str();
description_ = cfg["description"].str();
VALIDATE(!id_.empty(), missing_mandatory_wml_key("window", "id"));
VALIDATE(!description_.empty(), missing_mandatory_wml_key("window", "description"));
@ -354,7 +354,7 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
foreach (const config &lg, cfg.child_range("linked_group")) {
tlinked_group linked_group;
linked_group.id = lg["id"];
linked_group.id = lg["id"].str();
linked_group.fixed_width = utils::string_bool(lg["fixed_width"]);
linked_group.fixed_height = utils::string_bool(lg["fixed_height"]);

View File

@ -29,9 +29,9 @@ tbuilder_control::tbuilder_control(const config& cfg)
, id(cfg["id"])
, definition(cfg["definition"])
, linked_group(cfg["linked_group"])
, label(cfg["label"])
, tooltip(cfg["tooltip"])
, help(cfg["help"])
, label(cfg["label"].t_str())
, tooltip(cfg["tooltip"].t_str())
, help(cfg["help"].t_str())
, use_tooltip_on_label_overflow(
utils::string_bool("use_tooltip_on_label_overflow", true))
#ifndef LOW_MEM

View File

@ -35,8 +35,8 @@ tbuilder_slider::tbuilder_slider(const config& cfg)
, maximum_value_(lexical_cast_default<int>(cfg["maximum_value"]))
, step_size_(lexical_cast_default<unsigned>(cfg["step_size"]))
, value_(lexical_cast_default<unsigned>(cfg["value"]))
, minimum_value_label_(cfg["minimum_value_label"])
, maximum_value_label_(cfg["maximum_value_label"])
, minimum_value_label_(cfg["minimum_value_label"].t_str())
, maximum_value_label_(cfg["maximum_value_label"].t_str())
, value_labels_()
{
const config& labels = cfg.child("value_labels");

View File

@ -67,12 +67,12 @@ void taddon_list::pre_show(CVideo& /*video*/, twindow& window)
item["label"] = tmp;
data.insert(std::make_pair("name", item));
tmp = c["version"];
tmp = c["version"].str();
utils::truncate_as_wstring(tmp, 12);
item["label"] = tmp;
data.insert(std::make_pair("version", item));
tmp = c["author"];
tmp = c["author"].str();
utils::truncate_as_wstring(tmp, 16);
item["label"] = tmp;
data.insert(std::make_pair("author", item));

View File

@ -194,8 +194,8 @@ game_info::game_info(const config& game, const config& game_config)
utils::string_map symbols;
symbols["era_id"] = game["mp_era"];
if (era_cfg) {
era = era_cfg["name"];
era_short = era_cfg["short_name"];
era = era_cfg["name"].str();
era_short = era_cfg["short_name"].str();
if (era_short.empty()) {
era_short = make_short_name(era);
}
@ -243,7 +243,7 @@ game_info::game_info(const config& game, const config& game_config)
level_cfg = &game_config.find_child("generic_multiplayer", "id", game["mp_scenario"]);
}
if (*level_cfg) {
scenario = level_cfg->get_attribute("name");
scenario = (*level_cfg)["name"].str();
map_info += scenario;
// reloaded games do not match the original scenario hash,
// so it makes no sense to test them, they always would appear
@ -312,9 +312,9 @@ game_info::game_info(const config& game, const config& game_config)
vision = _("none");
}
if (game["mp_countdown"] == "yes" ) {
time_limit = game["mp_countdown_init_time"] + "+"
+ game["mp_countdown_turn_bonus"] + "/"
+ game["mp_countdown_action_bonus"];
time_limit = game["mp_countdown_init_time"].str() + "+"
+ game["mp_countdown_turn_bonus"].str() + "/"
+ game["mp_countdown_action_bonus"].str();
} else {
time_limit = "";
}

View File

@ -1372,7 +1372,7 @@ void tlobby_main::process_message(const config &data, bool whisper /*= false*/)
{
std::string sender = data["sender"];
DBG_LB << "process message from " << sender << " "
<< (whisper ? "(w)" : "") << ", len " << data["message"].size() << "\n";
<< (whisper ? "(w)" : "") << ", len " << data["message"].str().size() << '\n';
if (preferences::is_ignored(sender)) return;
const std::string& message = data["message"];
preferences::parse_admin_authentication(sender, message);

View File

@ -106,8 +106,8 @@ void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window)
{
if (utils::string_bool(map["allow_new_game"], true)) {
string_map item;
item.insert(std::make_pair("label", map["name"]));
item.insert(std::make_pair("tooltip", map["name"]));
item.insert(std::make_pair("label", map["name"].str()));
item.insert(std::make_pair("tooltip", map["name"].str()));
list.add_row(item);
// This hack is needed since the next item is too wide to fit.

View File

@ -243,7 +243,7 @@ const std::string& tgui_definition::read(const config& cfg)
* @end_table
*
*/
id = cfg["id"];
id = cfg["id"].str();
description = cfg["description"];
VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
@ -345,10 +345,10 @@ const std::string& tgui_definition::read(const config& cfg)
VALIDATE(double_click_time_, missing_mandatory_wml_key("settings", "double_click_time"));
sound_button_click_ = settings["sound_button_click"];
sound_toggle_button_click_ = settings["sound_toggle_button_click"];
sound_toggle_panel_click_ = settings["sound_toggle_panel_click"];
sound_slider_adjust_ = settings["sound_slider_adjust"];
sound_button_click_ = settings["sound_button_click"].str();
sound_toggle_button_click_ = settings["sound_toggle_button_click"].str();
sound_toggle_panel_click_ = settings["sound_toggle_panel_click"].str();
sound_slider_adjust_ = settings["sound_slider_adjust"].str();
return id;
}

View File

@ -903,7 +903,7 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
else if (section_cfg != NULL) {
const std::vector<std::string> sections = utils::quoted_split((*section_cfg)["sections"]);
sec.level = level;
const std::string id = level == 0 ? "toplevel" : (*section_cfg)["id"];
std::string id = level == 0 ? "toplevel" : (*section_cfg)["id"].str();
if (level != 0) {
if (!is_valid_id(id)) {
std::stringstream ss;
@ -911,7 +911,7 @@ void parse_config_internal(const config *help_cfg, const config *section_cfg,
throw parse_error(ss.str());
}
}
const std::string title = level == 0 ? "" : (*section_cfg)["title"];
std::string title = level == 0 ? "" : (*section_cfg)["title"].str();
sec.id = id;
sec.title = title;
std::vector<std::string>::const_iterator it;

View File

@ -313,10 +313,10 @@ void terrain_label::read(const config &cfg)
SDL_Color colour = font::LABEL_COLOUR;
std::string tmp_colour = cfg["colour"];
text_ = cfg["text"];
team_name_ = cfg["team_name"];
visible_in_fog_ = utils::string_bool(cfg["visible_in_fog"],true);
visible_in_shroud_ = utils::string_bool(cfg["visible_in_shroud"],false);
text_ = cfg["text"].str();
team_name_ = cfg["team_name"].str();
visible_in_fog_ = cfg["visible_in_fog"].to_bool(true);
visible_in_shroud_ = cfg["visible_in_shroud"].to_bool();
text_ = utils::interpolate_variables_into_string(text_, vs);
team_name_ = utils::interpolate_variables_into_string(team_name_, vs);

View File

@ -366,7 +366,7 @@ struct road_path_calculator : pathfind::cost_calculator
map_(terrain),
cfg_(cfg),
// Find out how windy roads should be.
windiness_(std::max<int>(1,atoi(cfg["road_windiness"].c_str()))),
windiness_(std::max<int>(1, cfg["road_windiness"].to_int())),
seed_(rand()),
cache_()
{
@ -425,7 +425,7 @@ double road_path_calculator::cost(const location& loc,
terrain = t_translation::write_terrain_code(c);
double res = getNoPathValue();
if (const config &child = cfg_.find_child("road_cost", "terrain", terrain)) {
res = atof(child["cost"].c_str());
res = child["cost"].to_double();
}
cache_.insert(std::pair<t_translation::t_terrain, double>(c,res));
@ -535,7 +535,7 @@ static map_location place_village(const t_translation::t_map& map,
std::set<map_location> locs;
get_tiles_radius(loc,radius,locs);
map_location best_loc;
size_t best_rating = 0;
int best_rating = 0;
for(std::set<map_location>::const_iterator i = locs.begin();
i != locs.end(); ++i) {
@ -557,7 +557,7 @@ static map_location place_village(const t_translation::t_map& map,
adjacent_liked = &(adj_liked_cache[t]);
}
size_t rating = atoi(child["rating"].c_str());
int rating = child["rating"];
map_location adj[6];
get_adjacent_tiles(map_location(i->x,i->y),adj);
for(size_t n = 0; n != 6; ++n) {
@ -819,8 +819,9 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
for(int tries = 0; tries != 100; ++tries) {
const int x = rand()%width;
const int y = rand()%height;
if(heights[x][y] > atoi(cfg["min_lake_height"].c_str())) {
const std::vector<location> river = generate_river(heights,terrain,x,y,atoi(cfg["river_frequency"].c_str()));
if (heights[x][y] > cfg["min_lake_height"].to_int()) {
std::vector<location> river = generate_river(heights,
terrain, x, y, cfg["river_frequency"]);
if(river.empty() == false && labels != NULL) {
std::string base_name;
@ -844,7 +845,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
LOG_NG << "generating lake...\n";
std::set<location> locs;
const bool res = generate_lake(terrain,x,y,atoi(cfg["lake_size"].c_str()),locs);
bool res = generate_lake(terrain, x, y, cfg["lake_size"], locs);
if(res && labels != NULL) {
bool touches_other_lake = false;
@ -901,8 +902,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
* more interesting types than the default.
*/
const height_map temperature_map = generate_height_map(width,height,
(atoi(cfg["temperature_iterations"].c_str())*width*height)/default_dimensions,
atoi(cfg["temperature_size"].c_str()),0,0);
cfg["temperature_iterations"].to_int() * width * height / default_dimensions,
cfg["temperature_size"], 0, 0);
LOG_NG << "generated temperature map...\n";
LOG_NG << (SDL_GetTicks() - ticks) << "\n"; ticks = SDL_GetTicks();
@ -976,7 +977,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
const int min_y = height/3 + 3;
const int max_x = (width/3)*2 - 4;
const int max_y = (height/3)*2 - 4;
const size_t min_distance = atoi(castle_config["min_distance"].c_str());
int min_distance = castle_config["min_distance"];
location best_loc;
int best_ranking = 0;
@ -1016,7 +1017,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
// Place roads.
// We select two tiles at random locations on the borders
// of the map, and try to build roads between them.
size_t nroads = atoi(cfg["roads"].c_str());
int nroads = cfg["roads"];
if(roads_between_castles) {
nroads += castles.size()*castles.size();
}
@ -1024,7 +1025,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
std::set<location> bridges;
road_path_calculator calc(terrain,cfg);
for(size_t road = 0; road != nroads; ++road) {
for (int road = 0; road != nroads; ++road) {
log_scope("creating road");
/*
@ -1040,7 +1041,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
dst.x += width/3 - 1;
dst.y += height/3 - 1;
if(roads_between_castles && road < castles.size()*castles.size()) {
if (roads_between_castles && road < int(castles.size() * castles.size())) {
const size_t src_castle = road/castles.size();
const size_t dst_castle = road%castles.size();
if(src_castle >= dst_castle) {

View File

@ -52,42 +52,42 @@ default_map_generator::default_map_generator(const config &cfg) :
{
if (!cfg) return;
const int width = ::atoi(cfg["map_width"].c_str());
int width = cfg["map_width"];
if (width > 0)
width_ = width;
const int height = ::atoi(cfg["map_height"].c_str());
int height = cfg["map_height"];
if (height > 0)
height_ = height;
default_width_ = width_;
default_height_ = height_;
const int iterations = ::atoi(cfg["iterations"].c_str());
int iterations = cfg["iterations"];
if (iterations > 0)
iterations_ = iterations;
const int hill_size = ::atoi(cfg["hill_size"].c_str());
int hill_size = cfg["hill_size"];
if (hill_size > 0)
hill_size_ = hill_size;
const int max_lakes = ::atoi(cfg["max_lakes"].c_str());
int max_lakes = cfg["max_lakes"];
if (max_lakes > 0)
max_lakes_ = max_lakes;
const int nvillages = ::atoi(cfg["villages"].c_str());
int nvillages = cfg["villages"];
if (nvillages > 0)
nvillages_ = nvillages;
const int castle_size = ::atoi(cfg["castle_size"].c_str());
int castle_size = cfg["castle_size"];
if (castle_size > 0)
castle_size_ = castle_size;
const int nplayers = ::atoi(cfg["players"].c_str());
int nplayers = cfg["players"];
if (nplayers > 0)
nplayers_ = nplayers;
const int island_size = ::atoi(cfg["island_size"].c_str());
int island_size = cfg["island_size"];
if (island_size > 0)
island_size_ = island_size;
}

View File

@ -3140,7 +3140,7 @@ void console_handler::do_choose_level() {
if (id == menu_handler_.gamestate_.classification().next_scenario)
next = nb;
++nb;
scenario = mp["next_scenario"];
scenario = mp["next_scenario"].str();
}
}
std::sort(options.begin(), options.end());

View File

@ -107,10 +107,10 @@ void mp_game_settings::set_from_config(const config& game_cfg)
const config& rs = game_cfg.child("replay_start");
// if it's a replay the multiplayer section can be in the replay_start tag else fallback to top level
const config& cfg = mp ? mp : rs ? (rs.child("multiplayer") ? rs.child("multiplayer") : game_cfg) : game_cfg;
name = cfg["scenario"];
hash = cfg["hash"];
mp_era = cfg["mp_era"];
mp_scenario = cfg["mp_scenario"];
name = cfg["scenario"].str();
hash = cfg["hash"].str();
mp_era = cfg["mp_era"].str();
mp_scenario = cfg["mp_scenario"].str();
xp_modifier = lexical_cast_default<int>(cfg["experience_modifier"]);
use_map_settings = utils::string_bool(cfg["mp_use_map_settings"]);
fog_game = utils::string_bool(cfg["mp_fog"]);

View File

@ -161,7 +161,7 @@ static server_type open_connection(game_display& disp, const std::string& origin
// Check for "redirect" messages
if (const config &redirect = data.child("redirect"))
{
host = redirect["host"];
host = redirect["host"].str();
port = lexical_cast_default<unsigned int>(redirect["port"], 15000);
if(shown_hosts.find(hostpair(host,port)) != shown_hosts.end()) {

View File

@ -61,24 +61,24 @@ connect::side::side(connect& parent, const config& cfg, int index) :
parent_(&parent),
cfg_(cfg),
index_(index),
id_(cfg_.get_attribute("id")),
player_id_(cfg_.get_attribute("player_id")),
save_id_(cfg_.get_attribute("save_id")),
current_player_(cfg_.get_attribute("current_player")),
id_(cfg_["id"]),
player_id_(cfg_["player_id"]),
save_id_(cfg_["save_id"]),
current_player_(cfg_["current_player"]),
controller_(CNTR_NETWORK),
faction_(lexical_cast_default<int>(cfg_.get_attribute("faction"), 0)),
faction_(cfg_["faction"]),
team_(0),
colour_(index),
gold_(lexical_cast_default<int>(cfg_.get_attribute("gold"), 100)),
income_(lexical_cast_default<int>(cfg_.get_attribute("income"), 0)),
gold_(cfg_["gold"].to_int(100)),
income_(cfg_["income"]),
leader_(),
gender_(),
ai_algorithm_(),
ready_for_start_(false),
gold_lock_(utils::string_bool(cfg_.get_attribute("gold_lock"), false)),
income_lock_(utils::string_bool(cfg_.get_attribute("income_lock"), false)),
team_lock_(utils::string_bool(cfg_.get_attribute("team_lock"), false)),
colour_lock_(utils::string_bool(cfg_.get_attribute("colour_lock"), false)),
gold_lock_(cfg_["gold_lock"].to_bool()),
income_lock_(cfg_["income_lock"].to_bool()),
team_lock_(cfg_["team_lock"].to_bool()),
colour_lock_(cfg_["colour_lock"].to_bool()),
player_number_(parent.video(), lexical_cast_default<std::string>(index+1, ""),
font::SIZE_LARGE, font::LOBBY_COLOUR),
combo_controller_(new gui::combo_drag(parent.disp(), parent.player_types_, parent.combo_control_group_)),
@ -93,8 +93,8 @@ connect::side::side(connect& parent, const config& cfg, int index) :
slider_income_(parent.video()),
label_gold_(parent.video(), "100", font::SIZE_SMALL, font::LOBBY_COLOUR),
label_income_(parent.video(), _("Normal"), font::SIZE_SMALL, font::LOBBY_COLOUR),
allow_player_(utils::string_bool(cfg_.get_attribute("allow_player"), true)),
allow_changes_(utils::string_bool(cfg_.get_attribute("allow_changes"), true)),
allow_player_(cfg_["allow_player"].to_bool(true)),
allow_changes_(cfg_["allow_changes"].to_bool(true)),
enabled_(!parent_->params_.saved_game), changed_(false),
llm_(parent.era_sides_, enabled_ ? &combo_leader_ : NULL, enabled_ ? &combo_gender_ : NULL)
{
@ -133,13 +133,13 @@ connect::side::side(connect& parent, const config& cfg, int index) :
slider_gold_.set_min(20);
slider_gold_.set_max(800);
slider_gold_.set_increment(25);
slider_gold_.set_value(lexical_cast_default<int>(cfg_.get_attribute("gold"), 100));
slider_gold_.set_value(cfg_["gold"].to_int(100));
slider_gold_.set_measurements(80, 16);
slider_income_.set_min(-2);
slider_income_.set_max(18);
slider_income_.set_increment(1);
slider_income_.set_value(lexical_cast_default<int>(cfg_.get_attribute("income"), 0));
slider_income_.set_value(cfg_["income"]);
slider_income_.set_measurements(50, 16);
combo_faction_.enable(enabled_);
@ -154,14 +154,14 @@ connect::side::side(connect& parent, const config& cfg, int index) :
std::vector<std::string>::const_iterator itor =
std::find(parent_->team_names_.begin(), parent_->team_names_.end(),
cfg_.get_attribute("team_name"));
cfg_["team_name"]);
if(itor == parent_->team_names_.end()) {
assert(!parent_->team_names_.empty());
team_ = 0;
} else {
team_ = itor - parent_->team_names_.begin();
}
if(!cfg_.get_attribute("colour").empty()) {
if (cfg_.has_attribute("colour")) {
colour_ = game_config::color_info(cfg_["colour"]).index() - 1;
}
llm_.set_colour(colour_);
@ -189,8 +189,8 @@ connect::side::side(connect& parent, const config& cfg, int index) :
foreach (const config &side_unit, cfg.child_range("unit"))
{
if (utils::string_bool(side_unit["canrecruit"], false)) {
leader_type = side_unit["type"];
gender_ = side_unit["gender"];
leader_type = side_unit["type"].str();
gender_ = side_unit["gender"].str();
break;
}
}
@ -236,8 +236,8 @@ connect::side::side(connect& parent, const config& cfg, int index) :
combo_colour_.enable(!colour_lock_);
// Set the leader and gender
leader_ = cfg_.get_attribute("type");
gender_ = cfg_.get_attribute("gender");
leader_ = cfg_["type"].str();
gender_ = cfg_["gender"].str();
if(!leader_.empty()) {
combo_leader_.enable(false);
combo_gender_.enable(false);
@ -275,11 +275,11 @@ connect::side::side(connect& parent, const config& cfg, int index) :
if(faction_ == 0) {
std::vector<std::string> find;
std::string search_field;
if(!cfg_.get_attribute("faction").empty()) {
if(cfg_.has_attribute("faction")) {
// Choose based on faction
find.push_back(cfg_["faction"]);
search_field = "id";
} else if(utils::string_bool(cfg["faction_from_recruit"]) && !cfg_.get_attribute("recruit").empty()) {
} else if(utils::string_bool(cfg["faction_from_recruit"]) && cfg_.has_attribute("recruit")) {
// Choose based on recruit
find = utils::split(cfg_["recruit"]);
search_field = "recruit";
@ -643,7 +643,7 @@ config connect::side::get_config() const
res["faction_name"] = res["name"];
}
res.append(cfg_);
if (cfg_.get_attribute("side").empty()
if (!cfg_.has_attribute("side")
|| cfg_["side"] != lexical_cast<std::string>(index_ + 1))
{
res["side"] = index_ + 1;
@ -659,7 +659,7 @@ config connect::side::get_config() const
description = N_("(Vacant slot)");
break;
case CNTR_LOCAL:
if(enabled_ && cfg_.get_attribute("save_id").empty()) {
if (enabled_ && !cfg_.has_attribute("save_id")) {
res["save_id"] = preferences::login() + res["side"].str();
}
res["player_id"] = preferences::login() + res["side"].str();
@ -667,7 +667,7 @@ config connect::side::get_config() const
description = N_("Anonymous local player");
break;
case CNTR_COMPUTER:
if(enabled_ && cfg_.get_attribute("save_id").empty()) {
if (enabled_ && !cfg_.has_attribute("save_id")) {
res["save_id"] = "ai" + res["side"].str();
}
{
@ -703,8 +703,8 @@ config connect::side::get_config() const
res["user_description"] = t_string(description, "wesnoth");
} else {
res["player_id"] = player_id_ + res["side"];
if(enabled_ && cfg_.get_attribute("save_id").empty()) {
res["save_id"] = player_id_ + res["side"].str();
if (enabled_ && !cfg_.has_attribute("save_id")) {
res["save_id"] = player_id_ + res["side"];
}
res["user_description"] = player_id_;
@ -834,7 +834,7 @@ void connect::side::import_network_user(const config& data)
if (controller_ == CNTR_RESERVED)
set_ready_for_start(true);
player_id_ = data["name"];
player_id_ = data["name"].str();
controller_ = CNTR_NETWORK;
if(enabled_ && !parent_->era_sides_.empty()) {
@ -884,16 +884,14 @@ void connect::side::resolve_random()
if(!enabled_ || parent_->era_sides_.empty())
return;
if(utils::string_bool(
(*parent_->era_sides_[faction_]).get_attribute("random_faction"),
false))
if ((*parent_->era_sides_[faction_])["random_faction"].to_bool())
{
std::vector<std::string> faction_choices, faction_excepts;
faction_choices = utils::split((*parent_->era_sides_[faction_]).get_attribute("choices"));
faction_choices = utils::split((*parent_->era_sides_[faction_])["choices"]);
if(faction_choices.size() == 1 && faction_choices.front() == "") {
faction_choices.clear();
}
faction_excepts = utils::split((*parent_->era_sides_[faction_]).get_attribute("except"));
faction_excepts = utils::split((*parent_->era_sides_[faction_])["except"]);
if(faction_excepts.size() == 1 && faction_excepts.front() == "") {
faction_excepts.clear();
}
@ -1475,8 +1473,8 @@ void connect::lists_init()
int side_num = 1;
foreach (config &side, sides)
{
config::proxy_string team_name = side["team_name"];
config::proxy_string user_team_name = side["user_team_name"];
config::attribute_value &team_name = side["team_name"];
config::attribute_value &user_team_name = side["user_team_name"];
if(team_name.empty())
team_name = side_num;
@ -1501,7 +1499,7 @@ void connect::lists_init()
foreach (config &side, sides)
{
const std::string side_num = lexical_cast<std::string>(_side_num);
config::proxy_string team_name = side["team_name"];
config::attribute_value &team_name = side["team_name"];
if(team_name.empty())
team_name = side_num;
@ -1593,7 +1591,7 @@ void connect::load_game()
std::string era = params_.mp_era;
if (params_.saved_game) {
if (const config &c = level_.child("snapshot").child("era"))
era = c["id"];
era = c["id"].str();
}
// Initialize the list of sides available for the current era.

View File

@ -289,7 +289,7 @@ mp_game_settings& create::get_parameters()
++era_list.first;
}
parameters_.mp_era = (*era_list.first)["id"];
parameters_.mp_era = (*era_list.first)["id"].str();
// CHECK
parameters_.mp_countdown_init_time = mp_countdown_init_time_val;
parameters_.mp_countdown_turn_bonus = mp_countdown_turn_bonus_val;

View File

@ -574,25 +574,25 @@ void ui::process_network_data(const config& data, const network::connection /*so
} else if (const config &c = data.child("room_join")) {
if (c["player"] == preferences::login()) {
chat_.add_message(time(NULL), "server",
"You have joined the room '" + c["room"] + "'");
"You have joined the room '" + c["room"].str() + "'");
} else {
chat_.add_message(time(NULL), "server",
c["player"] + " has joined the room '" + c["room"] + "'");
c["player"].str() + " has joined the room '" + c["room"].str() + "'");
}
chat_.update_textbox(chat_textbox_);
} else if (const config &c = data.child("room_part")) {
if (c["player"] == preferences::login()) {
chat_.add_message(time(NULL), "server",
"You have left the room '" + c["room"] + "'");
"You have left the room '" + c["room"].str() + "'");
} else {
chat_.add_message(time(NULL), "server",
c["player"] + " has left the room '" + c["room"] + "'");
c["player"].str() + " has left the room '" + c["room"].str() + "'");
}
chat_.update_textbox(chat_textbox_);
} else if (const config &c = data.child("room_query_response")) {
if (const config &ms = c.child("members")) {
std::stringstream ss;
ss << "Room " << c["room"] << " members: ";
ss << "Room " << c["room"].str() << " members: ";
foreach (const config& m, ms.child_range("member")) {
ss << m["name"] << " ";
}
@ -603,7 +603,7 @@ void ui::process_network_data(const config& data, const network::connection /*so
std::stringstream ss;
ss << "Rooms: ";
foreach (const config& r, rs.child_range("room")) {
ss << r["name"] << "(" << r["size"] << ") ";
ss << r["name"].str() << "(" << r["size"].str() << ") ";
}
chat_.add_message(time(NULL), "server", ss.str());
chat_.update_textbox(chat_textbox_);
@ -711,11 +711,11 @@ void ui::gamelist_updated(bool silent)
foreach (const config &user, gamelist_.child_range("user"))
{
user_info u_elem;
u_elem.name = user["name"];
u_elem.name = user["name"].str();
u_elem.state = user["available"] == "no" ? GAME : LOBBY;
u_elem.registered = utils::string_bool(user["registered"]);
u_elem.game_id = user["game_id"];
u_elem.location = user["location"];
u_elem.game_id = user["game_id"].str();
u_elem.location = user["location"].str();
if (u_elem.name == preferences::login()) {
u_elem.relation = ME;
} else if (preferences::is_ignored(u_elem.name)) {

View File

@ -446,7 +446,7 @@ void wait::generate_menu()
foreach (const config &side_unit, sd.child_range("unit"))
{
if (utils::string_bool(side_unit["canrecruit"], false)) {
leader_type = side_unit["type"];
leader_type = side_unit["type"].str();
break;
}
}
@ -468,7 +468,7 @@ void wait::generate_menu()
#else
std::string RCcolor = sd["colour"];
if (RCcolor.empty())
RCcolor = sd["side"];
RCcolor = sd["side"].str();
leader_image = utg.image() + std::string("~RC(") + std::string(utg.flag_rgb() + ">" + RCcolor + ")");
#endif
} else {

View File

@ -86,7 +86,7 @@ play_controller::play_controller(const config& level, game_state& state_of_game,
units_(),
undo_stack_(),
redo_stack_(),
xp_mod_(atoi(level["experience_modifier"].c_str()) > 0 ? atoi(level["experience_modifier"].c_str()) : 100),
xp_mod_(level["experience_modifier"].to_int(100)),
loading_game_(level["playing_team"].empty() == false),
first_human_team_(-1),
player_number_(1),
@ -808,7 +808,7 @@ std::string play_controller::get_unique_saveid(const config& cfg, std::set<std::
std::string save_id = cfg["save_id"];
if(save_id.empty()) {
save_id=cfg["id"];
save_id = cfg["id"].str();
}
if(save_id.empty()) {

View File

@ -118,7 +118,7 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,
bool skip_replay, end_level_data &end_level)
{
const int ticks = SDL_GetTicks();
const int num_turns = atoi((*level)["turns"].c_str());
int num_turns = (*level)["turns"].to_int();
LOG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << "\n";
playsingle_controller playcontroller(*level, state_of_game, ticks, num_turns, game_config, disp.video(), skip_replay);
@ -156,7 +156,7 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
io_type_t& io_type, end_level_data &end_level)
{
const int ticks = SDL_GetTicks();
const int num_turns = atoi((*level)["turns"].c_str());
int num_turns = (*level)["turns"].to_int();
playmp_controller playcontroller(*level, state_of_game, ticks, num_turns,
game_config, disp.video(), skip_replay, io_type == IO_SERVER);
LEVEL_RESULT res = playcontroller.play_scenario(story, log, skip_replay);
@ -311,7 +311,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
}
config::const_child_itors story = scenario->child_range("story");
gamestate.classification().next_scenario = (*scenario)["next_scenario"];
gamestate.classification().next_scenario = (*scenario)["next_scenario"].str();
bool save_game_after_scenario = true;
@ -322,7 +322,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// Preserve old label eg. replay
if (gamestate.classification().label.empty()) {
if (gamestate.classification().abbrev.empty())
gamestate.classification().label = (*scenario)["name"];
gamestate.classification().label = (*scenario)["name"].str();
else {
gamestate.classification().label = std::string(gamestate.classification().abbrev);
gamestate.classification().label.append("-");
@ -578,7 +578,7 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
// Update the label
std::string oldlabel = gamestate.classification().label;
if (gamestate.classification().abbrev.empty())
gamestate.classification().label = (*scenario)["name"];
gamestate.classification().label = (*scenario)["name"].str();
else {
gamestate.classification().label = std::string(gamestate.classification().abbrev);
gamestate.classification().label.append("-");

View File

@ -94,7 +94,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
if (const config &msg = cfg.child("whisper") /*&& is_observer()*/)
{
resources::screen->add_chat_message(time(NULL), "whisper: " + msg["sender"], 0,
resources::screen->add_chat_message(time(NULL), "whisper: " + msg["sender"].str(), 0,
msg["message"], events::chat_handler::MESSAGE_PRIVATE,
preferences::message_bell());
}

View File

@ -146,12 +146,12 @@ unit_race::unit_race() :
unit_race::unit_race(const config& cfg) :
id_(cfg["id"]),
plural_name_(cfg["plural_name"]),
description_(cfg["description"]),
ntraits_(atoi(cfg["num_traits"].c_str())),
chain_size_(atoi(cfg["markov_chain_size"].c_str())),
plural_name_(cfg["plural_name"].t_str()),
description_(cfg["description"].t_str()),
ntraits_(cfg["num_traits"]),
chain_size_(cfg["markov_chain_size"]),
traits_(cfg.child_range("trait")),
global_traits_(!utils::string_bool(cfg["ignore_global_traits"]))
global_traits_(!cfg["ignore_global_traits"].to_bool())
{
if (id_.empty()) {

View File

@ -37,7 +37,7 @@ LEVEL_RESULT play_replay_level(const config& game_config,
{
try{
const int ticks = SDL_GetTicks();
const int num_turns = atoi((*level)["turns"].c_str());
int num_turns = (*level)["turns"].to_int();
DBG_NG << "creating objects... " << (SDL_GetTicks() - ticks) << "\n";
replay_controller replaycontroller(*level, state_of_game, ticks, num_turns, game_config, video);
DBG_NG << "created objects... " << (SDL_GetTicks() - replaycontroller.get_ticks()) << "\n";

View File

@ -892,7 +892,7 @@ void savegame::extract_summary_data_from_save(config& out)
foreach (const config &u, side.child_range("unit"))
{
if (utils::string_bool(u["canrecruit"], false)) {
leader = u["id"];
leader = u["id"].str();
break;
}
}

View File

@ -136,7 +136,7 @@ static void write_compressed_internal(std::ostream &out, config const &cfg, comp
compress_emit_word(out, i.first, schema);
// Output the value, with no compression
compress_output_literal_word(out, i.second.to_serialized());
compress_output_literal_word(out, i.second.t_str().to_serialized());
}
}

View File

@ -89,10 +89,10 @@ void preproc_define::read_argument(const config &cfg)
void preproc_define::read(const config& cfg)
{
value = cfg["value"];
textdomain = cfg["textdomain"];
linenum = lexical_cast<int>(cfg["linenum"]);
location = cfg["location"];
value = cfg["value"].str();
textdomain = cfg["textdomain"].str();
linenum = cfg["linenum"];
location = cfg["location"].str();
foreach (const config &arg, cfg.child_range("argument"))
read_argument(arg);

View File

@ -187,23 +187,23 @@ static lg::log_domain log_server("server");
{
{
// parse ip and mask
ip_text_ = cfg["ip"];
ip_text_ = cfg["ip"].str();
ip_mask pair = parse_ip(ip_text_);
ip_ = pair.first;
mask_ = pair.second;
}
nick_ = cfg["nick"];
nick_ = cfg["nick"].str();
if (cfg.has_attribute("end_time"))
end_time_ = lexical_cast_default<time_t>(cfg["end_time"], 0);
if (cfg.has_attribute("start_time"))
start_time_ = lexical_cast_default<time_t>(cfg["start_time"], 0);
reason_ = cfg["reason"];
reason_ = cfg["reason"].str();
// only overwrite defaults if exists
if (cfg.has_attribute("who_banned"))
who_banned_ = cfg["who_banned"];
who_banned_ = cfg["who_banned"].str();
if (cfg.has_attribute("group"))
group_ = cfg["group"];
group_ = cfg["group"].str();
}
void banned::write(config& cfg) const
@ -708,7 +708,7 @@ static lg::log_domain log_server("server");
if (filename_ != cfg["ban_save_file"])
{
dirty_ = true;
filename_ = cfg["ban_save_file"];
filename_ = cfg["ban_save_file"].str();
}
}

View File

@ -36,11 +36,11 @@ room::room(const std::string& name)
}
room::room(const config& wml)
: name_(wml.get_attribute("name"))
: name_(wml["name"])
, members_()
, persistent_(utils::string_bool(wml.get_attribute("persistent")))
, topic_(wml.get_attribute("topic"))
, logged_(utils::string_bool(wml.get_attribute("logged")))
, persistent_(wml["persistent"].to_bool())
, topic_(wml["topic"])
, logged_(wml["logged"].to_bool())
{
}

View File

@ -89,7 +89,7 @@ const char* room_manager::string_from_pp(room_manager::PRIVILEGE_POLICY pp)
void room_manager::load_config(const config& cfg)
{
filename_ = cfg["room_save_file"];
filename_ = cfg["room_save_file"].str();
compress_stored_rooms_ = utils::string_bool(cfg["compress_stored_rooms"], true);
PRIVILEGE_POLICY pp = pp_from_string(cfg["new_room_policy"]);
if (pp != PP_COUNT) new_room_policy_ = pp;

View File

@ -121,7 +121,7 @@ static stats::str_int_map read_str_int_map(const config& cfg)
{
stats::str_int_map m;
foreach (const config::attribute &i, cfg.attribute_range()) {
m[i.first] = atoi(i.second.c_str());
m[i.first] = i.second;
}
return m;
@ -404,7 +404,7 @@ void stats::read(const config& cfg)
turn_expected_damage_inflicted = lexical_cast<long long>(cfg["turn_expected_damage_inflicted"]);
turn_expected_damage_taken = lexical_cast<long long>(cfg["turn_expected_damage_taken"]);
save_id = cfg["save_id"];
save_id = cfg["save_id"].str();
}
scenario_context::scenario_context(const std::string& name)

View File

@ -57,7 +57,7 @@ team::team_info::team_info(const config& cfg) :
average_price(0),
can_recruit(),
team_name(cfg["team_name"]),
user_team_name(cfg["user_team_name"]),
user_team_name(cfg["user_team_name"].t_str()),
save_id(cfg["save_id"]),
current_player(cfg["current_player"]),
countdown_time(cfg["countdown_time"]),
@ -66,7 +66,7 @@ team::team_info::team_info(const config& cfg) :
flag_icon(cfg["flag_icon"]),
description(cfg["id"]),
scroll_to_leader(utils::string_bool(cfg["scroll_to_leader"],true)),
objectives(cfg["objectives"]),
objectives(cfg["objectives"].t_str()),
objectives_changed(utils::string_bool(cfg["objectives_changed"])),
controller(),
share_maps(false),
@ -76,7 +76,7 @@ team::team_info::team_info(const config& cfg) :
no_leader(utils::string_bool(cfg["no_leader"])),
hidden(utils::string_bool(cfg["hidden"])),
music(cfg["music"]),
colour(cfg["colour"].size() ? cfg["colour"] : cfg["side"]),
colour(cfg.has_attribute("colour") ? cfg["colour"] : cfg["side"]),
side(lexical_cast_default<int>(cfg["side"], 1)),
persistent(false)
{
@ -105,7 +105,7 @@ team::team_info::team_info(const config& cfg) :
start_gold = default_team_gold;
if(team_name.empty()) {
team_name = cfg["side"];
team_name = cfg["side"].str();
}
if(save_id.empty()) {

View File

@ -65,30 +65,30 @@ terrain_type::terrain_type(const config& cfg) :
minimap_image_overlay_("void"),
editor_image_(cfg["editor_image"]),
id_(cfg["id"]),
name_(cfg["name"]),
description_(cfg["description"]),
name_(cfg["name"].t_str()),
description_(cfg["description"].t_str()),
number_(t_translation::read_terrain_code(cfg["string"])),
mvt_type_(),
def_type_(),
union_type_(),
height_adjust_(atoi(cfg["unit_height_adjust"].c_str())),
height_adjust_(cfg["unit_height_adjust"]),
height_adjust_set_(!cfg["unit_height_adjust"].empty()),
submerge_(atof(cfg["submerge"].c_str())),
submerge_(cfg["submerge"].to_double()),
submerge_set_(!cfg["submerge"].empty()),
light_modification_(atoi(cfg["light"].c_str())),
heals_(lexical_cast_default<int>(cfg["heals"], 0)),
light_modification_(cfg["light"]),
heals_(cfg["heals"]),
income_description_(),
income_description_ally_(),
income_description_enemy_(),
income_description_own_(),
editor_group_(cfg["editor_group"]),
village_(utils::string_bool(cfg["gives_income"])),
castle_(utils::string_bool(cfg["recruit_onto"])),
keep_(utils::string_bool(cfg["recruit_from"])),
village_(cfg["gives_income"].to_bool()),
castle_(cfg["recruit_onto"].to_bool()),
keep_(cfg["recruit_from"].to_bool()),
overlay_(number_.base == t_translation::NO_LAYER),
combined_(false),
editor_default_base_(t_translation::read_terrain_code(cfg["default_base"])),
hide_in_editor_(utils::string_bool(cfg["hidden"], false))
hide_in_editor_(cfg["hidden"].to_bool(false))
{
/**
* @todo reenable these validations. The problem is that all MP

View File

@ -56,7 +56,7 @@ static size_t compute(std::string expr, size_t ref1, size_t ref2=0 ) {
// If x2 or y2 are not specified, use x1 and y1 values
static _rect read_rect(const config& cfg) {
_rect rect = { 0, 0, 0, 0 };
const std::vector<std::string> items = utils::split(cfg["rect"].c_str());
std::vector<std::string> items = utils::split(cfg["rect"].str());
if(items.size() >= 1)
rect.x1 = atoi(items[0].c_str());
@ -173,7 +173,7 @@ static void expand_partialresolution(config& dst_cfg, const config& top_cfg)
if (!*parent)
throw config::error("[partialresolution] refers to non-existant [resolution] " + parent_id);
parent_stack.push_back(parent);
parent_id = (*parent)["inherits"];
parent_id = (*parent)["inherits"].str();
}
// Add the parent resolution and apply all the modifications of its children
@ -423,14 +423,15 @@ theme::label::label(const config& cfg) :
object(cfg),
text_(cfg["prefix"].str() + cfg["text"].str() + cfg["postfix"].str()),
icon_(cfg["icon"]),
font_(atoi(cfg["font_size"].c_str())),
font_(cfg["font_size"]),
font_rgb_set_(false),
font_rgb_(DefaultFontRGB)
{
if(font_ == 0)
font_ = DefaultFontSize;
if(cfg["font_rgb"].size()){
if (cfg.has_attribute("font_rgb"))
{
std::vector<std::string> rgb_vec = utils::split(cfg["font_rgb"]);
if(3 <= rgb_vec.size()){
std::vector<std::string>::iterator c=rgb_vec.begin();
@ -459,7 +460,7 @@ theme::status_item::status_item(const config& cfg) :
prefix_(cfg["prefix"].str() + cfg["prefix_literal"].str()),
postfix_(cfg["postfix_literal"].str() + cfg["postfix"].str()),
label_(),
font_(atoi(cfg["font_size"].c_str())),
font_(cfg["font_size"]),
font_rgb_set_(false),
font_rgb_(DefaultFontRGB)
{
@ -470,7 +471,8 @@ theme::status_item::status_item(const config& cfg) :
label_ = label(label_child);
}
if(cfg["font_rgb"].size()){
if (cfg.has_attribute("font_rgb"))
{
std::vector<std::string> rgb_vec = utils::split(cfg["font_rgb"]);
if(3 <= rgb_vec.size()){
std::vector<std::string>::iterator c=rgb_vec.begin();
@ -549,8 +551,8 @@ bool theme::set_resolution(const SDL_Rect& screen)
const config *current = NULL;
foreach (const config &i, cfg_.child_range("resolution"))
{
const int width = atoi(i["width"].c_str());
const int height = atoi(i["height"].c_str());
int width = i["width"];
int height = i["height"];
LOG_DP << "comparing resolution " << screen.w << "," << screen.h << " to " << width << "," << height << "\n";
if(screen.w >= width && screen.h >= height) {
LOG_DP << "loading theme: " << width << "," << height << "\n";
@ -801,7 +803,7 @@ theme::menu* theme::refresh_title2(const std::string& id, const std::string& tit
const config &cfg = find_ref(id, cfg_, false);
if (! cfg[title_tag].empty())
new_title = cfg[title_tag];
new_title = cfg[title_tag].str();
return refresh_title(id, new_title);
}

View File

@ -21,15 +21,12 @@
#include <cstdio>
time_of_day::time_of_day(const config& cfg)
: lawful_bonus(atoi(cfg["lawful_bonus"].c_str())),
bonus_modified(0),
image(cfg["image"]), name(cfg["name"]), id(cfg["id"]),
image_mask(cfg["mask"]),
red(atoi(cfg["red"].c_str())),
green(atoi(cfg["green"].c_str())),
blue(atoi(cfg["blue"].c_str())),
sounds(cfg["sound"])
time_of_day::time_of_day(const config& cfg):
lawful_bonus(cfg["lawful_bonus"]), bonus_modified(0),
image(cfg["image"]), name(cfg["name"].t_str()), id(cfg["id"]),
image_mask(cfg["mask"]),
red(cfg["red"]), green(cfg["green"]), blue(cfg["blue"]),
sounds(cfg["sound"])
{
}

View File

@ -168,9 +168,9 @@ void tod_manager::add_time_area(const config& cfg)
{
areas_.push_back(area_time_of_day());
area_time_of_day &area = areas_.back();
area.id = cfg["id"];
area.xsrc = cfg["x"];
area.ysrc = cfg["y"];
area.id = cfg["id"].str();
area.xsrc = cfg["x"].str();
area.ysrc = cfg["y"].str();
std::vector<map_location> const& locs = parse_location_range(area.xsrc, area.ysrc);
std::copy(locs.begin(), locs.end(), std::inserter(area.hexes, area.hexes.end()));
time_of_day::parse_times(cfg, area.times);

View File

@ -131,7 +131,7 @@ void cutter::add_sub_image(const surface &surf, surface_map &map, const config*
std::vector<std::string> pos = utils::split((*config)["pos"]);
if(pos.size() != 2)
throw exploder_failure("Invalid position " + (*config)["pos"]);
throw exploder_failure("Invalid position " + (*config)["pos"].str());
int x = atoi(pos[0].c_str());
int y = atoi(pos[1].c_str());

View File

@ -212,7 +212,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
type_(cfg["type"]),
race_(NULL),
id_(cfg["id"]),
name_(cfg["name"]),
name_(cfg["name"].t_str()),
underlying_id_(0),
type_name_(),
undead_variation_(),
@ -322,7 +322,7 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
}
level_ = lexical_cast_default<int>(cfg["level"], level_);
if(cfg["undead_variation"] != "") {
undead_variation_ = cfg["undead_variation"];
undead_variation_ = cfg["undead_variation"].str();
}
if(cfg["max_attacks"] != "") {
max_attacks_ = std::max<int>(0,lexical_cast_default<int>(cfg["max_attacks"],1));
@ -364,9 +364,9 @@ unit::unit(const config &cfg, bool use_traits, game_state* state) :
if (const config &ai = cfg.child("ai"))
{
unit_formula_ = ai["formula"];
unit_loop_formula_ = ai["loop_formula"];
unit_priority_formula_ = ai["priority"];
unit_formula_ = ai["formula"].str();
unit_loop_formula_ = ai["loop_formula"].str();
unit_priority_formula_ = ai["priority"].str();
if (const config &ai_vars = ai.child("vars"))
{
@ -914,7 +914,7 @@ const unit_type* unit::type() const
return &i.get_gender_unit_type(gender_).get_variation(variation_);
}
const std::string& unit::profile() const
std::string unit::profile() const
{
if(cfg_["profile"] != "" && cfg_["profile"] != "unit_image") {
return cfg_["profile"];
@ -1075,7 +1075,7 @@ void unit::remove_temporary_modifications()
const config &mod = modifications_.child(mod_name, j);
if (mod["duration"] != "forever" && !mod["duration"].empty()) {
if(mod.has_attribute("prev_type")) {
type_ = mod["prev_type"];
type_ = mod["prev_type"].str();
}
modifications_.remove_child(mod_name, j);
rebuild_from_type = true;
@ -2142,8 +2142,8 @@ std::vector<std::pair<std::string,std::string> > unit::amla_icons() const
foreach (const config &adv, get_modification_advances())
{
icon.first = adv["icon"];
icon.second = adv["description"];
icon.first = adv["icon"].str();
icon.second = adv["description"].str();
for (unsigned j = 0, j_count = modification_count("advance", adv["id"]);
j < j_count; ++j)
@ -2453,7 +2453,7 @@ void unit::add_modification(const std::string& type, const config& mod, bool no_
image_mods_ = mod;
}
LOG_UT << "applying image_mod \n";
mod = effect["add"];
mod = effect["add"].str();
if (!mod.empty()){
image_mods_ += mod;
}

View File

@ -101,11 +101,11 @@ public:
void rename(const std::string& name) {if (!unrenamable_) name_= name;}
/** The unit's profile */
const std::string& profile() const;
std::string profile() const;
/** The unit's transparent profile */
std::string transparent() const;
/** Information about the unit -- a detailed description of it */
const t_string &unit_description() const { return cfg_["description"]; }
t_string unit_description() const { return cfg_["description"]; }
int hitpoints() const { return hit_points_; }
int max_hitpoints() const { return max_hit_points_; }
@ -269,12 +269,12 @@ public:
Uint32 text_color = 0, STATE state = STATE_ANIM);
/** The name of the file to game_display (used in menus). */
const std::string& absolute_image() const { return cfg_["image"]; }
const std::string& image_halo() const { return cfg_["halo"]; }
std::string absolute_image() const { return cfg_["image"]; }
std::string image_halo() const { return cfg_["halo"]; }
const std::string& image_ellipse() const { return cfg_["ellipse"]; }
std::string image_ellipse() const { return cfg_["ellipse"]; }
const std::string& usage() const { return cfg_["usage"]; }
std::string usage() const { return cfg_["usage"]; }
unit_type::ALIGNMENT alignment() const { return alignment_; }
const unit_race* race() const { return race_; }

View File

@ -149,8 +149,8 @@ unit_animation::unit_animation(const config& cfg,const std::string& frame_string
unit_filter_(),
secondary_unit_filter_(),
directions_(),
frequency_(0),
base_score_(atoi(cfg["base_score"].c_str())),
frequency_(cfg["frequency"]),
base_score_(cfg["base_score"]),
event_(),
value_(),
primary_attack_filter_(),
@ -187,7 +187,6 @@ unit_animation::unit_animation(const config& cfg,const std::string& frame_string
foreach (const config &filter, cfg.child_range("filter_second")) {
secondary_unit_filter_.push_back(filter);
}
frequency_ = atoi(cfg["frequency"].c_str());
std::vector<std::string> value_str = utils::split(cfg["value"]);
std::vector<std::string>::iterator value;
@ -746,10 +745,10 @@ unit_animation::particule::particule(
starting_frame_time_=INT_MAX;
if(cfg[frame_string+"start_time"].empty() &&range.first != range.second) {
foreach (const config &frame, range) {
starting_frame_time_ = std::min(starting_frame_time_, atoi(frame["begin"].c_str()));
starting_frame_time_ = std::min(starting_frame_time_, frame["begin"].to_int());
}
} else {
starting_frame_time_ = atoi(cfg[frame_string+"start_time"].c_str());
starting_frame_time_ = cfg[frame_string+"start_time"];
}
foreach (const config &frame, range)

View File

@ -224,9 +224,9 @@ frame_builder::frame_builder(const config& cfg,const std::string& frame_string)
}
if(!cfg[frame_string+"duration"].empty()) {
duration(atoi(cfg[frame_string+"duration"].c_str()));
duration(cfg[frame_string + "duration"]);
} else {
duration(atoi(cfg[frame_string+"end"].c_str()) - atoi(cfg[frame_string+"begin"].c_str()));
duration(cfg[frame_string + "end"].to_int() - cfg[frame_string + "begin"].to_int());
}
halo(cfg[frame_string+"halo"],cfg[frame_string+"halo_x"],cfg[frame_string+"halo_y"],cfg[frame_string+"halo_mod"]);
tmp_string_vect=utils::split(cfg[frame_string+"blend_color"]);

View File

@ -46,17 +46,17 @@ attack_type::attack_type(const config& cfg) :
unitmap_(NULL),
other_attack_(NULL),
cfg_(cfg),
description_(cfg["description"]),
description_(cfg["description"].t_str()),
id_(cfg["name"]),
type_(cfg["type"]),
icon_(cfg["icon"]),
range_(cfg["range"].base_str()),
damage_(atol(cfg["damage"].c_str())),
num_attacks_(atol(cfg["number"].c_str())),
range_(cfg["range"]),
damage_(cfg["damage"]),
num_attacks_(cfg["number"]),
attack_weight_(lexical_cast_default<double>(cfg["attack_weight"],1.0)),
defense_weight_(lexical_cast_default<double>(cfg["defense_weight"],1.0)),
accuracy_(atol(cfg["accuracy"].c_str())),
parry_(atol(cfg["parry"].c_str()))
accuracy_(cfg["accuracy"]),
parry_(cfg["parry"])
{
if (description_.empty())
@ -311,13 +311,12 @@ unit_movement_type::unit_movement_type(const config& cfg, const unit_movement_ty
unit_movement_type::unit_movement_type(): moveCosts_(), defenseMods_(), parent_(NULL), cfg_()
{}
const t_string& unit_movement_type::name() const
std::string unit_movement_type::name() const
{
const t_string& res = cfg_.get_attribute("name");
if(res == "" && parent_ != NULL)
if (!cfg_.has_attribute("name") && parent_)
return parent_->name();
else
return res;
return cfg_["name"];
}
int unit_movement_type::movement_cost(const gamemap& map,
@ -702,7 +701,7 @@ unit_type::~unit_type()
void unit_type::set_config(const config& cfg)
{
cfg_ = cfg;
id_ = cfg["id"];
id_ = cfg["id"].str();
}
void unit_type::build_full(const config& cfg, const movement_type_map& mv_types,
@ -786,7 +785,7 @@ void unit_type::build_full(const config& cfg, const movement_type_map& mv_types,
DBG_UT << "no parent found for movement_type " << move_type << "\n";
}
flag_rgb_ = cfg["flag_rgb"];
flag_rgb_ = cfg["flag_rgb"].str();
game_config::add_color_info(cfg);

View File

@ -115,7 +115,7 @@ public:
unit_movement_type(const config& cfg, const unit_movement_type* parent=NULL);
unit_movement_type();
const t_string& name() const;
std::string name() const;
int movement_cost(const gamemap& map, t_translation::t_terrain terrain) const;
int defense_modifier(const gamemap& map, t_translation::t_terrain terrain) const;
int damage_against(const attack_type& attack) const { return resistance_against(attack); }

View File

@ -356,7 +356,7 @@ void upload_log::quit(int turn)
std::string turnstr = lexical_cast<std::string>(turn);
// We only record the quit if they've actually played a turn.
if (!game_ || game_->get_attribute("start_turn") == turnstr || turn == 1)
if (!game_ || (*game_)["start_turn"] == turnstr || turn == 1)
return;
add_game_result("quit", turn);

View File

@ -712,7 +712,8 @@ variable_info::variable_info(const std::string& varname,
}
}
config::proxy_string variable_info::as_scalar() {
config::attribute_value &variable_info::as_scalar()
{
assert(is_valid);
return (*vars)[key];
}

View File

@ -210,7 +210,7 @@ struct variable_info
* Results: after deciding the desired type, these methods can retrieve the result
* Note: first you should force_valid or check is_valid, otherwise these may fail
*/
config::proxy_string as_scalar();
config::attribute_value &as_scalar();
config& as_container();
array_range as_array(); //range may be empty
};