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;
111 : cache_(manage_memory ? new
config(cfg) : nullptr)
112 , cfg_(manage_memory ? cache_.
get() : &cfg)
126 : cache_(cache), cfg_(&cfg), variables_(&variables)
130 : cache_(), cfg_(&cfg), variables_(&variables)
143 static const config empty_config;
144 return vconfig(empty_config,
false);
179 static std::set<std::string> vconfig_recursion;
189 if (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 (key == key_to_get) {
234 }
else if (key ==
"insert_tag") {
236 if(insert_cfg[
"name"] == key_to_get)
241 for (
const config& ch : range)
262 if (key == key_to_count) {
264 }
else if (key ==
"insert_tag") {
266 if(insert_cfg[
"name"] == key_to_count)
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
362 val.second.apply_visitor(vconfig_expand_visitor(val.second, *
variables_));
369 val.second.apply_visitor(vconfig_expand_visitor(val.second, *
variables_));
386 if (inner_index_ >= 0 && i_->key ==
"insert_tag")
394 if (++inner_index_ <
static_cast<int>(range.size()))
418 if(inner_index_ >= 0 && i_->key ==
"insert_tag") {
419 if(--inner_index_ >= 0) {
449 const std::string &key = i_->key;
450 if (inner_index_ >= 0 && key ==
"insert_tag") {
458 if (inner_index_ >= 0 && i_->key ==
"insert_tag")
464 range.advance_begin(inner_index_);
477 return i_ ==
i.i_ && inner_index_ ==
i.inner_index_;
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.";
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()) {
578 tmp_cfg[
"x"] =
"recall";
579 tmp_cfg[
"y"] =
"recall";
Variant for storing WML attributes.
auto apply_visitor(const V &visitor) const
Visitor support: Applies a visitor to the underlying variant.
virtual config::attribute_value get_variable_const(const std::string &id) const
virtual variable_access_const get_variable_access_read(const std::string &varname) const
A config object defines a single node in a WML file, with access to child nodes.
all_children_iterator erase(const all_children_iterator &i)
const_all_children_iterator ordered_begin() const
const_attr_itors attribute_range() const
config_attribute_value attribute_value
Variant for storing WML attributes.
auto all_children_view() const
In-order iteration over all children.
const_all_children_iterator ordered_end() const
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
child_itors child_range(config_key_type key)
attribute_map::value_type attribute
boost::iterator_range< const_child_iterator > const_child_itors
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
virtual const std::vector< team > & teams() const override
std::vector< scoped_wml_variable * > scoped_variables
void clear_variable_cfg(const std::string &varname)
Clears only the config children does nothing if varname is no valid variable name.
config & add_variable_cfg(const std::string &varname, const config &value=config())
throws invalid_variablename_exception if varname is no valid variable name.
unsigned int recall_index_
const std::string player_
optional_const_config data_
scoped_wml_variable(const std::string &var_name)
config & store(const config &var_value=config())
virtual ~scoped_wml_variable()
const std::string var_name_
const std::string & name() const
This class stores all the data for a single 'side' (in game nomenclature).
unit_iterator find(std::size_t id)
Information on a WML variable.
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...
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...
virtual config::attribute_value get_variable_const(const std::string &id) const =0
virtual variable_access_const get_variable_access_read(const std::string &varname) const =0
A variable-expanding proxy for the config class.
~vconfig()
Default destructor, but defined here for possibly faster compiles (templates sometimes can be rough o...
bool memory_managed() const
Returns true if *this has made a copy of its config.
all_children_iterator ordered_begin() const
In-order iteration over all children.
std::vector< vconfig > child_list
static vconfig unconstructed_vconfig()
This is just a wrapper for the default constructor; it exists for historical reasons and to make it c...
static vconfig empty_vconfig()
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
config::attribute_value expand(const std::string &) const
const config & get_config() const
config get_parsed_config() const
all_children_iterator ordered_end() const
const vconfig & make_safe() const
instruct the vconfig to make a private copy of its underlying data.
std::shared_ptr< const config > cache_
Keeps a copy of our config alive when we manage our own memory.
static const config default_empty_config
const config * cfg_
Used to access our config (original or copy, as appropriate).
std::size_t count_children(const std::string &key) const
child_list get_children(const std::string &key) const
const variable_set * variables_
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
Standard logging facilities (interface).
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
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.
all_children_iterator(const Itor &i, const variable_set &vars)
const value_type reference
all_children_iterator & operator++()
const std::pair< std::string, vconfig > value_type
reference operator*() const
vconfig get_child() const
bool operator==(const all_children_iterator &i) const
pointer operator->() const
std::string get_key() const
all_children_iterator & operator--()
pointer operator->() const
reference operator*() const
const config::attribute reference
const variable_set * variables_
static map_location::direction n
static map_location::direction s
static lg::log_domain log_engine("engine")
static const variable_set * try_get_gamedata()
variable_info< const variable_info_implementation::vi_policy_const > variable_access_const
Read-only access.