34 #define LOG_NG LOG_STREAM(info, log_engine) 35 #define WRN_NG LOG_STREAM(warn, log_engine) 36 #define ERR_NG LOG_STREAM(err, log_engine) 39 const config as_nonempty_range_default(
"_");
70 ERR_NG <<
"invalid variablename " <<
id;
86 return &null_variable_set;
143 static const config empty_config;
144 return vconfig(empty_config,
false);
179 static std::set<std::string> vconfig_recursion;
189 if (
child.key ==
"insert_tag") {
191 std::string name = insert_cfg[
"name"];
192 std::string vname = insert_cfg[
"variable"];
193 if(!vconfig_recursion.insert(vname).second) {
194 throw recursion_error(
"vconfig::get_parsed_config() infinite recursion detected, aborting");
199 for (
const config& ch : range)
209 vconfig_recursion.erase(vname);
211 if(vconfig_recursion.empty()) {
218 vconfig_recursion.erase(vname);
232 if (
child.key == key) {
234 }
else if (
child.key ==
"insert_tag") {
236 if(insert_cfg[
"name"] == key)
241 for (
const config& ch : range)
262 if (
child.key == key) {
264 }
else if (
child.key ==
"insert_tag") {
266 if(insert_cfg[
"name"] == key)
296 if(insert_cfg[
"name"] == key)
323 if(insert_cfg[
"name"] == key) {
331 struct vconfig_expand_visitor
332 #ifdef USING_BOOST_VARIANT
333 : boost::static_visitor<void>
340 template<
typename T>
void operator()(
const T&)
const {}
341 void operator()(
const std::string &
s)
const 345 void operator()(
const t_string &s)
const 362 val.second.apply_visitor(vconfig_expand_visitor(val.second, *
variables_));
369 val.second.apply_visitor(vconfig_expand_visitor(val.second, *
variables_));
449 const std::string &key =
i_->key;
508 LOG_NG <<
"scoped_wml_variable: var_name \"" <<
var_name_ <<
"\" has been auto-stored.";
514 assert(
false &&
"invalid variable name of autostored variable");
515 throw "assertion ignored";
538 LOG_NG <<
"scoped_wml_variable: var_name \"" <<
var_name_ <<
"\" has been reverted.";
548 if(itor != umap_.end()) {
550 itor->write(tmp_cfg);
555 ERR_NG <<
"failed to auto-store $" <<
name() <<
" at (" <<
loc_ <<
")";
572 std::vector<team>::const_iterator team_it = std::find_if(teams.begin(), teams.end(), [&](
const team&
t) {
return t.save_id_or_number() == player_; });
574 if(team_it != teams.end()) {
575 if(team_it->recall_list().size() > recall_index_) {
577 team_it->recall_list()[recall_index_]->write(tmp_cfg);
578 tmp_cfg[
"x"] =
"recall";
579 tmp_cfg[
"y"] =
"recall";
580 LOG_NG <<
"auto-storing $" <<
name() <<
" for player: " << player_
581 <<
" at recall index: " << recall_index_;
583 ERR_NG <<
"failed to auto-store $" <<
name() <<
" for player: " << player_
584 <<
" at recall index: " << recall_index_;
587 ERR_NG <<
"failed to auto-store $" <<
name() <<
" for player: " << player_;
virtual variable_access_const get_variable_access_read(const std::string &varname) const =0
virtual config::attribute_value get_variable_const(const std::string &id) const
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
const_all_children_itors all_children_range() const
In-order iteration over all children.
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
virtual const std::vector< team > & teams() const override
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
std::shared_ptr< const config > cache_
reference operator*() const
all_children_iterator ordered_begin() const
In-order iteration over all children.
Variant for storing WML attributes.
const variable_set * variables_
all_children_iterator & operator--()
virtual variable_access_const get_variable_access_read(const std::string &varname) const
maybe_const_t< config::attribute_value, V > & as_scalar() const
If instantiated with vi_policy_const, the lifetime of the returned const attribute_value reference mi...
child_itors child_range(config_key_type key)
attribute_map::value_type attribute
~vconfig()
Default destructor, but defined here for possibly faster compiles (templates sometimes can be rough o...
const config::attribute reference
std::string get_key() const
static lg::log_domain log_engine("engine")
scoped_wml_variable(const std::string &var_name)
const_attr_itors attribute_range() const
const config * cfg_
Used to access our config (original or copy, as appropriate).
variable_info< const variable_info_implementation::vi_policy_const > variable_access_const
Read-only access.
const_all_children_iterator ordered_end() const
child_list get_children(const std::string &key) const
This class stores all the data for a single 'side' (in game nomenclature).
const vconfig & make_safe() const
instruct the vconfig to make a private copy of its underlying data.
const std::string & name() const
all_children_iterator ordered_end() const
bool memory_managed() const
Returns true if *this has made a copy of its config.
bool operator==(const all_children_iterator &i) const
config get_parsed_config() const
std::shared_ptr< const config > cache_
Keeps a copy of our config alive when we manage our own memory.
std::size_t count_children(const std::string &key) const
boost::iterator_range< const_child_iterator > const_child_itors
config & store(const config &var_value=config())
std::string id
Text to match against addon_info.tags()
std::vector< scoped_wml_variable * > scoped_variables
config::attribute_value expand(const std::string &) const
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
static const variable_set * try_get_gamedata()
static map_location::DIRECTION s
void clear_variable_cfg(const std::string &varname)
Clears only the config children does nothing if varname is no valid variable name.
static vconfig unconstructed_vconfig()
This is just a wrapper for the default constructor; it exists for historical reasons and to make it c...
config & add_child(config_key_type key)
pointer operator->() const
const_all_children_iterator ordered_begin() const
virtual config::attribute_value get_variable_const(const std::string &id) const =0
Information on a WML variable.
const std::pair< std::string, vconfig > value_type
vconfig get_child() const
A variable-expanding proxy for the config class.
const config & get_config() const
Standard logging facilities (interface).
auto apply_visitor(const V &visitor) const
Visitor support: Applies a visitor to the underlying variant.
static vconfig empty_vconfig()
const variable_set * variables_
config & add_variable_cfg(const std::string &varname, const config &value=config())
throws invalid_variablename_exception if varname is no valid variable name.
maybe_const_t< config::child_itors, V > as_array() const
If instantiated with vi_policy_const, the lifetime of the returned const attribute_value reference mi...
static const config default_empty_config
std::vector< vconfig > child_list
pointer operator->() const
config_attribute_value attribute_value
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
t_string interpolate_variables_into_tstring(const t_string &tstr, const variable_set &variables)
Function that does the same as the above, for t_stringS.
const std::string var_name_
static map_location::DIRECTION n
virtual ~scoped_wml_variable()
reference operator*() const
const value_type reference
all_children_iterator(const Itor &i, const variable_set &vars)
all_children_iterator & operator++()