Robobo
MethodRequest.h
1 #ifndef METHOD_REQUEST_INCLUDED
2 #define METHOD_REQUEST_INCLUDED
3 
4 #include <tuple>
5 
7 {
8  public:
9  bool persistent;
10  MethodRequestBase(): persistent(0) { }
11  virtual void execute();
12 };
13 
14 template<int ...> struct seq {};
15 template<int N, int ...S> struct gens : gens<N-1, N-1, S...> {};
16 template<int ...S> struct gens<0, S...>{ typedef seq<S...> type; };
17 
18 template <class AO, typename ...Args>
20 {
21  public:
22  std::tuple<Args...> params;
23  void (AO::*method_to_call)(Args...) ;
24  AO &object;
25 
26  MethodRequest(AO &o, void (AO::*method)(Args...), Args... x):
27  params(x...),
28  object(o),
29  method_to_call(method)
30  {
31  }
32 
33  void execute()
34  {
35  callFunc(typename gens<sizeof...(Args)>::type());
36  }
37 
38  template<int ...S>
39  void callFunc(seq<S...>)
40  {
41  (object.*method_to_call)(std::get<S>(params) ...);
42  }
43 
44 };
45 
46 #define MR1(classtype,object,funct,argtype,argval) new MethodRequest<classtype, argtype>( object, & classtype::funct, argval)
47 
48 #define MR0(classtype,object,funct) new MethodRequest<classtype >( object, & classtype::funct )
49 
50 #endif
Definition: MethodRequest.h:15
Definition: MethodRequest.h:6
Definition: MethodRequest.h:14
Definition: MethodRequest.h:19