libalcommon  1.14
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
almethodinfo.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALCOMMON_ALCOMMON_ALMETHODINFO_H_
12 #define _LIBALCOMMON_ALCOMMON_ALMETHODINFO_H_
13 
14 # include <alcommon/alparamtype.h>
15 # include <boost/shared_ptr.hpp>
16 
17 
18 # define BLOCKINGFUNCTION 0
19 # define ASYNCHRONOUSFUNCTION 1
21 namespace AL
22 {
23  class ALFunctorBase;
24 
34  {
35  public:
38  mask = 0;
39  }
40 
42  virtual ~ALMethodInfo() {}
43 
48  enum methodOption {
49  CPPMethod = 1,
50  AsynchronousMethod = 2,
51  localMethod = 4
52  };
53 
59  {
60  public:
61  std::string paramError;
62  std::string name;
63  std::string description;
64  std::string strType;
65  bool optional;
66  };
67 
72  template <typename T>
74  public:
79  ALParameterInfoOptional(T defaultValue) {
80  m_defaultValue = defaultValue;
81  }
83  };
84 
89  class ALExample {
90  public:
91  std::string language;
92  std::string strExample;
93  };
94 
95  std::string moduleName;
96  std::string methodName;
97  std::string methodDescription;
98  std::vector<ALParameterInfo> parameters;
99  std::string returnValue;
100  std::vector<ALExample> examples;
101  boost::shared_ptr<ALFunctorBase> ptrOnMethod;
103  short mask;
110  bool isCpp(void) {
111  return ((mask & CPPMethod) == CPPMethod);
112  }
113 
118  bool isAsynchronous(void) {
119  return (mask & AsynchronousMethod) > 0 ? true: false;
120  }
121 
126  bool isLocalMethod(void) {
127  return ((mask & localMethod) == localMethod);
128  }
129 
134  void addOption(int pOption)
135  {
136  mask = mask | (short)pOption;
137  }
138 
144  return ptrOnMethod.get();
145  }
146 
150  void clear(void) {
151  parameters.clear();
152  examples.clear();
153  }
154  };
155 
156  template <typename C, typename R>
157  void completeAndCheck(R(C::*) (), ALMethodInfo & pDesc)
158  {
159  pDesc.returnInfo.strType = getParamStrType<R>();
160  }
161 
162  template <typename C, typename P1, typename R>
163  void completeAndCheck(R(C::*) (P1), ALMethodInfo & pDesc)
164  {
165  pDesc.returnInfo.strType = getParamStrType<R>();
166  ALMethodInfo::ALParameterInfo param;
167  param.description = "arg";
168  std::string name = "arg0";
169  for (int i = pDesc.parameters.size(); i < 1; ++i) {
170  name[3] = (char) (i + '1');
171  param.name = name;
172  pDesc.parameters.push_back(param);
173  }
174  pDesc.parameters[0].strType = getParamStrType<P1>();
175  }
176 
177  template <typename C, typename P1, typename P2, typename R>
178  void completeAndCheck(R(C::*) (P1, P2), ALMethodInfo & pDesc)
179  {
180  pDesc.returnInfo.strType = getParamStrType<R>();
181  ALMethodInfo::ALParameterInfo param;
182  std::string name = "arg0";
183  param.description = "arg";
184  for (int i = pDesc.parameters.size() ; i < 2; ++i) {
185  name[3] = (char) (i + '1');
186  param.name = name;
187  pDesc.parameters.push_back(param);
188  }
189  pDesc.parameters[0].strType = getParamStrType<P1>();
190  pDesc.parameters[1].strType = getParamStrType<P2>();
191  }
192 
193  template <typename C, typename P1, typename P2, typename P3, typename R>
194  void completeAndCheck(R(C::*) (P1, P2, P3), ALMethodInfo & pDesc)
195  {
196  pDesc.returnInfo.strType = getParamStrType<R>();
197  ALMethodInfo::ALParameterInfo param;
198  std::string name = "arg0";
199  param.description = "arg";
200  for (int i = pDesc.parameters.size(); i < 3; ++i) {
201  name[3] = i + '1';
202  param.name = name;
203  pDesc.parameters.push_back(param);
204  }
205  pDesc.parameters[0].strType = getParamStrType<P1>();
206  pDesc.parameters[1].strType = getParamStrType<P2>();
207  pDesc.parameters[2].strType = getParamStrType<P3>();
208  }
209 
210  template <typename C, typename P1, typename P2, typename P3, typename P4, typename R>
211  void completeAndCheck(R(C::*) (P1, P2, P3, P4), ALMethodInfo & pDesc)
212  {
213  pDesc.returnInfo.strType = getParamStrType<R>();
214  ALMethodInfo::ALParameterInfo param;
215  std::string name = "arg0";
216  param.description = "arg";
217  for (int i = pDesc.parameters.size(); i < 4; ++i) {
218  name[3] = i + '1';
219  param.name = name;
220  pDesc.parameters.push_back(param);
221  }
222  pDesc.parameters[0].strType = getParamStrType<P1>();
223  pDesc.parameters[1].strType = getParamStrType<P2>();
224  pDesc.parameters[2].strType = getParamStrType<P3>();
225  pDesc.parameters[3].strType = getParamStrType<P4>();
226  }
227 
228  template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename R>
229  void completeAndCheck(R(C::*) (P1, P2, P3, P4, P5), ALMethodInfo & pDesc)
230  {
231  pDesc.returnInfo.strType = getParamStrType<R>();
232  ALMethodInfo::ALParameterInfo param;
233  std::string name = "arg0";
234  param.description = "arg";
235  for (int i = pDesc.parameters.size(); i < 5; ++i) {
236  name[3] = i + '1';
237  param.name = name;
238  pDesc.parameters.push_back(param);
239  }
240  pDesc.parameters[0].strType = getParamStrType<P1>();
241  pDesc.parameters[1].strType = getParamStrType<P2>();
242  pDesc.parameters[2].strType = getParamStrType<P3>();
243  pDesc.parameters[3].strType = getParamStrType<P4>();
244  pDesc.parameters[4].strType = getParamStrType<P5>();
245  }
246 
247  template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R>
248  void completeAndCheck(R(C::*) (P1, P2, P3, P4, P5, P6), ALMethodInfo & pDesc)
249  {
250  pDesc.returnInfo.strType = getParamStrType<R>();
251  ALMethodInfo::ALParameterInfo param;
252  std::string name = "arg0";
253  param.description = "arg";
254  for (int i = pDesc.parameters.size(); i < 6; ++i) {
255  name[3] = i + '1';
256  param.name = name;
257  pDesc.parameters.push_back(param);
258  }
259  pDesc.parameters[0].strType = getParamStrType<P1>();
260  pDesc.parameters[1].strType = getParamStrType<P2>();
261  pDesc.parameters[2].strType = getParamStrType<P3>();
262  pDesc.parameters[3].strType = getParamStrType<P4>();
263  pDesc.parameters[4].strType = getParamStrType<P5>();
264  pDesc.parameters[5].strType = getParamStrType<P6>();
265  }
266 
267 }
268 #endif // _LIBALCOMMON_ALCOMMON_ALMETHODINFO_H_
269