DataSourceArgsMethod.hpp

00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:04 CET 2006  DataSourceArgsMethod.hpp
00003 
00004                         DataSourceArgsMethod.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_DATASOURCE_ARGS_METHOD_HPP
00040 #define ORO_DATASOURCE_ARGS_METHOD_HPP
00041 
00042 #include "DataSource.hpp"
00043 #include "FunctorDataSource.hpp"
00044 #include <boost/function.hpp>
00045 
00046 namespace RTT
00047 {
00048     namespace detail
00049     {
00054         template<class SignatureT, class FunctorT = detail::FunctorDataSource<boost::function<SignatureT> > >
00055         class DataSourceArgsMethod
00056             : public DataSource< typename boost::function_traits<SignatureT>::result_type >
00057         {
00058             typename FunctorT::shared_ptr mmeth;
00059         public:
00060             typedef boost::function_traits<SignatureT> traits;
00061             typedef SignatureT Signature;
00062 
00063             typedef typename boost::function_traits<Signature>::result_type result_type;
00064             typedef DataSource<result_type> Base;
00065 
00066             DataSourceArgsMethod(boost::function<Signature> meth)
00067                 : mmeth( new FunctorT(meth) )
00068             {
00069             }
00070 
00071             DataSourceArgsMethod( typename FunctorT::shared_ptr ds)
00072                 : mmeth( ds )
00073             {
00074             }
00075 
00076             DataSourceArgsMethod<Signature,FunctorT>* create() const
00077             {
00078                 return clone();
00079             }
00080 
00081             template<class Arg1T>
00082             DataSourceArgsMethod<Signature,FunctorT>* create(DataSource<Arg1T>* a1) const
00083             {
00084                 DataSourceArgsMethod<Signature,FunctorT>* r =  this->clone();
00085                 r->mmeth->setArguments(a1);
00086                 return r;
00087             }
00088 
00089             template<class Arg1T, class Arg2T>
00090             DataSourceArgsMethod<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2) const
00091             {
00092                 DataSourceArgsMethod<Signature,FunctorT>* r =  this->clone();
00093                 r->mmeth->setArguments(a1, a2);
00094                 return r;
00095             }
00096 
00097             template<class Arg1T, class Arg2T, class Arg3T>
00098             DataSourceArgsMethod<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3) const
00099             {
00100                 DataSourceArgsMethod<Signature,FunctorT>* r =  this->clone();
00101                 r->mmeth->setArguments(a1, a2, a3);
00102                 return r;
00103             }
00104 
00105             template<class Arg1T, class Arg2T, class Arg3T, class Arg4T>
00106             DataSourceArgsMethod<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4) const
00107             {
00108                 DataSourceArgsMethod<Signature,FunctorT>* r =  this->clone();
00109                 r->mmeth->setArguments(a1, a2, a3, a4);
00110                 return r;
00111             }
00112 
00113             template<class Arg1T, class Arg2T, class Arg3T, class Arg4T, class Arg5T>
00114             DataSourceArgsMethod<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4, DataSource<Arg5T>* a5) const
00115             {
00116                 DataSourceArgsMethod<Signature,FunctorT>* r =  this->clone();
00117                 r->mmeth->setArguments(a1, a2, a3, a4, a5);
00118                 return r;
00119             }
00120 
00121             template<class Arg1T, class Arg2T, class Arg3T, class Arg4T, class Arg5T, class Arg6T>
00122             DataSourceArgsMethod<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4, DataSource<Arg5T>* a5, DataSource<Arg6T>* a6) const
00123             {
00124                 DataSourceArgsMethod<Signature,FunctorT>* r =  this->clone();
00125                 r->mmeth->setArguments(a1, a2, a3, a4, a5, a6);
00126                 return r;
00127             }
00128 
00129 
00130             result_type operator()() {
00131                 return mmeth->get();
00132             }
00133 
00134             virtual result_type get() const {
00135                 return mmeth->get();
00136             }
00137 
00138             virtual result_type value() const {
00139                 return mmeth->value();
00140             }
00141 
00142             virtual DataSourceArgsMethod<Signature,FunctorT>* clone() const {
00143                 return new DataSourceArgsMethod( typename FunctorT::shared_ptr(mmeth->clone()) );
00144             }
00145 
00146             virtual DataSource<result_type>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const
00147             {
00148                 return new DataSourceArgsMethod<Signature,FunctorT>( typename FunctorT::shared_ptr(mmeth->copy(alreadyCloned)) );
00149             }
00150 
00151             boost::function<Signature> getMethodFunction() const {
00152                 return mmeth.ff.gen;
00153             }
00154         };
00155     }
00156 }
00157 
00158 
00159 #endif
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3