35 #include <boost/variant/static_visitor.hpp>
38 #define LOG_NG LOG_STREAM(info, log_engine)
39 #define WRN_NG LOG_STREAM(warn, log_engine)
40 #define ERR_NG LOG_STREAM(err, log_engine)
49 if(range.first == range.second)
64 cache_(), cfg_(&default_empty_config)
99 static const config empty_config;
100 return vconfig(empty_config,
false);
134 static std::set<std::string> vconfig_recursion;
144 if (
child.key ==
"insert_tag") {
147 const t_string& vname = insert_cfg[
"variable"];
148 if(!vconfig_recursion.insert(vname).second) {
149 throw recursion_error(
"vconfig::get_parsed_config() infinite recursion detected, aborting");
164 vconfig_recursion.erase(vname);
166 if(vconfig_recursion.empty()) {
173 vconfig_recursion.erase(vname);
187 if (
child.key == key) {
189 }
else if (
child.key ==
"insert_tag") {
191 if(insert_cfg[
"name"] == key)
217 if (
child.key == key) {
219 }
else if (
child.key ==
"insert_tag") {
221 if(insert_cfg[
"name"] == key)
226 n += range.second - range.first;
251 if(insert_cfg[
"name"] == key)
256 return vconfig(*range.first,
true);
278 if(insert_cfg[
"name"] == key) {
286 struct vconfig_expand_visitor : boost::static_visitor<void>
291 template<
typename T>
void operator()(T
const &)
const {}
296 void operator()(
const t_string &s)
const
317 i_(i), inner_index_(0),
cache_(cache)
323 if (inner_index_ >= 0 &&
i_->key ==
"insert_tag")
331 if (++inner_index_ < std::distance(range.first, range.second))
368 if (inner_index_ >= 0 && key ==
"insert_tag") {
376 if (inner_index_ >= 0 &&
i_->key ==
"insert_tag")
382 std::advance(range.first, inner_index_);
383 return vconfig(*range.first,
true);
426 LOG_NG <<
"scoped_wml_variable: var_name \"" <<
var_name_ <<
"\" has been auto-stored.\n";
432 assert(
false &&
"invalid variable name of autostored varaible");
433 throw "assertion ignored";
454 LOG_NG <<
"scoped_wml_variable: var_name \"" <<
var_name_ <<
"\" has been reverted.\n";
467 itor->write(tmp_cfg);
468 tmp_cfg[
"x"] =
x_ + 1;
469 tmp_cfg[
"y"] =
y_ + 1;
470 LOG_NG <<
"auto-storing $" <<
name() <<
" at (" << loc <<
")\n";
472 ERR_NG <<
"failed to auto-store $" <<
name() <<
" at (" << loc <<
")" << std::endl;
489 std::vector<team>::const_iterator team_it;
490 for (team_it = teams.begin(); team_it != teams.end(); ++team_it) {
491 if (team_it->save_id() ==
player_ )
495 if(team_it != teams.end()) {
499 tmp_cfg[
"x"] =
"recall";
500 tmp_cfg[
"y"] =
"recall";
508 ERR_NG <<
"failed to auto-store $" <<
name() <<
" for player: " <<
player_ <<
'\n';
child_itors child_range(const std::string &key)
size_t count_children(const std::string &key) const
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 ...
all_children_iterator ordered_end() const
variable_info_detail::maybe_const< vit, config::child_itors >::type as_array() const
might throw invalid_variablename_exception
vconfig get_child() const
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
config get_parsed_config() const
const std::string & name() const
all_children_iterator ordered_end() const
attribute_map::value_type attribute
GLuint const GLfloat * val
~vconfig()
Default destructor, but defined here for possibly faster compiles (templates sometimes can be rough o...
all_children_iterator(const Itor &i)
V::result_type apply_visitor(const V &visitor) const
Applies a visitor to the underlying variant.
std::pair< std::string, vconfig > value_type
static lg::log_domain log_engine("engine")
std::pair< const_child_iterator, const_child_iterator > const_child_itors
scoped_wml_variable(const std::string &var_name)
Variant for storing WML attributes.
bool memory_managed() const
Returns true if *this has made a copy of its config.
unsigned int recall_index_
const config * cfg_
Used to access our config (original or copy, as appropriate).
static std::vector< team > *& teams
std::vector< team > * teams
child_list get_children(const std::string &key) const
all_children_itors all_children_range() const
In-order iteration over all children.
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
config & add_child(const std::string &key)
Encapsulates the map of the game.
config & store(const config &var_value=config())
std::vector< scoped_wml_variable * > scoped_variables
std::map< std::string, tfilter >::iterator itor
config::attribute_value expand(const std::string &) const
boost::shared_ptr< const config > cache_
Keeps a copy of our config alive when we manage our own memory.
const config & get_config() const
const_attr_itors attribute_range() const
Information on a WML variable.
void clear_variable_cfg(const std::string &varname)
Clears only the config children does nothing if varname is no valid variable name.
variable_access_const get_variable_access_read(const std::string &varname) const
returns a variable_access that cannot be used to change the game variables
GLdouble GLdouble GLdouble r
static vconfig unconstructed_vconfig()
This is just a wrapper for the default constructor; it exists for historical reasons and to make it c...
const config & get_child(const std::string &key)
GLuint const GLchar * name
reference operator*() const
const std::string player_
bool operator==(const all_children_iterator &i) const
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
pointer operator->() const
static vconfig empty_vconfig()
config & add_variable_cfg(const std::string &varname, const config &value=config())
throws invalid_variablename_exception if varname is no valid variable name.
static const config default_empty_config
unit_iterator find(size_t id)
std::vector< vconfig > child_list
A config object defines a single node in a WML file, with access to child nodes.
void make_safe() const
instruct the vconfig to make a private copy of its underlying data.
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_
GLsizei const GLcharARB ** string
virtual ~scoped_wml_variable()
std::string get_key() const
all_children_iterator ordered_begin() const
In-order iteration over all children.
const value_type reference
all_children_iterator ordered_begin() const
all_children_iterator & operator++()