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"];
79 for (std::size_t
i = 0;
i < arrsize;
i++)
85 ERR_PERSIST <<
"cannot store global variable into invalid variablename " << local;
91 std::string global = pcfg[
"global"];
92 ctx.
clear_var(global, pcfg[
"immediate"].to_bool());
97 if (pcfg[
"from_local"].empty()) {
100 std::string global = pcfg[
"to_global"];
101 std::string local = pcfg[
"from_local"];
115 for (std::size_t
i = 0;
i < arraylen;
i++)
118 ctx.
set_var(global, val, pcfg[
"immediate"].to_bool());
125 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"from_global\"";
129 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"to_local\"";
134 ERR_PERSIST <<
"[get_global_variable] missing attribute \"namespace\"";
138 DBG_PERSIST <<
"verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"];
142 ERR_PERSIST <<
"[get_global_variable] attribute \"side\" specifies invalid side number.";
145 DBG_PERSIST <<
"end verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"];
153 LOG_PERSIST <<
"Error: [get_global_variable] attribute \"namespace\" is not valid.";
161 ERR_PERSIST <<
"[set_global_variable] missing required attribute \"to_global\"";
165 LOG_PERSIST <<
"Warning: [set_global_variable] missing attribute \"from_local\", global variable will be cleared";
169 ERR_PERSIST <<
"[set_global_variable] missing attribute \"namespace\" and no global namespace provided.";
174 int side = pcfg_side;
176 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
179 ERR_PERSIST <<
"[set_global_variable] attribute \"side\" specifies invalid side number.";
182 LOG_PERSIST <<
"[set_global_variable] attribute \"side\" specifies a null-controlled side number.";
196 LOG_PERSIST <<
"Error: [set_global_variable] attribute \"namespace\" is not valid.";
204 ERR_PERSIST <<
"[clear_global_variable] missing required attribute \"global\"";
208 ERR_PERSIST <<
"[clear_global_variable] missing attribute \"namespace\" and no global namespace provided.";
213 const int side = pcfg_side.
to_int();
215 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
218 ERR_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies invalid side number.";
221 LOG_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies a null-controlled side number.";
235 LOG_PERSIST <<
"Error: [clear_global_variable] attribute \"namespace\" is not valid.";
Variant for storing WML attributes.
std::string str(const std::string &fallback="") const
int to_int(int def=0) const
bool empty() const
Tests for an attribute that either was never set or was set to "".
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
std::size_t child_count(config_key_type key) const
config & add_child(config_key_type key)
void clear_variable(const std::string &varname)
Clears attributes config children does nothing if varname is no valid variable name.
const config & get_variables() const
void set_variable(const std::string &varname, const t_string &value)
does nothing if varname is no valid variable name.
virtual config get_var(const std::string &) const =0
virtual bool set_var(const std::string &, const config &, bool immediate=false)=0
virtual bool clear_var(const std::string &, bool immediate=false)=0
persist_context & get_context(const std::string &ns)
A variable-expanding proxy for the config class.
bool has_attribute(const std::string &key) const
< Synonym for operator[]
static std::string _(const char *str)
Standard logging facilities (interface).
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
persist_manager * persist
play_controller * controller
config pack_scalar(const std::string &name, const t_string &val)
static void clear_global_variable(persist_context &ctx, const vconfig &pcfg)
static void set_global_variable(persist_context &ctx, const vconfig &pcfg)
void verify_and_set_global_variable(const vconfig &pcfg)
void verify_and_clear_global_variable(const vconfig &pcfg)
static void get_global_variable(persist_context &ctx, const vconfig &pcfg)
void verify_and_get_global_variable(const vconfig &pcfg)
Interface for querying local choices.
virtual config random_choice(int) const
const persist_context & ctx
persist_choice(const persist_context &context, const std::string &name, int side_num)
virtual std::string description() const
virtual bool is_visible() const
whether the choice is visible for the user like an advancement choice a non-visible choice is for exa...
virtual config query_user(int) const