Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

base_actions.h

Go to the documentation of this file.
00001 /*
00002  *  base_actions.h
00003  *  
00004  *
00005  *  Created by Andreas Vox on 02.06.06.
00006  *  Copyright 2006 under GPL2. All rights reserved.
00007  *
00008  */
00009 
00010 
00011 #ifndef BASE_ACTIONS_H
00012 #define BASE_ACTIONS_H
00013 
00014 /*****
00015 
00016     Defines the following actions:
00017 
00018     Attribute<D>( name, def)                        - -> D
00019     Attribute<D>( name )                            - -> D
00020     *RefAttribute<D>( name )                         - -> D
00021     *Get<O,D>( gen<O>, fun )                         - -> D
00022     *Set<O,D>( gen<O>, fun, gen<D> )                 - -> -
00023     *Top<D>( n )                                     - -> D
00024     *Bottom<D>( n )                                  - -> D
00025     *WithText<O,D>( gen<O>, fun )                    - -> -
00026     *Invoke<O, F, A1, ...>(fun, a1, ...)             O -> O
00027     *InvokeLater<O, F, A1, ...>(fun, a1, ...)        O -> O
00028     *Call<F,A1, ..., An>(fun, a1, ..., an)           - -> -
00029     *CallLater<F,A1, ..., An>(fun, a1, ..., an)      - -> -
00030     *Filter<D,E> ( gen<D>, fun )                     - -> E
00031     *Combine<D,E,F> ( gen<D>, gen<D>, fun)           - -> F
00032 
00033 *****/
00034 
00035 
00041 template<class Data_Type>
00042 class Attribute_body : public Generator_body<Data_Type>
00043 {
00044 public:
00045     Attribute_body(const Xml_string& name) 
00046     : name_(name), default_(NULL) 
00047 {}
00048     
00049     Attribute_body(const Xml_string& name, const Data_Type& def) 
00050     : name_(name), default_(new Data_Type(def)) 
00051 {}
00052     
00053     ~Attribute_body() 
00054 { 
00055         if (default_) 
00056             delete default_; 
00057 }
00058 
00059 void begin(const Xml_string&, Xml_attr)
00060 {
00061     if (attr.contains(name_))
00062         dig->push(new Data_Type(attr[name_]));
00063     else if (default_)
00064         dig->push(new Data_Type(default_));
00065     else
00066         dig->push(NULL);
00067 }
00068 private:
00069 const Xml_string name_;
00070 const Data_Type* default_;
00071 };
00072 
00073 
00074 template <class Type>
00075 struct  Attribute : public MakeGenerator<Attribute_body<Type>, const Xml_string&, const Type&> 
00076 { 
00077     Attribute(const Xml_string& name)
00078     : MakeGenerator<Attribute_body<Type>, const Xml_string&>::MakeGenerator(name) {} 
00079     
00080     Attribute(const Xml_string& name, const Type& def)
00081     : MakeGenerator<Attribute_body<Type>, const Xml_string&, const Type&>::MakeGenerator(name, def) {} 
00082     
00083 };
00084 
00085 
00086 
00087 /*
00088  template<class Functor>
00089  class Call0 : public Action
00090  {
00091 public:
00092      Call0(Functor f) : fun(f)
00093     {}
00094      
00095      void begin(const std::string, std::map<std::string,std::string> attr)
00096     {
00097          fun();
00098     }   
00099 private:
00100      Functor fun;
00101  };
00102  
00103  
00104  template<class Functor, class Arg1>
00105  class Call1 : public Action
00106  {
00107 public:
00108      Call1(Functor f, Generator<Arg1> a1) : fun(f), arg1(a1)
00109     {}
00110      
00111      void begin(const std::string, std::map<std::string,std::string> attr)
00112     {
00113          fun(arg1->eval(digester(), tag, attr));
00114     }
00115 private:
00116      Functor fun;
00117      Generator<Arg1> arg1;
00118  };
00119  
00120  template<class Functor, class Arg1, class Arg2>
00121  class Call2 : public Action
00122  {
00123 public:
00124      Call2(Functor f, Generator<Arg1>* a1, Generator<Arg2>* a2) : fun(f), arg1(a1), arg2(a2) 
00125     {}
00126      
00127      void begin(const std::string, std::map<std::string,std::string> attr)
00128     {
00129          fun(arg1->eval(digester(), tag, attr), 
00130              arg2->eval(digester(), tag, attr));
00131     }
00132 private:
00133      Functor fun;
00134      Generator<Arg1> arg1;  
00135      Generator<Arg2> arg2;  
00136  };
00137  
00138  /* Baustelle
00139  template<class Obj_Type, class Data_Type>
00140  class Invoke : public Action 
00141  {
00142 public:
00143      Invoke(void (Obj_Type::*inv)(Data_Type&)) : set_(set) {}
00144      void end(const std::string);
00145 private:
00146      void (Obj_Type::*set_)(Data_Type&);
00147  };
00148  */
00149  
00150 
00151 #endif
00152 
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.