17 #include "transaction.h"
19 #include "threadlocal.h"
31 #define trans(node) for(Transaction \
32 implicit_tr(node, false); !implicit_tr.isModified() || !implicit_tr.commitOrNext(); ) implicit_tr[node]
35 typename std::enable_if<std::is_base_of<XNode, T>::value,
const SingleSnapshot<T> >::type
40 template <
typename...Args>
42 template <
typename...Args>
51 explicit XNode(
const char *name,
bool runtime =
false);
55 shared_ptr<T> create(
const char *name) {
return create<T>(name,
false);}
56 template <
class T,
typename... Args>
57 shared_ptr<T> create(
const char *name,
bool runtime, Args&&... args);
60 shared_ptr<T> create(
Transaction &tr,
const char *name) {
return create<T>(tr, name,
false);}
61 template <
class T,
typename... Args>
62 shared_ptr<T> create(
Transaction &tr,
const char *name,
bool runtime, Args&&... args);
65 static shared_ptr<T__> createOrphan(
const char *name) {
return createOrphan<T__>(name,
false);}
66 template <
class T__,
typename... Args_>
67 static shared_ptr<T__> createOrphan(
const char *name,
bool runtime, Args_&&... args);
75 shared_ptr<XNode> getChild(
const XString &var)
const;
76 shared_ptr<XNode> getParent()
const;
88 bool isUIEnabled()
const {
return m_flags & FLAG::NODE_UI_ENABLED;}
89 void setUIEnabled(
bool var);
90 bool isDisabled()
const {
return m_flags & FLAG::NODE_DISABLED;}
92 bool isRuntime()
const {
return m_flags & FLAG::NODE_RUNTIME;}
93 void setRuntime(
bool var) {m_flags = (m_flags & ~FLAG::NODE_RUNTIME) | (var ? FLAG::NODE_RUNTIME : 0);}
98 enum FLAG :
int {NODE_UI_ENABLED = 0x1, NODE_DISABLED = 0x2, NODE_RUNTIME = 0x4};
131 using Validator = void (*)(
XString &);
132 void setValidator(Validator x) {m_validator = x;}
137 virtual XString to_str()
const = 0;
142 if(static_cast<XValueNodeBase&>(node()).m_validator)
151 virtual void str_(
const XString &) = 0;
155 Validator m_validator;
159 template <
typename T,
int base = 10>
167 virtual XString to_str()
const override;
168 operator T()
const {
return m_var;}
169 Payload &operator=(T x) {
171 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>(&node()));
175 virtual void str_(
const XString &)
override;
182 explicit XDoubleNode(
const char *name,
bool runtime =
false,
const char *format = 0L);
186 void setFormat(
const char* format);
190 virtual XString to_str()
const override;
191 operator double()
const {
return m_var;}
192 Payload &operator=(
double x) {
194 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>(&node()));
198 virtual void str_(
const XString &)
override;
206 explicit XStringNode(
const char *name,
bool runtime =
false);
211 operator const XString&()
const {
return m_var;}
212 Payload &operator=(
const XString &x) {
214 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>(&node()));
230 template <
class T,
typename... Args>
232 XNode::createOrphan(
const char *name,
bool runtime, Args&&... args) {
234 shared_ptr<T> ptr = dynamic_pointer_cast<T>(XNode::stl_thisCreating->back());
235 XNode::stl_thisCreating->pop_back();
239 template <
class T,
typename... Args>
241 XNode::create(
Transaction &tr,
const char *name,
bool runtime, Args&&... args) {
242 shared_ptr<T> ptr(createOrphan<T>(name, runtime, std::forward<Args>(args)...));
243 if(ptr)
insert(tr, ptr,
true);
247 template <
class T,
typename... Args>
249 XNode::create(
const char *name,
bool runtime, Args&&... args) {
250 shared_ptr<T> ptr(createOrphan<T>(name, runtime, std::forward<Args>(args)...));