15 #ifndef PERSIST_CONTEXT_H_INCLUDED
16 #define PERSIST_CONTEXT_H_INCLUDED
21 #define LOG_PERSIST LOG_STREAM(info, log_persist)
22 #define ERR_PERSist LOG_STREAM(err, log_persist)
41 while (namespace_.find_first_of(
"^") < namespace_.size()) {
42 if (namespace_[0] ==
'^') {
47 std::string infix = namespace_.substr(namespace_.find_first_of(
"^"));
48 size_t end = infix.find_first_not_of(
"^");
49 if (!((end >= infix.length()) || (infix[end] ==
'.'))) {
54 infix = infix.substr(0,end);
55 std::string suffix = namespace_.substr(namespace_.find_first_of(
"^") + infix.length());
56 while (!infix.empty())
59 body = body.substr(0,body.find_last_of(
"."));
60 infix = infix.substr(1);
61 namespace_ = body + infix + suffix;
71 operator bool ()
const {
return valid_; }
92 valid_ = ((namespace_.find_first_not_of(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_.") > namespace_.length()) && !namespace_.empty());
93 root_ = namespace_.substr(0,namespace_.find_first_of(
"."));
94 node_ = namespace_.substr(namespace_.find_last_of(
".") + 1);
95 if (namespace_.find_last_of(
".") <= namespace_.length())
96 lineage_ = namespace_.substr(0,namespace_.find_last_of(
"."));
97 if (namespace_.find_first_of(
".") <= namespace_.length())
98 descendants_ = namespace_.substr(namespace_.find_first_of(
".") + 1);
111 , in_transaction_(false)
116 , namespace_(name_space,true)
117 , valid_(namespace_.
valid())
118 , in_transaction_(false)
virtual bool start_transaction()=0
static lg::log_domain log_persist("engine/persistence")
virtual bool cancel_transaction()=0
virtual ~persist_context()
config & child_or_add(const std::string &key)
Returns a reference to the first child with the given key.
static void body(LexState *ls, expdesc *e, int ismethod, int line)
virtual bool set_var(const std::string &, const config &, bool immediate=false)=0
Definitions for the interface to Wesnoth Markup Language (WML).
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
const config * get_node(const config &cfg, const name_space &ns) const
virtual config get_var(const std::string &) const =0
bool set_var(const std::string &, const config &, bool immediate=false)
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)
std::string get_node() const
persist_file_context(const std::string &name_space)
virtual bool end_transaction()=0
void set_node(const std::string &)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
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()
config get_var(const std::string &) const
GLsizei const GLcharARB ** string
bool clear_var(const std::string &, bool immediate=false)