| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

ParameterDescription.h

Go to the documentation of this file.
00001 #ifndef PARAMETERDESCRIPTION_H
00002 #define PARAMETERDESCRIPTION_H
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <typeinfo>
00007 #include <boost/shared_ptr.hpp>
00008 
00009 
00010 namespace RuleParser{
00011 
00012 class RuleFactory;
00013 
00014 class ParameterDescription
00015 {
00016 public:
00017   // For complex, user-driven parameter types
00018   ParameterDescription(unsigned int id,                    // ID number for use with queryParam
00019                        const std::string& name,            // String that matches this paramter when parsing
00020                        const std::type_info& type,         // Type of returned parameter, int, double, string, or custom
00021                        const std::vector<std::string>& operators, // List of operators valid for this parameter.
00022                        const boost::shared_ptr<RuleFactory>& ruleFactory // Optional factory that will produce rule for this paramater
00023                        );
00024 
00025   ParameterDescription(unsigned int id,                    // ID number for use with queryParam
00026                        const std::string& name,            // String that matches this paramter when parsing
00027                        const std::type_info& type,         // Type of returned parameter, int, double, string, or custom
00028                        const std::vector<std::string>& operators, // List of operators valid for this parameter.
00029                        RuleFactory* ruleFactory           // Optional factory that will produce rule for this paramater
00030                        );
00031 
00032   // For simple parameters (int,double,string match)
00033   ParameterDescription(unsigned int id,                    // ID number for use with queryParam
00034                        const std::string& name,            // String that matches this paramter when parsing
00035                        const std::type_info& type          // Type of returned parameter, int, double, string, or custom
00036                        );
00037 
00038   ~ParameterDescription();
00039 
00040   const std::string&   name()  const{ return m_name; };
00041   unsigned int         id()    const{ return m_id;   };
00042   const std::string&   type()  const{ return m_type; };
00043   
00044   const std::vector<std::string>&       operators() const{ return m_operators; };
00045   const boost::shared_ptr<RuleFactory>& factory()   const{ return m_factory; };
00046   bool                                  isCustom()  const{ return m_factory.get(); };
00047   
00048 protected:
00049   unsigned int                   m_id;
00050   std::string                    m_name;
00051   std::string                    m_type;
00052   std::vector<std::string>       m_operators;
00053   boost::shared_ptr<RuleFactory> m_factory;
00054 };
00055 
00056 
00057 class ParameterList;
00058 
00059 class ParameterList : public std::vector<ParameterDescription>
00060 {
00061 public:
00062   // Some easier ways to add paramters to the list.
00063   
00064   ParameterList& add(const ParameterDescription& d) { push_back(d); return *this; };
00065 
00066   template<typename T>
00067   ParameterList& add(unsigned int id, const std::string& name)
00068     { push_back(ParameterDescription(id,name,typeid(T))); return *this; }  ;
00069 
00070   template<typename T>
00071   ParameterList& add(unsigned int id, 
00072                     const std::string& name, 
00073                     const std::string& alias1)
00074     { 
00075       push_back(ParameterDescription(id,name,  typeid(T)));
00076       push_back(ParameterDescription(id,alias1,typeid(T)));
00077       return *this; 
00078     }; 
00079   
00080   template<typename T>
00081   ParameterList& add(unsigned int id, 
00082                     const std::string& name, 
00083                     const std::string& alias1,
00084                     const std::string& alias2)
00085     { 
00086       push_back(ParameterDescription(id,name,  typeid(T)));
00087       push_back(ParameterDescription(id,alias1,typeid(T)));
00088       push_back(ParameterDescription(id,alias2,typeid(T)));
00089       return *this; 
00090     };  
00091 
00092   template<typename T>
00093   ParameterList& add(unsigned int id, 
00094                     const std::string& name, 
00095                     const std::string& alias1,
00096                     const std::string& alias2,
00097                     const std::string& alias3)
00098     { 
00099       push_back(ParameterDescription(id,name,  typeid(T)));
00100       push_back(ParameterDescription(id,alias1,typeid(T)));
00101       push_back(ParameterDescription(id,alias2,typeid(T)));
00102       push_back(ParameterDescription(id,alias3,typeid(T)));
00103       return *this; 
00104     }; 
00105   
00106   template<typename T>
00107   ParameterList& add(unsigned int id, 
00108                     const std::string& name,
00109                     const std::string& opname,
00110                     RuleFactory* factory)
00111     { 
00112       push_back(ParameterDescription(id,name,typeid(T),std::vector<std::string>(1,opname),factory)); 
00113       return *this; 
00114     };  
00115   
00116   template<typename T>
00117   ParameterList& add(unsigned int id, 
00118                     const std::string& name,
00119                     const std::string& opname,
00120                     const boost::shared_ptr<RuleFactory>& factory)
00121     { 
00122       push_back(ParameterDescription(id,name,typeid(T),std::vector<std::string>(1,opname),factory)); 
00123       return *this; 
00124     };  
00125   
00126 };
00127 
00128 }
00129 
00130 #endif /* PARAMETERDESCRIPTION_H */
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:09:14 2011 for RuleParser by doxygen 1.4.7