12 #ifndef SIMPLE_ACTIONS_H
13 #define SIMPLE_ACTIONS_H
52 template<
class Obj_Type>
56 typedef Obj_Type* (*FunType)();
62 Factory_body(FunType create)
66 void begin(
const Xml_string&, Xml_attr)
68 this->dig->push(create_? create_() :
new Obj_Type());
71 Obj_Type* (*create_)();
88 template<
class Obj_Type>
92 typedef Obj_Type* (*FunType)(
const Xml_string&, Xml_attr);
98 void begin(
const Xml_string& name, Xml_attr attr)
100 this->dig->push(create_(name, attr));
103 Obj_Type* (*create_)(
const Xml_string&, Xml_attr);
106 template <
class Type>
118 template<
class Obj_Type>
122 typedef Obj_Type* (*FunType)(
const Xml_string&);
128 FactoryWithName_body(FunType create)
132 void begin(
const Xml_string& tag, Xml_attr)
134 this->dig->push(create_? create_(tag) :
new Obj_Type(tag));
140 template <
class Type>
154 template<
class Obj_Type>
159 : proto_(
new Obj_Type(proto))
167 void begin(
const Xml_string&, Xml_attr)
169 this->dig->push(
new Obj_Type(proto_));
172 const Obj_Type* proto_;
176 template <
class Type>
188 template<
class Obj_Type>
196 void begin(
const Xml_string&, Xml_attr)
198 this->dig->push(this->dig->template top<Obj_Type>(distance));
201 unsigned int distance;
205 template <
class Type>
220 template<
class Obj_Type,
class Data_Type>
224 typedef const Data_Type& (Obj_Type::*FunType)();
230 void begin(
const Xml_string&, Xml_attr)
232 Obj_Type* obj = this->dig->template top<Obj_Type>(1);
233 Data_Type* data = (obj->*get_)();
234 this->dig->push(data);
241 template <
class Type,
class Data>
242 struct Getter :
public MakeGenerator<Getter_body<Type, Data>, Data, typename Getter_body<Type, Data>::FunType>
252 template<
class Obj_Type,
class Data_Type,
class Store_Type>
256 typedef void (Obj_Type::*FunType)(Data_Type*);
262 void end(
const Xml_string&)
264 Store_Type* data = this->dig->template top<Store_Type>();
265 Obj_Type* obj = this->dig->template top<Obj_Type>(1);
267 std::cerr <<
"setter(ptr): " << obj <<
" .= " << data <<
"\n";
269 (obj->*set_)( data );
276 template <
class Type,
class Data,
class Store = Data>
277 struct SetterP :
public MakeAction<SetterP_body<Type, Data, Store>, typename SetterP_body<Type, Data, Store>::FunType>
287 template<
class Obj_Type,
class Data_Type>
291 typedef void (Obj_Type::*FunType)(Data_Type);
297 void end(
const Xml_string&)
299 Data_Type* data = this->dig->template top<Data_Type>();
300 Obj_Type* obj = this->dig->template top<Obj_Type>(1);
302 std::cerr <<
"setter: " << obj <<
" .= *(" << data <<
")\n";
304 (obj->*set_)( *data );
311 template <
class Type,
class Data>
312 struct Setter :
public MakeAction<Setter_body<Type, Data>, typename Setter_body<Type, Data>::FunType>
322 template<
class Obj_Type,
class Data_Type,
class Store_Type>
326 typedef void (Obj_Type::*FunType)(Data_Type);
327 typedef Data_Type (*ConvType)(Store_Type);
330 : set_(set), conv_(conv)
333 void end(
const Xml_string&)
335 Store_Type* data = this->dig->template top<Store_Type>();
336 Obj_Type* obj = this->dig->template top<Obj_Type>(1);
338 std::cerr <<
"setter: " << obj <<
" .= " << conv_ <<
"(*" << data <<
")\n";
341 (obj->*set_)( conv_(*data) );
343 (obj->*set_)(
static_cast<Data_Type
>(*data) );
351 template <
class Type,
class Data,
class Store>
352 struct SetterWithConversion :
public MakeAction<SetterWithConversion_body<Type, Data, Store>, typename SetterWithConversion_body<Type, Data, Store>::FunType, typename SetterWithConversion_body<Type, Data, Store>::ConvType>
365 template<
class Obj_Type>
369 typedef void (Obj_Type::*FunType)(
const Xml_string&,
const Xml_string&) ;
374 void begin(
const Xml_string&, Xml_attr attr)
376 Obj_Type* obj = this->dig->template top<Obj_Type>();
377 Xml_attr::iterator it;
378 for(it=attr.begin(); it != attr.end(); ++it)
379 (obj->*set_)( Xml_key(it), Xml_data(it) );
386 template <
class Type>
399 template<
class Obj_Type,
class Data_Type>
403 typedef void (Obj_Type::*FunType)(Data_Type) ;
406 : set_(set), name_(name), default_(), hasDefault_(
false)
409 SetAttribute_body(FunType set,
const Xml_string& name, Data_Type deflt)
410 : set_(set), name_(name), default_(deflt), hasDefault_(
true)
413 void begin(
const Xml_string&, Xml_attr attr)
415 Obj_Type* obj = this->dig->template top<Obj_Type>();
416 Xml_attr::iterator it = attr.find(name_);
417 if (it != attr.end() )
418 (obj->*set_)( Data_Type(Xml_data(it)) );
419 else if (hasDefault_)
420 (obj->*set_)( default_ );
430 template <
class Type,
class Data>
431 struct SetAttribute :
public MakeAction<SetAttribute_body<Type,Data>, typename SetAttribute_body<Type,Data>::FunType, const Xml_string&, Data>
436 SetAttribute(
typename SetAttribute_body<Type,Data>::FunType set,
const Xml_string& name, Data deflt)
446 template<
class Obj_Type,
class Data_Type>
450 typedef void (Obj_Type::*FunType)(Data_Type) ;
451 typedef Data_Type (*ConvType)(
const Xml_string&);
454 : set_(set), name_(name), conv_(conv), default_(), hasDefault_(
false)
457 SetAttributeWithConversion_body(FunType set,
const Xml_string& name, ConvType conv, Data_Type deflt)
458 : set_(set), name_(name), conv_(conv), default_(deflt), hasDefault_(
true)
461 void begin(
const Xml_string&, Xml_attr attr)
463 Obj_Type* obj = this->dig->template top<Obj_Type>();
464 Xml_attr::iterator it = attr.find(name_);
465 if (it != attr.end() && conv_)
466 (obj->*set_)( conv_(Xml_data(it)) );
467 else if (hasDefault_)
468 (obj->*set_)( default_ );
479 template <
class Type,
class Data>
480 struct SetAttributeWithConversion :
public MakeAction<SetAttributeWithConversion_body<Type,Data>, typename SetAttributeWithConversion_body<Type,Data>::FunType, const Xml_string&, typename SetAttributeWithConversion_body<Type,Data>::ConvType, Data>
487 SetAttributeWithConversion(
typename BodyType::FunType set,
const Xml_string& name,
typename BodyType::ConvType conv, Data deflt)
497 template<
class Obj_Type>
501 typedef void (Obj_Type::*FunType)(
const Xml_string&);
506 void chars(
const Xml_string& txt)
508 Obj_Type* obj = this->dig->template top<Obj_Type>();
517 template <
class Type>
533 template<
class Obj_Type>
537 typedef void (Obj_Type::*FunType)(
const Xml_string&);
542 void begin(
const Xml_string&, Xml_attr)
547 void chars(
const Xml_string& chunk)
552 void end(
const Xml_string& tag)
554 Obj_Type* obj = this->dig->template top<Obj_Type>();
565 template <
class Type>
569 SetText(
typename BodyType::FunType set)
576 template<
class Obj_Type>
580 Store_body(
const Xml_string& name) : m_name(name) {}
582 void begin(
const Xml_string& tag, Xml_attr attr)
584 Obj_Type* obj = this->dig->template top<Obj_Type>();
586 this->dig->template store<Obj_Type>(m_name, obj);
594 template <
class Type>
613 template<
class Obj_Type>
619 void begin(
const Xml_string&, Xml_attr attr)
621 Obj_Type* obj = this->dig->template top<Obj_Type>();
623 Xml_attr::iterator it = attr.find(
"id");
624 if (it != attr.end())
626 mode.ID = attr[
"id"];
627 mode.isIdRef =
false;
630 Xml_attr::iterator it = attr.find(
"idref");
631 if (it != attr.end())
633 mode.ID = attr[
"idref"];
638 mode.isIdRef =
false;
643 Obj_Type* storedObj = this->dig->template lookup<Obj_Type>(mode.ID);
646 this->dig->store(mode.ID, obj);
648 else if ( !mode.isIdRef )
650 delete (this->dig->template top<Obj_Type>());
652 this->dig->push(this->dig->template lookup<Obj_Type>(mode.ID));
659 stack.push_back(mode);
662 void end(
const Xml_string&)
664 Mode mode = stack.back();
668 delete (this->dig->template top<Obj_Type>());
670 this->dig->push(this->dig->template lookup<Obj_Type>(mode.ID));
675 struct Mode { Xml_string ID;
bool isIdRef; };
676 std::vector<Mode> stack;
680 template <
class Type>
690 template<
class Data_Type>
698 void begin(
const Xml_string&, Xml_attr)
700 Data_Type* data = this->dig->template lookup<Data_Type>(ID_);
701 this->dig->push(data);
708 template <
class Data>
720 template<
class Obj_Type,
class Arg_Type>
724 typedef Obj_Type (*FunType)(
const Arg_Type&);
730 void begin(
const Xml_string&, Xml_attr)
733 cell.arg = this->dig->template top<Arg_Type>();
734 cell.obj = fun_(*cell.arg);
736 std::cerr <<
"transform: " << cell.arg <<
" -> " << cell.obj <<
")\n";
738 stack.push_back(cell);
740 this->dig->push(&cell.obj);
743 void end(
const Xml_string&)
745 Cell cell = stack.back();
748 this->dig->push(cell.arg);
752 struct Cell { Arg_Type* arg; Obj_Type obj; };
753 std::vector<Cell> stack;
757 template <
class Type,
class Arg>
758 struct Transform :
public MakeAction<Transform_body<Type, Arg>, typename Transform_body<Type, Arg>::FunType>
767 template<
class Obj_Type,
class Data_Type>
771 typedef void (Obj_Type::*FunType)(Data_Type*) ;
774 : set_(set), name_(name)
777 void begin(
const Xml_string&, Xml_attr attr)
779 Xml_attr::iterator it = attr.find(name_);
780 if (it != attr.end())
782 Obj_Type* obj = this->dig->template top<Obj_Type>();
783 this->dig->template patchInvoke<Obj_Type,Data_Type>(Xml_data(it), obj, set_);
792 template <
class Type,
class Data>
793 struct PatchIdRefAttribute :
public MakeAction<PatchIdRefAttribute_body<Type,Data>, typename PatchIdRefAttribute_body<Type,Data>::FunType, const Xml_string&>
806 template<
class Data_Type>
813 void end(
const Xml_string&)
815 this->dig->setResult(dig->template top<Data_Type>());
821 template <
class Data>
Definition: simple_actions.h:253
Definition: simple_actions.h:498
Definition: simple_actions.h:400
Definition: simple_actions.h:431
Definition: simple_actions.h:577
Definition: actions.h:139
Definition: simple_actions.h:119
Definition: simple_actions.h:366
Definition: simple_actions.h:53
Definition: simple_actions.h:518
Definition: simple_actions.h:206
Definition: simple_actions.h:155
Definition: simple_actions.h:141
Definition: simple_actions.h:107
Definition: simple_actions.h:323
Definition: simple_actions.h:709
Definition: simple_actions.h:822
Definition: simple_actions.h:352
Definition: simple_actions.h:221
Definition: simple_actions.h:681
Definition: simple_actions.h:768
Definition: simple_actions.h:189
Definition: simple_actions.h:242
Definition: simple_actions.h:721
Definition: simple_actions.h:566
Definition: simple_actions.h:793
Definition: simple_actions.h:89
Definition: simple_actions.h:614
Definition: simple_actions.h:691
Definition: simple_actions.h:177
Coord distance(Point const &a, Point const &b)
Definition: point.h:205
Definition: simple_actions.h:447
Definition: simple_actions.h:534
Definition: simple_actions.h:277
Definition: actions.h:182
Definition: simple_actions.h:807
Definition: simple_actions.h:288
Definition: actions.h:121
Definition: simple_actions.h:480
Definition: simple_actions.h:312
Definition: simple_actions.h:595
Definition: simple_actions.h:75
Definition: simple_actions.h:387