libalcommon  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alfunctor.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALCOMMON_ALCOMMON_ALFUNCTOR_H_
12 #define _LIBALCOMMON_ALCOMMON_ALFUNCTOR_H_
13 
14 # include <alcommon/api.h>
15 # include <alvalue/alvalue.h>
16 # include <boost/shared_ptr.hpp>
17 # include <qi/anyobject.hpp>
18 # include <sstream>
19 
21 namespace AL
22 {
28  typedef void ALVoid;
29 
36  {
37  public:
39  {
40  }
41 
42  ALFunctorBase(qi::AnyFunction metaFun)
43  : _functor(metaFun)
44  {
45  }
46 
47  void reset(){
48  _functor = qi::AnyFunction();
49  }
50 
51  qi::AnyFunction genericFunction() {
52  return _functor;
53  }
54 
55  qi::Signature signature() const
56  {
57  //drop the first arg
58  return _functor.parametersSignature(true);
59  }
60 
61  qi::Signature sigreturn() const
62  {
63  return _functor.returnSignature();
64  }
65 
71  virtual void call(const ALValue& pParams, ALValue& pResult) {
72  qiLogError("alcommon.ALFunctor") << "ALFunctor::call not implemented";
73  //TODO: NOT IMPLEMENTED
74  };
75 
77  virtual ~ALFunctorBase() {
78  //delete _functor;
79  }
80 
81  qi::AnyFunction _functor;
82  };
83 
84 }
85 
86 namespace AL {
87 
88  template<typename C, typename F>
89  boost::shared_ptr<ALFunctorBase> createFunctor(C* obj, F fun)
90  {
91  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(
92  qi::AnyFunction::from(fun, obj).dropFirstArgument()));
93  }
94  template <typename C, typename R>
95  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) ()) {
96  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
97  }
98 
99  template <typename C, typename P1, typename R>
100  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &)) {
101  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
102  }
103 
104  template <typename C, typename P1, typename P2, typename R>
105  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &)) {
106  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
107  }
108 
109  template <typename C, typename P1, typename P2, typename P3, typename R>
110  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3 &)) {
111  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
112  }
113 
114  template <typename C, typename P1, typename P2, typename P3, typename P4, typename R>
115  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3 &, const P4 &)) {
116  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
117  }
118 
119  template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename R>
120  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3 &, const P4 &, const P5 &)) {
121  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
122  }
123 
124  template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R>
125  boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3 &, const P4 &, const P5 &, const P6 &)) {
126  return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
127  }
128 
129 }
130 
131 #endif // _LIBALCOMMON_ALCOMMON_ALFUNCTOR_H_
virtual void call(const ALValue &pParams, ALValue &pResult)
Generic call to a bound module's method.
Definition: alfunctor.h:71
boost::shared_ptr< ALFunctorBase > createFunctor(C *obj, F fun)
Definition: alfunctor.h:89
qi::AnyFunction _functor
Definition: alfunctor.h:81
ALFunctorBase(qi::AnyFunction metaFun)
Definition: alfunctor.h:42
void ALVoid
Type def to void.
Definition: alfunctor.h:28
qi::Signature signature() const
Definition: alfunctor.h:55
qi::AnyFunction genericFunction()
Definition: alfunctor.h:51
ALFunctorBase is a generic functor class for pointer management.
Definition: alfunctor.h:35
#define ALCOMMON_API
Definition: api.h:14
qi::Signature sigreturn() const
Definition: alfunctor.h:61
virtual ~ALFunctorBase()
Destructor.
Definition: alfunctor.h:77