LocalMethod.hpp

00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:05 CET 2006  LocalMethod.hpp
00003 
00004                         LocalMethod.hpp -  description
00005                            -------------------
00006     begin                : do november 02 2006
00007     copyright            : (C) 2006 FMTC
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 #ifndef ORO_LOCAL_METHOD_HPP
00040 #define ORO_LOCAL_METHOD_HPP
00041 
00042 #include <boost/function.hpp>
00043 #include <string>
00044 #include "Invoker.hpp"
00045 #include "MethodBase.hpp"
00046 #include "BindStorage.hpp"
00047 
00048 namespace RTT
00049 {
00050     namespace detail
00051     {
00052         template<class FunctionT>
00053         class LocalMethodImpl
00054             : public MethodBase<FunctionT>
00055         {
00056         protected:
00057             boost::function<FunctionT> mmeth;
00058         public:
00059             typedef FunctionT Signature;
00060             typedef typename boost::function_traits<Signature>::result_type result_type;
00061             typedef boost::function_traits<Signature> traits;
00062 
00063             void readArguments() {}
00064 
00065             bool execute() {
00066                 return false;
00067             }
00068 
00072             result_type invoke()
00073             {
00074                 return mmeth();
00075             }
00076 
00080             template<class T1>
00081             result_type invoke(T1 t)
00082             {
00083                 return mmeth(t);
00084             }
00085 
00089             template<class T1, class T2>
00090             result_type invoke(T1 t1, T2 t2)
00091             {
00092                 return mmeth(t1, t2);
00093             }
00094 
00098             template<class T1, class T2, class T3>
00099             result_type invoke(T1 t1, T2 t2, T3 t3)
00100             {
00101                 return mmeth(t1, t2, t3);
00102             }
00103 
00107             template<class T1, class T2, class T3, class T4>
00108             result_type invoke(T1 t1, T2 t2, T3 t3, T4 t4)
00109             {
00110                 return mmeth(t1, t2, t3, t4);
00111             }
00112 
00113         };
00114 
00124         template<class FunctionT>
00125         struct LocalMethod
00126             : public Invoker<FunctionT,LocalMethodImpl<FunctionT> >
00127         {
00128             typedef FunctionT Signature;
00129             typedef typename boost::function_traits<Signature>::result_type result_type;
00130             typedef boost::function_traits<Signature> traits;
00131 
00137             LocalMethod()
00138             {}
00139 
00148             template<class M, class ObjectType>
00149             LocalMethod(M meth, ObjectType object)
00150             {
00151                 this->mmeth = detail::MethodBinder<Signature>()(meth, object);
00152             }
00153 
00160             template<class M>
00161             LocalMethod(M meth)
00162             {
00163                 this->mmeth = meth;
00164             }
00165 
00166             boost::function<Signature> getMethodFunction() const
00167             {
00168                 return this->mmeth;
00169             }
00170 
00171             ActionInterface* clone() const
00172             {
00173                 return new LocalMethod<Signature>(*this);
00174             }
00175 
00176             MethodBase<Signature>* cloneI() const
00177             {
00178                 return new LocalMethod<Signature>(*this);
00179             }
00180         };
00181     }
00182 }
00183 
00184 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3