DataSourceArgsEvent.hpp

00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:05 CET 2006  DataSourceArgsEvent.hpp
00003 
00004                         DataSourceArgsEvent.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_EVENT_HPP
00040 #define ORO_DATASOURCE_ARGS_EVENT_HPP
00041 
00042 #include "DataSource.hpp"
00043 #include "LocalEvent.hpp"
00044 #include "FunctorDataSource.hpp"
00045 
00046 namespace RTT
00047 {
00048     namespace detail
00049     {
00054         template<class SignatureT, class FunctorT = detail::FunctorDataSource<boost::function<SignatureT> > >
00055         class DataSourceArgsEvent
00056             : public ActionInterface
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 ActionInterface Base;
00065 
00066             DataSourceArgsEvent(boost::function<Signature> meth)
00067                 : mmeth( new FunctorT(meth) )
00068             {
00069             }
00070 
00071             DataSourceArgsEvent( typename FunctorT::shared_ptr ds)
00072                 : mmeth( ds )
00073             {
00074             }
00075 
00076             DataSourceArgsEvent<Signature,FunctorT>* create() const
00077             {
00078                 return clone();
00079             }
00080 
00081             template<class Arg1T>
00082             DataSourceArgsEvent<Signature,FunctorT>* create(DataSource<Arg1T>* a1) const
00083             {
00084                 DataSourceArgsEvent<Signature,FunctorT>* r =  this->clone();
00085                 r->mmeth->setArguments(a1);
00086                 return r;
00087             }
00088 
00089             template<class Arg1T, class Arg2T>
00090             DataSourceArgsEvent<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2) const
00091             {
00092                 DataSourceArgsEvent<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             DataSourceArgsEvent<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3) const
00099             {
00100                 DataSourceArgsEvent<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             DataSourceArgsEvent<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4) const
00107             {
00108                 DataSourceArgsEvent<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             DataSourceArgsEvent<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4, DataSource<Arg5T>* a5) const
00115             {
00116                 DataSourceArgsEvent<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             DataSourceArgsEvent<Signature,FunctorT>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4, DataSource<Arg5T>* a5, DataSource<Arg6T>* a6) const
00123             {
00124                 DataSourceArgsEvent<Signature,FunctorT>* r =  this->clone();
00125                 r->mmeth->setArguments(a1, a2, a3, a4, a5, a6);
00126                 return r;
00127             }
00128 
00129 
00130             bool execute() {
00131                 mmeth->get();
00132                 return true;
00133             }
00134 
00135             void readArguments() {
00136                 // the arguments are read in mmeth.get() above.
00137             }
00138 
00139             virtual DataSourceArgsEvent<Signature,FunctorT>* clone() const {
00140                 return new DataSourceArgsEvent( typename FunctorT::shared_ptr(mmeth->clone()) );
00141             }
00142 
00143             virtual ActionInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const
00144             {
00145                 return new DataSourceArgsEvent<Signature,FunctorT>( typename FunctorT::shared_ptr(mmeth->copy(alreadyCloned)) );
00146             }
00147 
00148             boost::function<Signature> getEventFunction() const {
00149                 return mmeth.ff.gen;
00150             }
00151         };
00152     }
00153 }
00154 
00155 
00156 #endif
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3