Orocos Real-Time Toolkit  2.5.0
DataSourceGenerator.hpp
00001 /***************************************************************************
00002   tag: Peter Soetens  Wed Jan 18 14:11:40 CET 2006  DataSourceGenerator.hpp
00003 
00004                         DataSourceGenerator.hpp -  description
00005                            -------------------
00006     begin                : Wed January 18 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.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_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         }; // normal type
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         }; // datasource type
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         }; // reference type
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         }; // reference type
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         }; // datasource shared_ptr type
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