30 #define DBG_PERSIST LOG_STREAM(debug, log_persist) 31 #define ERR_PERSIST LOG_STREAM(err, log_persist) 59 return _(
"waiting for^a global variable");
66 std::string global = pcfg[
"from_global"];
67 std::string local = pcfg[
"to_local"];
80 for (std::size_t
i = 0;
i < arrsize;
i++)
89 ERR_PERSIST <<
"cannot store global variable into invalid variablename " << local;
95 std::string global = pcfg[
"global"];
96 ctx.
clear_var(global, pcfg[
"immediate"].to_bool());
101 if (pcfg[
"from_local"].empty()) {
104 std::string global = pcfg[
"to_global"];
105 std::string local = pcfg[
"from_local"];
119 for (std::size_t
i = 0;
i < arraylen;
i++)
122 ctx.
set_var(global, val, pcfg[
"immediate"].to_bool());
129 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"from_global\"";
133 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"to_local\"";
138 ERR_PERSIST <<
"[get_global_variable] missing attribute \"namespace\"";
142 DBG_PERSIST <<
"verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"];
146 ERR_PERSIST <<
"[get_global_variable] attribute \"side\" specifies invalid side number.";
149 DBG_PERSIST <<
"end verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"];
157 LOG_PERSIST <<
"Error: [get_global_variable] attribute \"namespace\" is not valid.";
165 ERR_PERSIST <<
"[set_global_variable] missing required attribute \"to_global\"";
169 LOG_PERSIST <<
"Warning: [set_global_variable] missing attribute \"from_local\", global variable will be cleared";
173 ERR_PERSIST <<
"[set_global_variable] missing attribute \"namespace\" and no global namespace provided.";
178 int side = pcfg_side;
180 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
183 ERR_PERSIST <<
"[set_global_variable] attribute \"side\" specifies invalid side number.";
186 LOG_PERSIST <<
"[set_global_variable] attribute \"side\" specifies a null-controlled side number.";
200 LOG_PERSIST <<
"Error: [set_global_variable] attribute \"namespace\" is not valid.";
208 ERR_PERSIST <<
"[clear_global_variable] missing required attribute \"global\"";
212 ERR_PERSIST <<
"[clear_global_variable] missing attribute \"namespace\" and no global namespace provided.";
219 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
222 ERR_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies invalid side number.";
225 LOG_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies a null-controlled side number.";
239 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