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_EXECUTION_DATASOURCE_GENERATOR_HPP
00040 #define ORO_EXECUTION_DATASOURCE_GENERATOR_HPP
00041
00042 #include "DataSources.hpp"
00043 #include <boost/utility/enable_if.hpp>
00044 #include <boost/ref.hpp>
00045 #include <boost/type_traits/is_base_of.hpp>
00046 #include <boost/type_traits/remove_pointer.hpp>
00047
00048 namespace RTT
00049 {
00050 namespace internal
00051 {
00052 template<class T, class Enable = void >
00053 struct DSWrap {
00054 base::DataSourceBase::shared_ptr operator()(T t) { return new ConstantDataSource<T>( t );}
00055 };
00056
00057 template<class T>
00058 struct DSWrap<T, typename boost::enable_if< boost::is_base_of<base::DataSourceBase, typename boost::remove_pointer<T>::type > >::type > {
00059 base::DataSourceBase::shared_ptr operator()(T t) { return t; }
00060 };
00061
00062 template<class T>
00063 struct DSWrap<T, typename boost::enable_if< boost::is_reference<T> >::type > {
00064 base::DataSourceBase::shared_ptr operator()(T t) { return new ReferenceDataSource< typename boost::remove_reference<T>::type >( t ); }
00065 };
00066
00067 template<class T>
00068 struct DSWrap<T, typename boost::enable_if< boost::is_reference_wrapper<T> >::type > {
00069 typedef typename boost::unwrap_reference<T>::type RT;
00070 base::DataSourceBase::shared_ptr operator()(T t) { return new ReferenceDataSource< typename boost::remove_reference<RT>::type >( t ); }
00071 };
00072
00073 template<class T>
00074 struct DSWrap<boost::intrusive_ptr<T>, typename boost::enable_if< boost::is_base_of<base::DataSourceBase, typename boost::remove_pointer<T>::type > >::type >
00075 : public DSWrap<T> {
00076 };
00077
00078 using boost::ref;
00079
00095 struct GenerateDataSource
00096 {
00097 template<class A1>
00098 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1)
00099 {
00100 std::vector<base::DataSourceBase::shared_ptr> res;
00101 res.push_back( DSWrap<A1>()(a1));
00102 return res;
00103 }
00104
00105 template<class A1, class A2>
00106 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1, A2 a2 )
00107 {
00108 std::vector<base::DataSourceBase::shared_ptr> res = operator()(a1);
00109 res.push_back( DSWrap<A2>()(a2));
00110 return res;
00111 }
00112
00113 template<class A1, class A2, class A3>
00114 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1, A2 a2, A3 a3 )
00115 {
00116 std::vector<base::DataSourceBase::shared_ptr> res = operator()(a1,a2);
00117 res.push_back( DSWrap<A3>()(a3));
00118 return res;
00119 }
00120
00121 template<class A1, class A2, class A3, class A4>
00122 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1, A2 a2, A3 a3, A4 a4 )
00123 {
00124 std::vector<base::DataSourceBase::shared_ptr> res = operator()(a1,a2,a3);
00125 res.push_back( DSWrap<A4>()(a4));
00126 return res;
00127 }
00128
00129 template<class A1, class A2, class A3, class A4, class A5, class A6>
00130 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6 )
00131 {
00132 std::vector<base::DataSourceBase::shared_ptr> res = operator()(a1,a2,a3,a4,a5);
00133 res.push_back( DSWrap<A6>()(a6));
00134 return res;
00135 }
00136
00137 template<class A1, class A2, class A3, class A4, class A5, class A6, class A7>
00138 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7 )
00139 {
00140 std::vector<base::DataSourceBase::shared_ptr> res = operator()(a1,a2,a3,a4,a5,a6);
00141 res.push_back( DSWrap<A7>()(a7));
00142 return res;
00143 }
00144
00145 template<class A1, class A2, class A3, class A4, class A5>
00146 std::vector<base::DataSourceBase::shared_ptr> operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5 )
00147 {
00148 std::vector<base::DataSourceBase::shared_ptr> res = operator()(a1,a2,a3,a4);
00149 res.push_back( DSWrap<A5>()(a5));
00150 return res;
00151 }
00152 };
00153 }}
00154
00155 #endif