Orocos Real-Time Toolkit
2.5.0
|
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 "signal0.hpp" 00048 #include "signal1.hpp" 00049 #include "signal2.hpp" 00050 #include "signal3.hpp" 00051 #include "signal4.hpp" 00052 #include "signal5.hpp" 00053 #include "signal6.hpp" 00054 #include "signal7.hpp" 00055 00056 namespace RTT { 00057 namespace internal { 00058 template<int Arity, 00059 typename Signature, 00060 typename SlotFunction> 00061 class real_get_signal_impl; 00062 00063 template<typename Signature, 00064 typename SlotFunction> 00065 class real_get_signal_impl<0, Signature, 00066 SlotFunction> 00067 { 00068 typedef boost::function_traits<Signature> traits; 00069 00070 public: 00071 typedef signal0<typename traits::result_type, 00072 SlotFunction> type; 00073 }; 00074 00075 template<typename Signature, 00076 typename SlotFunction> 00077 class real_get_signal_impl<1, Signature, 00078 SlotFunction> 00079 { 00080 typedef boost::function_traits<Signature> traits; 00081 00082 public: 00083 typedef signal1<typename traits::result_type, 00084 typename traits::arg1_type, 00085 SlotFunction> type; 00086 }; 00087 00088 template<typename Signature, 00089 typename SlotFunction> 00090 class real_get_signal_impl<2, Signature, 00091 SlotFunction> 00092 { 00093 typedef boost::function_traits<Signature> traits; 00094 00095 public: 00096 typedef signal2<typename traits::result_type, 00097 typename traits::arg1_type, 00098 typename traits::arg2_type, 00099 SlotFunction> type; 00100 }; 00101 00102 template<typename Signature, 00103 typename SlotFunction> 00104 class real_get_signal_impl<3, Signature, 00105 SlotFunction> 00106 { 00107 typedef boost::function_traits<Signature> traits; 00108 00109 public: 00110 typedef signal3<typename traits::result_type, 00111 typename traits::arg1_type, 00112 typename traits::arg2_type, 00113 typename traits::arg3_type, 00114 SlotFunction> type; 00115 }; 00116 00117 template<typename Signature, 00118 typename SlotFunction> 00119 class real_get_signal_impl<4, Signature, 00120 SlotFunction> 00121 { 00122 typedef boost::function_traits<Signature> traits; 00123 00124 public: 00125 typedef signal4<typename traits::result_type, 00126 typename traits::arg1_type, 00127 typename traits::arg2_type, 00128 typename traits::arg3_type, 00129 typename traits::arg4_type, 00130 SlotFunction> type; 00131 }; 00132 00133 template<typename Signature, 00134 typename SlotFunction> 00135 class real_get_signal_impl<5, Signature, 00136 SlotFunction> 00137 { 00138 typedef boost::function_traits<Signature> traits; 00139 00140 public: 00141 typedef signal5<typename traits::result_type, 00142 typename traits::arg1_type, 00143 typename traits::arg2_type, 00144 typename traits::arg3_type, 00145 typename traits::arg4_type, 00146 typename traits::arg5_type, 00147 SlotFunction> type; 00148 }; 00149 00150 template<typename Signature, 00151 typename SlotFunction> 00152 class real_get_signal_impl<6, Signature, 00153 SlotFunction> 00154 { 00155 typedef boost::function_traits<Signature> traits; 00156 00157 public: 00158 typedef signal6<typename traits::result_type, 00159 typename traits::arg1_type, 00160 typename traits::arg2_type, 00161 typename traits::arg3_type, 00162 typename traits::arg4_type, 00163 typename traits::arg5_type, 00164 typename traits::arg6_type, 00165 SlotFunction> type; 00166 }; 00167 00168 template<typename Signature, 00169 typename SlotFunction> 00170 class real_get_signal_impl<7, Signature, 00171 SlotFunction> 00172 { 00173 typedef boost::function_traits<Signature> traits; 00174 00175 public: 00176 typedef signal7<typename traits::result_type, 00177 typename traits::arg1_type, 00178 typename traits::arg2_type, 00179 typename traits::arg3_type, 00180 typename traits::arg4_type, 00181 typename traits::arg5_type, 00182 typename traits::arg6_type, 00183 typename traits::arg7_type, 00184 SlotFunction> type; 00185 }; 00186 00187 00188 template<typename Signature, 00189 typename SlotFunction> 00190 struct get_signal_impl : 00191 public real_get_signal_impl<(boost::function_traits<Signature>::arity), 00192 Signature, 00193 SlotFunction> 00194 { 00195 }; 00196 00202 template< 00203 typename Signature, 00204 typename TSlotFunction = boost::function<Signature> 00205 > 00206 class Signal : 00207 public get_signal_impl<Signature, 00208 TSlotFunction>::type 00209 { 00210 protected: 00211 typedef typename get_signal_impl< Signature, 00212 TSlotFunction>::type base_type; 00213 00214 public: 00215 typedef boost::shared_ptr<Signal<Signature,TSlotFunction> > shared_ptr; 00216 Signal() {} 00217 typedef TSlotFunction SlotFunction; 00218 }; 00219 00220 } // end namespace detail 00221 00222 } // namespace RTT 00223 00224 00225 #endif 00226