35 #define LOG_NG LOG_STREAM(info, log_engine)
36 #define WRN_NG LOG_STREAM(warn, log_engine)
37 #define ERR_NG LOG_STREAM(err, log_engine)
40 const config as_nonempty_range_default(
"_");
71 ERR_NG <<
"invalid variablename " <<
id;
87 return &null_variable_set;
112 : cache_(manage_memory ? new
config(
cfg) : nullptr)
113 , cfg_(manage_memory ? cache_.
get() : &
cfg)
127 : cache_(cache), cfg_(&
cfg), variables_(&variables)
131 : cache_(), cfg_(&
cfg), variables_(&variables)
144 static const config empty_config;
145 return vconfig(empty_config,
false);
180 static std::set<std::string> vconfig_recursion;
190 if (key ==
"insert_tag") {
192 std::string name = insert_cfg[
"name"];
193 std::string vname = insert_cfg[
"variable"];
194 if(!vconfig_recursion.insert(vname).second) {
195 throw recursion_error(
"vconfig::get_parsed_config() infinite recursion detected, aborting");
200 for (
const config& ch : range)
210 vconfig_recursion.
erase(vname);
212 if(vconfig_recursion.empty()) {
219 vconfig_recursion.
erase(vname);
233 if (key == key_to_get) {
235 }
else if (key ==
"insert_tag") {
237 if(insert_cfg[
"name"] == key_to_get)
242 for (
const config& ch : range)
263 if (key == key_to_count) {
265 }
else if (key ==
"insert_tag") {
267 if(insert_cfg[
"name"] == key_to_count)
297 if(insert_cfg[
"name"] == key)
324 if(insert_cfg[
"name"] == key) {
332 struct vconfig_expand_visitor
333 #ifdef USING_BOOST_VARIANT
334 : boost::static_visitor<void>
341 template<
typename T>
void operator()(
const T&)
const {}
342 void operator()(
const std::string &
s)
const
363 val.second.apply_visitor(vconfig_expand_visitor(val.second, *
variables_));
370 val.second.apply_visitor(vconfig_expand_visitor(val.second, *
variables_));
387 if (inner_index_ >= 0 && i_->key ==
"insert_tag")
395 if (++inner_index_ <
static_cast<int>(range.size()))
419 if(inner_index_ >= 0 && i_->key ==
"insert_tag") {
420 if(--inner_index_ >= 0) {
450 const std::string &key = i_->key;
451 if (inner_index_ >= 0 && key ==
"insert_tag") {
459 if (inner_index_ >= 0 && i_->key ==
"insert_tag")
465 range.advance_begin(inner_index_);
478 return i_ ==
i.i_ && inner_index_ ==
i.inner_index_;
509 LOG_NG <<
"scoped_wml_variable: var_name \"" <<
var_name_ <<
"\" has been auto-stored.";
515 assert(
false &&
"invalid variable name of autostored variable");
516 throw "assertion ignored";
539 LOG_NG <<
"scoped_wml_variable: var_name \"" <<
var_name_ <<
"\" has been reverted.";
551 itor->write(tmp_cfg);
556 ERR_NG <<
"failed to auto-store $" <<
name() <<
" at (" <<
loc_ <<
")";
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
std::string save_id_or_number() const
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).
auto find(Container &container, const Value &value, const Projection &projection={})
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.