29 #define DBG_PERSIST LOG_STREAM(debug, log_persist) 30 #define ERR_PERSIST LOG_STREAM(err, log_persist) 58 return _(
"waiting for^a global variable");
65 std::string global = pcfg[
"from_global"];
66 std::string local = pcfg[
"to_local"];
79 for (std::size_t
i = 0;
i < arrsize;
i++)
88 ERR_PERSIST <<
"cannot store global variable into invalid variablename " << local << std::endl;
94 std::string global = pcfg[
"global"];
95 ctx.
clear_var(global, pcfg[
"immediate"].to_bool());
100 if (pcfg[
"from_local"].empty()) {
103 std::string global = pcfg[
"to_global"];
104 std::string local = pcfg[
"from_local"];
118 for (std::size_t
i = 0;
i < arraylen;
i++)
121 ctx.
set_var(global, val, pcfg[
"immediate"].to_bool());
128 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"from_global\"";
132 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"to_local\"";
137 ERR_PERSIST <<
"[get_global_variable] missing attribute \"namespace\"";
141 DBG_PERSIST <<
"verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"] <<
"\n";
145 ERR_PERSIST <<
"[get_global_variable] attribute \"side\" specifies invalid side number." <<
"\n";
148 DBG_PERSIST <<
"end verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"] <<
"\n";
156 LOG_PERSIST <<
"Error: [get_global_variable] attribute \"namespace\" is not valid.";
164 ERR_PERSIST <<
"[set_global_variable] missing required attribute \"to_global\"";
168 LOG_PERSIST <<
"Warning: [set_global_variable] missing attribute \"from_local\", global variable will be cleared";
172 ERR_PERSIST <<
"[set_global_variable] missing attribute \"namespace\" and no global namespace provided.";
177 int side = pcfg_side;
179 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
182 ERR_PERSIST <<
"[set_global_variable] attribute \"side\" specifies invalid side number.";
185 LOG_PERSIST <<
"[set_global_variable] attribute \"side\" specifies a null-controlled side number.";
199 LOG_PERSIST <<
"Error: [set_global_variable] attribute \"namespace\" is not valid.";
207 ERR_PERSIST <<
"[clear_global_variable] missing required attribute \"global\"";
211 ERR_PERSIST <<
"[clear_global_variable] missing attribute \"namespace\" and no global namespace provided.";
218 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
221 ERR_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies invalid side number.";
224 LOG_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies a null-controlled side number.";
238 LOG_PERSIST <<
"Error: [clear_global_variable] attribute \"namespace\" is not valid.";
void verify_and_get_global_variable(const vconfig &pcfg)
play_controller * controller
bool empty() const
Tests for an attribute that either was never set or was set to "".
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
static void get_global_variable(persist_context &ctx, const vconfig &pcfg)
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...
static void set_global_variable(persist_context &ctx, const vconfig &pcfg)
Variant for storing WML attributes.
unsigned child_count(config_key_type key) const
bool has_attribute(const std::string &key) const
< Synonym for operator[]
virtual config query_user(int) const
persist_manager * persist
void verify_and_set_global_variable(const vconfig &pcfg)
int to_int(int def=0) const
config pack_scalar(const std::string &name, const t_string &val)
const config & get_variables() const
virtual bool set_var(const std::string &, const config &, bool immediate=false)=0
static std::string _(const char *str)
virtual std::string description() const
virtual config get_var(const std::string &) const =0
persist_choice(const persist_context &context, const std::string &name, int side_num)
Interface for querying local choices.
virtual config random_choice(int) const
void set_variable(const std::string &varname, const t_string &value)
does nothing if varname is no valid variable name.
virtual bool clear_var(const std::string &, bool immediate=false)=0
const persist_context & ctx
persist_context & get_context(const std::string &ns)
config & add_child(config_key_type key)
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
static void clear_global_variable(persist_context &ctx, const vconfig &pcfg)
void clear_variable(const std::string &varname)
Clears attributes config children does nothing if varname is no valid variable name.
A config object defines a single node in a WML file, with access to child nodes.
virtual bool is_visible() const
whether the choice is visible for the user like an advancement choice a non-visible choice is for exa...
void verify_and_clear_global_variable(const vconfig &pcfg)
std::string str(const std::string &fallback="") const