libalcommon  2.0.6.8
/home/opennao/work/master/sdk/libnaoqi/libalcommon/alcommon/alfunctor.h
Go to the documentation of this file.
00001 
00010 #pragma once
00011 #ifndef _LIBALCOMMON_ALCOMMON_ALFUNCTOR_H_
00012 #define _LIBALCOMMON_ALCOMMON_ALFUNCTOR_H_
00013 
00014 # include <alcommon/api.h>
00015 # include <alvalue/alvalue.h>
00016 # include <boost/shared_ptr.hpp>
00017 # include <qitype/anyobject.hpp>
00018 # include <sstream>
00019 
00021 namespace AL
00022 {
00028   typedef void ALVoid;
00029 
00035   class ALFunctorBase
00036   {
00037   public:
00038     ALFunctorBase()
00039     {
00040     }
00041 
00042     ALFunctorBase(qi::AnyFunction metaFun)
00043       : _functor(metaFun)
00044     {
00045     }
00046 
00047     void reset(){
00048       _functor = qi::AnyFunction();
00049     }
00050 
00051     qi::AnyFunction genericFunction() {
00052       return _functor;
00053     }
00054 
00055     qi::Signature signature() const
00056     {
00057       //drop the first arg
00058       return _functor.parametersSignature(true);
00059     }
00060 
00061     qi::Signature sigreturn() const
00062     {
00063       return _functor.returnSignature();
00064     }
00065 
00071     virtual void call(const ALValue& pParams, ALValue& pResult) {
00072       qiLogError("alcommon.ALFunctor") << "ALFunctor::call not implemented";
00073       //TODO: NOT IMPLEMENTED
00074     };
00075 
00077     virtual ~ALFunctorBase() {
00078       //delete _functor;
00079     }
00080 
00081     qi::AnyFunction _functor;
00082   };
00083 
00084 }
00085 
00086 namespace AL {
00087 
00088   template<typename C, typename F>
00089   boost::shared_ptr<ALFunctorBase> createFunctor(C* obj, F fun)
00090   {
00091      return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(
00092        qi::AnyFunction::from(fun, obj).dropFirstArgument()));
00093   }
00094   template <typename C, typename R>
00095   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) ()) {
00096     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00097    }
00098 
00099   template <typename C, typename P1, typename R>
00100   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &)) {
00101     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00102   }
00103 
00104   template <typename C, typename P1, typename P2, typename R>
00105   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &)) {
00106     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00107   }
00108 
00109   template <typename C, typename P1, typename P2, typename P3, typename R>
00110   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const  P3 &)) {
00111     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00112   }
00113 
00114   template <typename C, typename P1, typename P2, typename P3, typename P4, typename R>
00115   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3 &, const P4 &)) {
00116     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00117   }
00118 
00119   template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename R>
00120   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3 &, const P4 &, const P5 &)) {
00121     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00122   }
00123 
00124   template <typename C, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R>
00125   boost::shared_ptr<ALFunctorBase> createFunctor(C *obj, R (C::*f) (const P1 &, const P2 &, const P3  &, const P4 &, const P5 &, const P6 &)) {
00126     return boost::shared_ptr<ALFunctorBase>(new ALFunctorBase(qi::AnyFunction::from(f, obj).dropFirstArgument()));
00127   }
00128 
00129 }
00130 
00131 #endif  // _LIBALCOMMON_ALCOMMON_ALFUNCTOR_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines