18 #include "xlistnode.h"
23 explicit XItemNodeBase(
const char *name,
bool runtime =
false,
bool auto_set_any =
false);
27 virtual std::vector<Item> itemStrings(
const Snapshot &shot_of_list)
const = 0;
29 bool autoSetAny()
const {
return !!m_lsnTryAutoSet;}
44 shared_ptr<XListener> m_lsnTryAutoSet;
45 void onTryAutoSet(
const Snapshot &shot,
const Payload::ListChangeEvent &e);
49 xpointeritemnode_throwConversionError_();
55 const shared_ptr<TL> &list,
bool auto_set_any =
false)
63 operator shared_ptr<XNode>()
const {
return m_var.lock();}
65 shared_ptr<XNode>
node( *
this);
67 return node->getLabel();
71 Payload &operator=(
const shared_ptr<XNode> &t) {
73 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>( &
node()));
79 *
this = shared_ptr<XNode>();
82 if(
auto list = static_cast<const XPointerItemNode&>(
node()).m_list.lock()) {
85 for(
auto it = shot.list()->begin(); it != shot.list()->end(); ++it) {
86 if(( *it)->getLabel() == var) {
93 xpointeritemnode_throwConversionError_();
95 weak_ptr<XNode> m_var;
100 if(e.released != (shared_ptr<XNode>)shot[ *
this])
103 tr[ *
this] = shared_ptr<XNode>();
104 if(tr.commit())
break;
108 if(
auto list = m_list.lock()) {
109 assert(node == list.get());
110 typename Payload::ListChangeEvent e(shot,
this);
111 Snapshot( *this).talk(( **this)->onListChanged(), std::move(e));
114 shared_ptr<XListener> m_lsnOnItemReleased, m_lsnOnListChanged;
119 template <
class TL,
class... VT>
126 const shared_ptr<TL> &list,
bool auto_set_any =
false)
130 virtual std::vector<XItemNodeBase::Item> itemStrings(
const Snapshot &)
const override {
131 return std::vector<XItemNodeBase::Item>();
137 template <
class TL,
class T1,
class... VT>
141 const shared_ptr<TL> &list,
bool auto_set_any =
false)
142 :
XItemNode<TL, VT...>(name, runtime, tr_list, list, auto_set_any) {
148 operator shared_ptr<T1>()
const {
149 return dynamic_pointer_cast<T1>(shared_ptr<XNode>( *this));
151 Payload &operator=(
const shared_ptr<XNode> &t) {
157 virtual std::vector<XItemNodeBase::Item> itemStrings(
const Snapshot &shot)
const override {
159 if(
auto list = this->m_list.lock()) {
160 if(shot.size(list)) {
161 for(
auto it = shot.list(list)->begin(); it != shot.list(list)->end(); ++it) {
162 if(dynamic_pointer_cast<T1>( *it)) {
164 item.name = ( *it)->getName();
165 item.label = ( *it)->getLabel();
166 items.push_back(std::move(item));
171 return std::move(items);
178 explicit XComboNode(
const char *name,
bool runtime =
false,
bool auto_set_any =
false);
181 virtual std::vector<XItemNodeBase::Item> itemStrings(
const Snapshot &shot)
const override {
182 return shot[ *
this].itemStrings();
187 m_var(std::pair<XString, int>(
"", -1)) {}
189 void add(std::initializer_list<XString> strlist) {
for(
auto &&x: strlist){ add(x);}}
191 operator int()
const {
return m_var.second;}
193 Payload &operator=(
int t);
194 Payload &operator=(
const XString &);
195 virtual std::vector<XItemNodeBase::Item> itemStrings()
const;
197 virtual void str_(
const XString &)
override;
199 shared_ptr<std::deque<XString> > m_strings;
200 std::pair<XString, int> m_var;