/* * base_actions.h * * * Created by Andreas Vox on 02.06.06. * Copyright 2006 under GPL2. All rights reserved. * */ #ifndef BASE_ACTIONS_H #define BASE_ACTIONS_H /***** Defines the following actions: Attribute( name, def) - -> D Attribute( name ) - -> D *RefAttribute( name ) - -> D *Get( gen, fun ) - -> D *Set( gen, fun, gen ) - -> - *Top( n ) - -> D *Bottom( n ) - -> D *WithText( gen, fun ) - -> - *Invoke(fun, a1, ...) O -> O *InvokeLater(fun, a1, ...) O -> O *Call(fun, a1, ..., an) - -> - *CallLater(fun, a1, ..., an) - -> - *Filter ( gen, fun ) - -> E *Combine ( gen, gen, fun) - -> F *****/ /** * Converts an attribute to an object of type Data_Type and pushes it onto the stack. */ template class Attribute_body : public Generator_body { public: Attribute_body(const Xml_string& name) : name_(name), default_(NULL) {} Attribute_body(const Xml_string& name, const Data_Type& def) : name_(name), default_(new Data_Type(def)) {} ~Attribute_body() { if (default_) delete default_; } void begin(const Xml_string&, Xml_attr) { if (attr.contains(name_)) dig->push(new Data_Type(attr[name_])); else if (default_) dig->push(new Data_Type(default_)); else dig->push(NULL); } private: const Xml_string name_; const Data_Type* default_; }; template struct Attribute : public MakeGenerator, const Xml_string&, const Type&> { Attribute(const Xml_string& name) : MakeGenerator, const Xml_string&>::MakeGenerator(name) {} Attribute(const Xml_string& name, const Type& def) : MakeGenerator, const Xml_string&, const Type&>::MakeGenerator(name, def) {} }; /* template class Call0 : public Action { public: Call0(Functor f) : fun(f) {} void begin(const std::string, std::map attr) { fun(); } private: Functor fun; }; template class Call1 : public Action { public: Call1(Functor f, Generator a1) : fun(f), arg1(a1) {} void begin(const std::string, std::map attr) { fun(arg1->eval(digester(), tag, attr)); } private: Functor fun; Generator arg1; }; template class Call2 : public Action { public: Call2(Functor f, Generator* a1, Generator* a2) : fun(f), arg1(a1), arg2(a2) {} void begin(const std::string, std::map attr) { fun(arg1->eval(digester(), tag, attr), arg2->eval(digester(), tag, attr)); } private: Functor fun; Generator arg1; Generator arg2; }; /* Baustelle template class Invoke : public Action { public: Invoke(void (Obj_Type::*inv)(Data_Type&)) : set_(set) {} void end(const std::string); private: void (Obj_Type::*set_)(Data_Type&); }; */ #endif