22 explicit XListNodeBase(
const char *name,
bool runtime =
false);
27 virtual shared_ptr<XNode> createByTypename(
30 virtual bool isThreadSafeDuringCreationByTypename()
const = 0;
35 unsigned int src_idx, dst_idx;
42 shared_ptr<XNode> caught;
49 shared_ptr<XNode> released;
59 virtual void catchEvent(
const shared_ptr<XNode>&,
int);
60 virtual void releaseEvent(
const shared_ptr<XNode>&,
int);
61 virtual void moveEvent(
unsigned int src_idx,
unsigned int dst_idx);
62 virtual void listChangeEvent();
71 explicit XListNode(
const char *name,
bool runtime =
false)
75 virtual bool isThreadSafeDuringCreationByTypename()
const {
return true;}
79 return this->create<NT>(name.c_str(),
false);
91 virtual bool isThreadSafeDuringCreationByTypename()
const {
return true;}
95 return shared_ptr<XNode>();
106 virtual bool isThreadSafeDuringCreationByTypename()
const {
return false;}
112 #include <functional>
118 template <
class... ArgTypes>
120 using creator_t = std::function<shared_ptr<XNode>(
const char*, bool, ArgTypes&&...)>;
123 fprintf(stderr,
"New typeholder\n");
126 creator_t creator(
const XString &tp) {
127 for(
unsigned int i = 0; i < names.size(); i++) {
128 if(names[i] == tp)
return creators[i];
130 return [](
const char*, bool, ArgTypes&&...){
return shared_ptr<XNode>();};
132 template <
class tChild>
135 creator_t create_typed =
136 [](
const char *name,
bool runtime, ArgTypes&&... args)->shared_ptr<XNode>
137 {
return XNode::createOrphan<tChild>(name, runtime, std::forward<ArgTypes>(args)...);};
138 assert(create_typed);
141 if(std::find(holder.names.begin(), holder.names.end(),
XString(name)) != holder.names.end()) {
142 fprintf(stderr,
"Duplicated name!\n");
145 holder.creators.push_back(create_typed);
146 holder.names.push_back(
XString(name));
147 holder.labels.push_back(
XString(label));
148 fprintf(stderr,
"%s %s\n", name, label);
152 static shared_ptr<XNode> creator_(
const char *name,
bool runtime, ArgTypes&&... args) {
153 return XNode::createOrphan<T>(name, runtime, std::forward<ArgTypes>(args)...);
156 template <
class tChild>
friend struct Creator;
157 std::deque<creator_t> creators;
158 std::deque<XString> names, labels;
161 #define DEFINE_TYPE_HOLDER(...) \
162 typedef XTypeHolder<__VA_ARGS__> TypeHolder; \
163 static TypeHolder s_types; \
164 static TypeHolder::creator_t creator(const XString &tp) {return s_types.creator(tp);} \
165 static std::deque<XString> &typenames() {return s_types.names;} \
166 static std::deque<XString> &typelabels() {return s_types.labels;}
168 #define DECLARE_TYPE_HOLDER(list) \
169 list::TypeHolder list::s_types;
171 #define REGISTER_TYPE_2__(list, type, name, label) list::TypeHolder::Creator<type> \
172 g_driver_type_ ## name(list::s_types, # name, label);
174 #define REGISTER_TYPE(list, type, label) REGISTER_TYPE_2__(list, X ## type, type, label)
178 explicit XStringList(
const char *name,
bool runtime =
false)