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"];
78 for (std::size_t
i = 0;
i < arrsize;
i++)
84 ERR_PERSIST <<
"cannot store global variable into invalid variablename " << local;
90 std::string global = pcfg[
"global"];
91 ctx.
clear_var(global, pcfg[
"immediate"].to_bool());
96 if (pcfg[
"from_local"].empty()) {
99 std::string global = pcfg[
"to_global"];
100 std::string local = pcfg[
"from_local"];
114 for (std::size_t
i = 0;
i < arraylen;
i++)
117 ctx.
set_var(global, val, pcfg[
"immediate"].to_bool());
124 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"from_global\"";
128 ERR_PERSIST <<
"[get_global_variable] missing required attribute \"to_local\"";
133 ERR_PERSIST <<
"[get_global_variable] missing attribute \"namespace\"";
137 DBG_PERSIST <<
"verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"];
141 ERR_PERSIST <<
"[get_global_variable] attribute \"side\" specifies invalid side number.";
144 DBG_PERSIST <<
"end verify_and_get_global_variable with from_global=" << pcfg[
"from_global"] <<
" from side " << pcfg[
"side"];
152 LOG_PERSIST <<
"Error: [get_global_variable] attribute \"namespace\" is not valid.";
160 ERR_PERSIST <<
"[set_global_variable] missing required attribute \"to_global\"";
164 LOG_PERSIST <<
"Warning: [set_global_variable] missing attribute \"from_local\", global variable will be cleared";
168 ERR_PERSIST <<
"[set_global_variable] missing attribute \"namespace\" and no global namespace provided.";
173 int side = pcfg_side.
to_int();
175 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
178 ERR_PERSIST <<
"[set_global_variable] attribute \"side\" specifies invalid side number.";
181 LOG_PERSIST <<
"[set_global_variable] attribute \"side\" specifies a null-controlled side number.";
195 LOG_PERSIST <<
"Error: [set_global_variable] attribute \"namespace\" is not valid.";
203 ERR_PERSIST <<
"[clear_global_variable] missing required attribute \"global\"";
207 ERR_PERSIST <<
"[clear_global_variable] missing attribute \"namespace\" and no global namespace provided.";
212 const int side = pcfg_side.
to_int();
214 if (pcfg_side.
str() !=
"global" && !pcfg_side.
empty()) {
217 ERR_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies invalid side number.";
220 LOG_PERSIST <<
"[clear_global_variable] attribute \"side\" specifies a null-controlled side number.";
234 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