libalcommon  1.14.5
alcommon/almethodinfo.h
Go to the documentation of this file.
00001 
00010 #pragma once
00011 #ifndef _LIBALCOMMON_ALCOMMON_ALMETHODINFO_H_
00012 #define _LIBALCOMMON_ALCOMMON_ALMETHODINFO_H_
00013 
00014 # include <alcommon/alparamtype.h>
00015 # include <boost/shared_ptr.hpp>
00016 
00017 
00018 # define BLOCKINGFUNCTION     0 
00019 # define ASYNCHRONOUSFUNCTION 1 
00021 namespace AL
00022 {
00023   class ALFunctorBase;
00024 
00033   class ALMethodInfo
00034   {
00035   public:
00037     ALMethodInfo() {
00038       mask = 0;
00039     }
00040 
00042     virtual ~ALMethodInfo() {}
00043 
00048     enum methodOption {
00049       CPPMethod           = 1, 
00050       AsynchronousMethod  = 2, 
00051       localMethod         = 4  
00052     };
00053 
00058     class ALParameterInfo
00059     {
00060     public:
00061       std::string paramError;  
00062       std::string name;        
00063       std::string description; 
00064       std::string strType;     
00065       bool        optional;    
00066     };
00067 
00072     template <typename T>
00073     class ALParameterInfoOptional: public ALParameterInfo {
00074     public:
00079       ALParameterInfoOptional(T defaultValue) {
00080         m_defaultValue = defaultValue;
00081       }
00082       T m_defaultValue; 
00083     };
00084 
00089     class ALExample {
00090     public:
00091       std::string language;   
00092       std::string strExample; 
00093     };
00094 
00095     std::string                      moduleName;        
00096     std::string                      methodName;        
00097     std::string                      methodDescription; 
00098     std::vector<ALParameterInfo>     parameters;        
00099     std::string                      returnValue;       
00100     std::vector<ALExample>           examples;          
00101     boost::shared_ptr<ALFunctorBase> ptrOnMethod;       
00102     ALParameterInfo                  returnInfo;        
00103     short                            mask;              
00110     bool isCpp(void) {
00111       return ((mask & CPPMethod) == CPPMethod);
00112     }
00113 
00118     bool isAsynchronous(void) {
00119       return (mask & AsynchronousMethod) > 0 ? true: false;
00120     }
00121 
00126     bool isLocalMethod(void) {
00127       return ((mask & localMethod) == localMethod);
00128     }
00129 
00134     void addOption(int pOption)
00135     {
00136       mask = mask | (short)pOption;
00137     }
00138 
00143     ALFunctorBase* getFunction() {
00144       return ptrOnMethod.get();
00145     }
00146 
00150     void clear(void) {
00151       parameters.clear();
00152       examples.clear();
00153     }
00154   };
00155 
00156   template <typename C, typename R>
00157   void completeAndCheck(R(C::*) (), ALMethodInfo & pDesc)
00158   {
00159     pDesc.returnInfo.strType = getParamStrType<R>();
00160   }
00161 
00162   template <typename C, typename P1, typename R>
00163   void completeAndCheck(R(C::*) (P1), ALMethodInfo & pDesc)
00164   {
00165     pDesc.returnInfo.strType = getParamStrType<R>();
00166     ALMethodInfo::ALParameterInfo param;
00167     param.description = "arg";
00168     std::string name = "arg0";
00169     for (int i = pDesc.parameters.size(); i < 1; ++i) {
00170       name[3] = (char) (i + '1');
00171       param.name = name;
00172       pDesc.parameters.push_back(param);
00173     }
00174     pDesc.parameters[0].strType =  getParamStrType<P1>();
00175   }
00176 
00177   template <typename C, typename P1, typename P2, typename R>
00178   void completeAndCheck(R(C::*) (P1, P2), ALMethodInfo & pDesc)
00179   {
00180     pDesc.returnInfo.strType = getParamStrType<R>();
00181     ALMethodInfo::ALParameterInfo param;
00182     std::string name = "arg0";
00183     param.description = "arg";
00184     for (int i = pDesc.parameters.size() ; i < 2; ++i) {
00185       name[3] = (char) (i + '1');
00186       param.name  = name;
00187       pDesc.parameters.push_back(param);
00188     }
00189     pDesc.parameters[0].strType =  getParamStrType<P1>();
00190     pDesc.parameters[1].strType =  getParamStrType<P2>();
00191   }
00192 
00193   template <typename C, typename P1, typename P2, typename P3, typename R>
00194   void completeAndCheck(R(C::*) (P1, P2, P3), ALMethodInfo & pDesc)
00195   {
00196     pDesc.returnInfo.strType = getParamStrType<R>();
00197     ALMethodInfo::ALParameterInfo param;
00198     std::string name = "arg0";
00199     param.description = "arg";
00200     for (int i = pDesc.parameters.size(); i < 3; ++i) {
00201       name[3] = i + '1';
00202       param.name = name;
00203       pDesc.parameters.push_back(param);
00204     }
00205     pDesc.parameters[0].strType =  getParamStrType<P1>();
00206     pDesc.parameters[1].strType =  getParamStrType<P2>();
00207     pDesc.parameters[2].strType =  getParamStrType<P3>();
00208   }
00209 
00210   template <typename C, typename P1, typename P2, typename P3, typename P4, typename R>
00211   void completeAndCheck(R(C::*) (P1, P2, P3, P4), ALMethodInfo & pDesc)
00212   {
00213     pDesc.returnInfo.strType = getParamStrType<R>();
00214     ALMethodInfo::ALParameterInfo param;
00215     std::string name = "arg0";
00216     param.description = "arg";
00217     for (int i = pDesc.parameters.size(); i < 4; ++i) {
00218       name[3] = i + '1';
00219       param.name = name;
00220       pDesc.parameters.push_back(param);
00221     }
00222     pDesc.parameters[0].strType =  getParamStrType<P1>();
00223     pDesc.parameters[1].strType =  getParamStrType<P2>();
00224     pDesc.parameters[2].strType =  getParamStrType<P3>();
00225     pDesc.parameters[3].strType =  getParamStrType<P4>();
00226   }
00227 
00228   template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename R>
00229   void completeAndCheck(R(C::*) (P1, P2, P3, P4, P5), ALMethodInfo & pDesc)
00230   {
00231     pDesc.returnInfo.strType = getParamStrType<R>();
00232     ALMethodInfo::ALParameterInfo param;
00233     std::string name = "arg0";
00234     param.description = "arg";
00235     for (int i = pDesc.parameters.size(); i < 5; ++i) {
00236       name[3] = i + '1';
00237       param.name = name;
00238       pDesc.parameters.push_back(param);
00239     }
00240     pDesc.parameters[0].strType =  getParamStrType<P1>();
00241     pDesc.parameters[1].strType =  getParamStrType<P2>();
00242     pDesc.parameters[2].strType =  getParamStrType<P3>();
00243     pDesc.parameters[3].strType =  getParamStrType<P4>();
00244     pDesc.parameters[4].strType =  getParamStrType<P5>();
00245   }
00246 
00247   template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R>
00248   void completeAndCheck(R(C::*) (P1, P2, P3, P4, P5, P6), ALMethodInfo & pDesc)
00249   {
00250     pDesc.returnInfo.strType = getParamStrType<R>();
00251     ALMethodInfo::ALParameterInfo param;
00252     std::string name = "arg0";
00253     param.description = "arg";
00254     for (int i = pDesc.parameters.size(); i < 6; ++i) {
00255       name[3] = i + '1';
00256       param.name = name;
00257       pDesc.parameters.push_back(param);
00258     }
00259     pDesc.parameters[0].strType =  getParamStrType<P1>();
00260     pDesc.parameters[1].strType =  getParamStrType<P2>();
00261     pDesc.parameters[2].strType =  getParamStrType<P3>();
00262     pDesc.parameters[3].strType =  getParamStrType<P4>();
00263     pDesc.parameters[4].strType =  getParamStrType<P5>();
00264     pDesc.parameters[5].strType =  getParamStrType<P6>();
00265   }
00266 
00267 }
00268 #endif  // _LIBALCOMMON_ALCOMMON_ALMETHODINFO_H_
00269 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines