Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:09:52

0001 #ifndef ATOOLS_Org_Getter_Function_H
0002 #define ATOOLS_Org_Getter_Function_H
0003 
0004 #include <map>
0005 #include <vector>
0006 #include <string>
0007 
0008 namespace ATOOLS {
0009 
0010   class String_Sort;
0011 
0012   template <class ObjectType,class ParameterType,
0013         class SortCriterion=std::less<std::string> >
0014   class Getter_Function {
0015   public:
0016 
0017     typedef ObjectType Object_Type;
0018     typedef SortCriterion Sort_Criterion;
0019     typedef std::vector<const Getter_Function *> Getter_List;
0020     typedef ParameterType Parameter_Type;
0021     typedef typename std::map<const std::string,Getter_Function *const,
0022                   Sort_Criterion> String_Getter_Map;
0023 
0024   private:
0025 
0026     static String_Getter_Map *s_getters;
0027 
0028     static bool s_exactmatch;
0029     bool m_display;
0030 
0031   protected:
0032 
0033     virtual Object_Type * 
0034     operator()(const Parameter_Type &parameters) const;
0035 
0036     virtual void PrintInfo(std::ostream &str,const size_t width) const;
0037 
0038   public:
0039     
0040     // constructor
0041     Getter_Function(const std::string &name);
0042 
0043     // destructor
0044     virtual ~Getter_Function();
0045 
0046     // member functions
0047     static void PrintGetterInfo(std::ostream &str,const size_t width,
0048                                 const std::string &indent="   ",
0049                                 const std::string &separator=" ",
0050                                 const std::string &lineend="\n",
0051                                 const std::string &replacefrom="",
0052                                 const std::string &replaceto="");
0053 
0054     Object_Type *GetObject(const Parameter_Type &parameters) const;
0055 
0056     static Object_Type *GetObject(const std::string &name,
0057                   const Parameter_Type &parameters);
0058     static Getter_List GetGetters(const std::string &name="");
0059 
0060     // inline functions
0061     inline static void SetExactMatch(const bool exactmatch)
0062     { s_exactmatch=exactmatch; }
0063     inline void SetDisplay(const bool display)
0064     { m_display=display; }
0065     
0066     inline static bool ExactMatch() { return s_exactmatch; }
0067   
0068   };// end of class Getter_Function
0069 
0070   template <class ObjectType,class ParameterType,class TagType,
0071         class SortCriterion=std::less<std::string> >
0072   class Getter {};
0073 
0074 }// end of namespace ATOOLS
0075 
0076 #define DECLARE_GETTER_BASE(NAME,TAG,OBJECT,PARAMETER,SORT)     \
0077                                     \
0078   namespace ATOOLS {                            \
0079     template <> class Getter<OBJECT,PARAMETER,NAME,SORT>:       \
0080       public Getter_Function<OBJECT,PARAMETER,SORT> {           \
0081     private:                                \
0082       static Getter<OBJECT,PARAMETER,NAME,SORT> s_initializer;      \
0083     protected:                              \
0084       void PrintInfo(std::ostream &str,const size_t width) const;   \
0085       Object_Type *operator()(const Parameter_Type &parameters) const;  \
0086     public:                             \
0087       Getter(const bool &d=true):       \
0088     Getter_Function<OBJECT,PARAMETER,SORT>(TAG)         \
0089     { SetDisplay(d); }                      \
0090     };                                  \
0091   }
0092 
0093 #define DECLARE_ND_GETTER(NAME,TAG,OBJECT,PARAMETER,DISP)       \
0094                                     \
0095   namespace ATOOLS {                            \
0096     template <> class Getter<OBJECT,PARAMETER,NAME>/** @cond RECURSIVE_WARNING */:      \
0097       public Getter_Function<OBJECT,PARAMETER> /** @endcond */ {            \
0098     private:                                \
0099       static Getter<OBJECT,PARAMETER,NAME> s_initializer;       \
0100     protected:                              \
0101       void PrintInfo(std::ostream &str,const size_t width) const;   \
0102       Object_Type *operator()(const Parameter_Type &parameters) const;  \
0103     public:                             \
0104       Getter(const bool &d=true):       \
0105     Getter_Function<OBJECT,PARAMETER>(TAG)          \
0106     { SetDisplay(d); }                      \
0107   }; \
0108   Getter<OBJECT,PARAMETER,NAME>                 \
0109   Getter<OBJECT,PARAMETER,NAME>::s_initializer(DISP); \
0110   }
0111 
0112 #define DECLARE_GETTER(NAME,TAG,OBJECT,PARAMETER)           \
0113   DECLARE_ND_GETTER(NAME,TAG,OBJECT,PARAMETER,true)
0114 
0115 #define DECLARE_NI_GETTER(NAME,OBJECT,PARAMETER,SORT)           \
0116                                     \
0117   namespace ATOOLS {                            \
0118     template <> class Getter<OBJECT,PARAMETER,NAME,SORT>:       \
0119       public ATOOLS::Getter_Function<OBJECT,PARAMETER,SORT> {       \
0120     protected:                              \
0121       void PrintInfo(std::ostream &str,const size_t width) const;   \
0122       Object_Type *operator()(const Parameter_Type &parameters) const;  \
0123     public:                             \
0124       Getter(const std::string &name,const bool d=true):            \
0125     Getter_Function<OBJECT,PARAMETER,SORT>(name)            \
0126     { SetDisplay(d); }                      \
0127     };                                  \
0128   }
0129 
0130 #endif