00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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