22 #define LOG_PERSIST LOG_STREAM(info, log_persist) 23 #define ERR_PERSist LOG_STREAM(err, log_persist) 42 while (namespace_.find_first_of(
"^") < namespace_.size()) {
43 if (namespace_[0] ==
'^') {
48 std::string infix = namespace_.substr(namespace_.find_first_of(
"^"));
49 std::size_t end = infix.find_first_not_of(
"^");
50 if (!((end >= infix.length()) || (infix[end] ==
'.'))) {
55 infix = infix.substr(0,end);
56 std::string suffix = namespace_.substr(namespace_.find_first_of(
"^") + infix.length());
57 while (!infix.empty())
59 std::string body = namespace_.substr(0,namespace_.find_first_of(
"^"));
60 body = body.substr(0,body.find_last_of(
"."));
61 infix = infix.substr(1);
62 namespace_ = body + infix + suffix;
72 operator bool ()
const {
return valid_; }
93 valid_ = ((namespace_.find_first_not_of(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_.") > namespace_.length()) && !namespace_.empty());
94 root_ = namespace_.substr(0,namespace_.find_first_of(
"."));
95 node_ = namespace_.substr(namespace_.find_last_of(
".") + 1);
96 if (namespace_.find_last_of(
".") <= namespace_.length())
97 lineage_ = namespace_.substr(0,namespace_.find_last_of(
"."));
98 if (namespace_.find_first_of(
".") <= namespace_.length())
99 descendants_ = namespace_.substr(namespace_.find_first_of(
".") + 1);
112 , in_transaction_(false)
117 , namespace_(name_space,true)
118 , valid_(namespace_.
valid())
119 , in_transaction_(false)
149 virtual bool clear_var(
const std::string &,
bool immediate =
false) = 0;
151 virtual bool set_var(
const std::string &,
const config &,
bool immediate =
false) = 0;
172 bool clear_var(
const std::string &,
bool immediate =
false);
174 bool set_var(
const std::string &,
const config &,
bool immediate =
false);
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...
virtual bool start_transaction()=0
static lg::log_domain log_persist("engine/persistence")
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
const config * get_node(const config &cfg, const name_space &ns) const
virtual bool cancel_transaction()=0
virtual ~persist_context()
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
virtual bool set_var(const std::string &, const config &, bool immediate=false)=0
Definitions for the interface to Wesnoth Markup Language (WML).
struct utils::detail::formula_initer init
virtual config get_var(const std::string &) const =0
config pack_scalar(const std::string &, const t_string &)
virtual bool clear_var(const std::string &, bool immediate=false)=0
persist_context(const std::string &name_space)
virtual bool end_transaction()=0
void set_node(const std::string &)
std::string get_node() const
config * get_node(config &cfg, name_space &ns, bool force=false)
Standard logging facilities (interface).
name_space(const std::string &ns, bool doParse=false)
A config object defines a single node in a WML file, with access to child nodes.
bool cancel_transaction()