Signal.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Wed Jan 18 14:11:38 CET 2006  Signal.hpp
00003 
00004                         Signal.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_CORELIB_SIGNAL_HPP
00040 #define ORO_CORELIB_SIGNAL_HPP
00041 
00042 #define OROCOS_SIGNAL_MAX_ARGS 4
00043 
00044 #include <boost/type_traits/function_traits.hpp>
00045 #include <boost/function.hpp>
00046 #include "Handle.hpp"
00047 #include "impl/signal0.hpp"
00048 #include "impl/signal1.hpp"
00049 #include "impl/signal2.hpp"
00050 #include "impl/signal3.hpp"
00051 #include "impl/signal4.hpp"
00052 
00053 namespace RTT {
00054     namespace detail {
00055       template<int Arity,
00056                typename Signature,
00057                typename SlotFunction>
00058       class real_get_signal_impl;
00059 
00060       template<typename Signature,
00061                typename SlotFunction>
00062       class real_get_signal_impl<0, Signature,
00063                                  SlotFunction>
00064       {
00065         typedef boost::function_traits<Signature> traits;
00066 
00067       public:
00068         typedef signal0<typename traits::result_type,
00069                         SlotFunction> type;
00070       };
00071 
00072       template<typename Signature,
00073                typename SlotFunction>
00074       class real_get_signal_impl<1, Signature,
00075                                  SlotFunction>
00076       {
00077         typedef boost::function_traits<Signature> traits;
00078 
00079       public:
00080         typedef signal1<typename traits::result_type,
00081                         typename traits::arg1_type,
00082                         SlotFunction> type;
00083       };
00084 
00085       template<typename Signature,
00086                typename SlotFunction>
00087       class real_get_signal_impl<2, Signature,
00088                                  SlotFunction>
00089       {
00090         typedef boost::function_traits<Signature> traits;
00091 
00092       public:
00093         typedef signal2<typename traits::result_type,
00094                         typename traits::arg1_type,
00095                         typename traits::arg2_type,
00096                         SlotFunction> type;
00097       };
00098 
00099       template<typename Signature,
00100                typename SlotFunction>
00101       class real_get_signal_impl<3, Signature,
00102                                  SlotFunction>
00103       {
00104         typedef boost::function_traits<Signature> traits;
00105 
00106       public:
00107         typedef signal3<typename traits::result_type,
00108                         typename traits::arg1_type,
00109                         typename traits::arg2_type,
00110                         typename traits::arg3_type,
00111                         SlotFunction> type;
00112       };
00113 
00114       template<typename Signature,
00115                typename SlotFunction>
00116       class real_get_signal_impl<4, Signature,
00117                                  SlotFunction>
00118       {
00119         typedef boost::function_traits<Signature> traits;
00120 
00121       public:
00122         typedef signal4<typename traits::result_type,
00123                         typename traits::arg1_type,
00124                         typename traits::arg2_type,
00125                         typename traits::arg3_type,
00126                         typename traits::arg4_type,
00127                         SlotFunction> type;
00128       };
00129 
00130       template<typename Signature,
00131                typename SlotFunction>
00132       struct get_signal_impl :
00133         public real_get_signal_impl<(boost::function_traits<Signature>::arity),
00134                                     Signature,
00135                                     SlotFunction>
00136       {
00137       };
00138 
00144     template<
00145         typename Signature, // function type R (T1, T2, ..., TN)
00146         typename SlotFunction = boost::function<Signature>
00147     >
00148     class signal :
00149         public detail::get_signal_impl<Signature,
00150                                        SlotFunction>::type
00151     {
00152     protected:
00153         typedef typename detail::get_signal_impl< Signature,
00154                                                   SlotFunction>::type base_type;
00155 
00156     public:
00157         signal() {}
00158     };
00159 
00160     } // end namespace detail
00161 
00162 } // namespace RTT
00163 
00164 
00165 #endif
00166 
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3