DataSourceStorage.hpp
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_TASK_DATASOURCE_STORAGE_HPP
00040 #define ORO_TASK_DATASOURCE_STORAGE_HPP
00041
00042 #include <boost/function.hpp>
00043 #include <boost/bind.hpp>
00044 #include <boost/mem_fn.hpp>
00045 #include "boost/function_types/function_type.hpp"
00046 #include "boost/function_types/function_type_arity.hpp"
00047 #include "CommandC.hpp"
00048
00049 namespace RTT
00050 {
00051 namespace detail
00052 {
00053
00054 template<class R>
00055 struct DataSourceResultStorage
00056 {
00057 typename ValueDataSource<R>::shared_ptr result;
00058
00059 DataSourceResultStorage()
00060 : result(new ValueDataSource<R>() )
00061 {
00062 }
00063
00064 template<class ContainerT>
00065 void initRet(ContainerT& cc) {
00066 cc.ret(DataSourceBase::shared_ptr(result));
00067 }
00068
00069 R getResult() {
00070 return result->get();
00071 }
00072 };
00073
00074 template<>
00075 struct DataSourceResultStorage<void>
00076 {
00077 DataSourceResultStorage()
00078 {
00079 }
00080
00081 template<class ContainerT>
00082 void initRet(ContainerT& ) {}
00083
00084 void getResult() {}
00085 };
00086
00089 template<class R>
00090 struct DataSourceResultStorage<R&>
00091 {
00092 typename ValueDataSource<R>::shared_ptr result;
00093
00094 DataSourceResultStorage()
00095 : result(new ValueDataSource<R>() )
00096 {
00097 }
00098
00099 template<class ContainerT>
00100 void initRet(ContainerT& cc) {
00101 cc.ret(DataSourceBase::shared_ptr(result));
00102 }
00103
00104 R getResult() {
00105 return result->get();
00106 }
00107 };
00108
00109
00110 template<class A>
00111 struct DataSourceArgStorage
00112 {
00113 typename ValueDataSource<A>::shared_ptr value;
00114 DataSourceArgStorage()
00115 : value(new ValueDataSource<A>() )
00116 {}
00117 };
00118
00121 template<class A>
00122 struct DataSourceArgStorage<A&>
00123 {
00124
00125 typename ValueDataSource<A>::shared_ptr value;
00126 DataSourceArgStorage()
00127 : value(new ValueDataSource<A>() )
00128 {}
00129 };
00130
00131 template<int, class T>
00132 struct DataSourceStorageImpl;
00133
00137 template<class DataType>
00138 struct DataSourceStorageImpl<0, DataType>
00139 : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
00140 {
00141 template<class ContainerT>
00142 void initArgs(ContainerT& ) {}
00143 };
00144
00148 template<class DataType>
00149 struct DataSourceStorageImpl<1, DataType>
00150 : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
00151 {
00152 typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
00153 DataSourceArgStorage<arg1_type> ma1;
00154
00155 template<class ContainerT>
00156 void initArgs(ContainerT& cc) {
00157 cc.arg( DataSourceBase::shared_ptr(ma1.value.get()) );
00158 }
00159
00160 void store(arg1_type a1) {
00161 ma1.value->set(a1);
00162 }
00163 };
00164
00165 template<class DataType>
00166 struct DataSourceStorageImpl<2, DataType>
00167 : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
00168 {
00169 typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
00170 typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
00171 DataSourceArgStorage<arg1_type> ma1;
00172 DataSourceArgStorage<arg2_type> ma2;
00173
00174 template<class ContainerT>
00175 void initArgs(ContainerT& cc) {
00176 cc.arg( DataSourceBase::shared_ptr(ma1.value) );
00177 cc.arg( DataSourceBase::shared_ptr(ma2.value) );
00178 }
00179 void store(arg1_type a1, arg2_type a2) {
00180 ma1.value->set(a1);
00181 ma2.value->set(a2);
00182 }
00183 };
00184
00185 template<class DataType>
00186 struct DataSourceStorageImpl<3, DataType>
00187 : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
00188 {
00189 typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
00190 typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
00191 typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
00192 DataSourceArgStorage<arg1_type> ma1;
00193 DataSourceArgStorage<arg2_type> ma2;
00194 DataSourceArgStorage<arg3_type> ma3;
00195
00196 template<class ContainerT>
00197 void initArgs(ContainerT& cc) {
00198 cc.arg( DataSourceBase::shared_ptr(ma1.value) );
00199 cc.arg( DataSourceBase::shared_ptr(ma2.value) );
00200 cc.arg( DataSourceBase::shared_ptr(ma3.value) );
00201 }
00202 void store(arg1_type a1, arg2_type a2, arg3_type a3) {
00203 ma1.value->set(a1);
00204 ma2.value->set(a2);
00205 ma3.value->set(a3);
00206 }
00207 };
00208
00209 template<class DataType>
00210 struct DataSourceStorageImpl<4, DataType>
00211 : public DataSourceResultStorage<typename boost::function_traits<DataType>::result_type>
00212 {
00213 typedef typename boost::function_traits<DataType>::arg1_type arg1_type;
00214 typedef typename boost::function_traits<DataType>::arg2_type arg2_type;
00215 typedef typename boost::function_traits<DataType>::arg3_type arg3_type;
00216 typedef typename boost::function_traits<DataType>::arg4_type arg4_type;
00217 DataSourceArgStorage<arg1_type> ma1;
00218 DataSourceArgStorage<arg2_type> ma2;
00219 DataSourceArgStorage<arg3_type> ma3;
00220 DataSourceArgStorage<arg4_type> ma4;
00221
00222 template<class ContainerT>
00223 void initArgs(ContainerT& cc) {
00224 cc.arg( DataSourceBase::shared_ptr(ma1.value) );
00225 cc.arg( DataSourceBase::shared_ptr(ma2.value) );
00226 cc.arg( DataSourceBase::shared_ptr(ma3.value) );
00227 cc.arg( DataSourceBase::shared_ptr(ma4.value) );
00228 }
00229 void store(arg1_type a1, arg2_type a2, arg3_type a3, arg4_type a4) {
00230 ma1.value->set(a1);
00231 ma2.value->set(a2);
00232 ma3.value->set(a3);
00233 ma4.value->set(a4);
00234 }
00235 };
00236
00237
00244 template<class DataType>
00245 struct DataSourceStorage
00246 : public DataSourceStorageImpl<boost::function_traits<DataType>::arity, DataType>
00247 {
00248 };
00249 }
00250 }
00251 #endif