Orocos Real-Time Toolkit
2.5.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jun 26 13:25:56 CEST 2006 RealTimeTypekit.cxx 00003 00004 RealTimeTypekit.cxx - description 00005 ------------------- 00006 begin : Mon June 26 2006 00007 copyright : (C) 2006 Peter Soetens 00008 email : peter.soetens@fmtc.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 00040 #include "rtt-typekit-config.h" 00041 #include "RealTimeTypekit.hpp" 00042 #include "../types/Types.hpp" 00043 #include "../types/Operators.hpp" 00044 #include "../types/OperatorTypes.hpp" 00045 #include "../internal/mystd.hpp" 00046 #include "../rtt-fwd.hpp" 00047 #include "../FlowStatus.hpp" 00048 #include "../SendStatus.hpp" 00049 #include "../ConnPolicy.hpp" 00050 #include "../typekit/Types.hpp" 00051 #include <ostream> 00052 #include <sstream> 00053 #ifdef OS_RT_MALLOC 00054 #include "../rt_string.hpp" 00055 #endif 00056 00057 namespace RTT 00058 { 00059 using namespace std; 00060 using namespace detail; 00061 00062 #ifndef RTT_NO_STD_TYPES 00063 template<class T> 00064 struct get_capacity 00065 : public std::unary_function<T, int> 00066 { 00067 int operator()(T cont ) const 00068 { 00069 return cont.capacity(); 00070 } 00071 }; 00072 00073 template<class T> 00074 struct get_size 00075 : public std::unary_function<T, int> 00076 { 00077 int operator()(T cont ) const 00078 { 00079 return cont.size(); 00080 } 00081 }; 00082 00086 template <class T> 00087 struct string_concatenation : public std::binary_function<const std::string&, T, std::string> { 00088 std::string operator()(const std::string& s, T t) const { 00089 std::ostringstream oss(s, std::ios_base::ate); 00090 oss << std::boolalpha << t; 00091 return oss.str(); 00092 } 00093 }; 00094 #ifdef OS_RT_MALLOC 00095 template <class T> 00096 struct rt_string_concatenation : public std::binary_function<const rt_string&, T, rt_string> { 00097 rt_string operator()(const rt_string& s, T t) const { 00098 rt_ostringstream oss(s, std::ios_base::ate); 00099 oss << std::boolalpha << t; 00100 return oss.str(); 00101 } 00102 }; 00103 #endif 00104 00105 #endif 00106 00107 bool RealTimeTypekitPlugin::loadOperators() 00108 { 00109 OperatorRepository::shared_ptr oreg = OperatorRepository::Instance(); 00110 00111 // boolean stuff: 00112 oreg->add( newUnaryOperator( "!", std::logical_not<bool>() ) ); 00113 oreg->add( newBinaryOperator( "&&", std::logical_and<bool>() ) ); 00114 oreg->add( newBinaryOperator( "||", std::logical_or<bool>() ) ); 00115 oreg->add( newBinaryOperator( "==", std::equal_to<bool>() ) ); 00116 oreg->add( newBinaryOperator( "!=", std::not_equal_to<bool>() ) ); 00117 00118 // int stuff 00119 oreg->add( newUnaryOperator( "-", std::negate<int>() ) ); 00120 oreg->add( newUnaryOperator( "+", identity<int>() ) ); 00121 oreg->add( newBinaryOperator( "*", std::multiplies<int>() ) ); 00122 oreg->add( newBinaryOperator( "/", divides3<int,int,int>() ) ); // use our own divides<> which detects div by zero 00123 oreg->add( newBinaryOperator( "%", std::modulus<int>() ) ); 00124 oreg->add( newBinaryOperator( "+", std::plus<int>() ) ); 00125 oreg->add( newBinaryOperator( "-", std::minus<int>() ) ); 00126 oreg->add( newBinaryOperator( "<", std::less<int>() ) ); 00127 oreg->add( newBinaryOperator( "<=", std::less_equal<int>() ) ); 00128 oreg->add( newBinaryOperator( ">", std::greater<int>() ) ); 00129 oreg->add( newBinaryOperator( ">=", std::greater_equal<int>() ) ); 00130 oreg->add( newBinaryOperator( "==", std::equal_to<int>() ) ); 00131 oreg->add( newBinaryOperator( "!=", std::not_equal_to<int>() ) ); 00132 #ifndef ORO_EMBEDDED 00133 // uint stuff 00134 oreg->add( newUnaryOperator( "+", identity<unsigned int>() ) ); 00135 oreg->add( newBinaryOperator( "*", std::multiplies<unsigned int>() ) ); 00136 oreg->add( newBinaryOperator( "/", divides3<unsigned int,unsigned int,unsigned int>() ) ); // use our own divides<> which detects div by zero 00137 oreg->add( newBinaryOperator( "%", std::modulus<unsigned int>() ) ); 00138 oreg->add( newBinaryOperator( "+", std::plus<unsigned int>() ) ); 00139 oreg->add( newBinaryOperator( "-", std::minus<unsigned int>() ) ); 00140 oreg->add( newBinaryOperator( "<", std::less<unsigned int>() ) ); 00141 oreg->add( newBinaryOperator( "<=", std::less_equal<unsigned int>() ) ); 00142 oreg->add( newBinaryOperator( ">", std::greater<unsigned int>() ) ); 00143 oreg->add( newBinaryOperator( ">=", std::greater_equal<unsigned int>() ) ); 00144 oreg->add( newBinaryOperator( "==", std::equal_to<unsigned int>() ) ); 00145 oreg->add( newBinaryOperator( "!=", std::not_equal_to<unsigned int>() ) ); 00146 #endif 00147 // double stuff.. 00148 oreg->add( newUnaryOperator( "-", std::negate<double>() ) ); 00149 oreg->add( newUnaryOperator( "+", identity<double>() ) ); 00150 oreg->add( newBinaryOperator( "*", std::multiplies<double>() ) ); 00151 oreg->add( newBinaryOperator( "/", std::divides<double>() ) ); 00152 oreg->add( newBinaryOperator( "+", std::plus<double>() ) ); 00153 oreg->add( newBinaryOperator( "-", std::minus<double>() ) ); 00154 oreg->add( newBinaryOperator( "<", std::less<double>() ) ); 00155 oreg->add( newBinaryOperator( "<=", std::less_equal<double>() ) ); 00156 oreg->add( newBinaryOperator( ">", std::greater<double>() ) ); 00157 oreg->add( newBinaryOperator( ">=", std::greater_equal<double>() ) ); 00158 oreg->add( newBinaryOperator( "==", std::equal_to<double>() ) ); 00159 oreg->add( newBinaryOperator( "!=", std::not_equal_to<double>() ) ); 00160 #ifndef ORO_EMBEDDED 00161 // float stuff 00162 oreg->add( newUnaryOperator( "-", std::negate<float>() ) ); 00163 oreg->add( newUnaryOperator( "+", identity<float>() ) ); 00164 oreg->add( newBinaryOperator( "*", std::multiplies<float>() ) ); 00165 oreg->add( newBinaryOperator( "/", std::divides<float>() ) ); 00166 oreg->add( newBinaryOperator( "+", std::plus<float>() ) ); 00167 oreg->add( newBinaryOperator( "-", std::minus<float>() ) ); 00168 oreg->add( newBinaryOperator( "<", std::less<float>() ) ); 00169 oreg->add( newBinaryOperator( "<=", std::less_equal<float>() ) ); 00170 oreg->add( newBinaryOperator( ">", std::greater<float>() ) ); 00171 oreg->add( newBinaryOperator( ">=", std::greater_equal<float>() ) ); 00172 oreg->add( newBinaryOperator( "==", std::equal_to<float>() ) ); 00173 oreg->add( newBinaryOperator( "!=", std::not_equal_to<float>() ) ); 00174 #endif 00175 #ifndef RTT_NO_STD_TYPES 00176 // strings 00177 // causes memory allocation.... 00178 oreg->add( newBinaryOperator( "+", std::plus<std::string>() ) ); 00179 oreg->add( newBinaryOperator( "+", string_concatenation<int>() ) ); 00180 oreg->add( newBinaryOperator( "+", string_concatenation<unsigned int>() ) ); 00181 oreg->add( newBinaryOperator( "+", string_concatenation<double>() ) ); 00182 oreg->add( newBinaryOperator( "+", string_concatenation<float>() ) ); 00183 oreg->add( newBinaryOperator( "+", string_concatenation<bool>() ) ); 00184 oreg->add( newBinaryOperator( "+", string_concatenation<char>() ) ); 00185 oreg->add( newBinaryOperator( "==", std::equal_to<const std::string&>() ) ); 00186 oreg->add( newBinaryOperator( "!=", std::not_equal_to< const std::string&>() ) ); 00187 oreg->add( newBinaryOperator( "<", std::less<const std::string&>() ) ); 00188 oreg->add( newBinaryOperator( ">", std::greater<const std::string&>() ) ); 00189 oreg->add( newBinaryOperator( "<=", std::less_equal<std::string>() ) ); 00190 oreg->add( newBinaryOperator( ">=", std::greater_equal<std::string>() ) ); 00191 #endif 00192 00193 #ifdef OS_RT_MALLOC 00194 oreg->add( newBinaryOperator( "+", std::plus<rt_string>() ) ); 00195 oreg->add( newBinaryOperator( "+", rt_string_concatenation<int>() ) ); 00196 oreg->add( newBinaryOperator( "+", rt_string_concatenation<unsigned int>() ) ); 00197 oreg->add( newBinaryOperator( "+", rt_string_concatenation<double>() ) ); 00198 oreg->add( newBinaryOperator( "+", rt_string_concatenation<float>() ) ); 00199 oreg->add( newBinaryOperator( "+", rt_string_concatenation<bool>() ) ); 00200 oreg->add( newBinaryOperator( "+", rt_string_concatenation<char>() ) ); 00201 oreg->add( newBinaryOperator( "==", std::equal_to<const rt_string&>() ) ); 00202 oreg->add( newBinaryOperator( "!=", std::not_equal_to< const rt_string&>() ) ); 00203 oreg->add( newBinaryOperator( "<", std::less<const rt_string&>() ) ); 00204 oreg->add( newBinaryOperator( ">", std::greater<const rt_string&>() ) ); 00205 oreg->add( newBinaryOperator( "<=", std::less_equal<rt_string>() ) ); 00206 oreg->add( newBinaryOperator( ">=", std::greater_equal<rt_string>() ) ); 00207 #endif 00208 00209 #ifndef ORO_EMBEDDED 00210 // chars 00211 oreg->add( newBinaryOperator( "==", std::equal_to<char>() ) ); 00212 oreg->add( newBinaryOperator( "!=", std::not_equal_to<char>() ) ); 00213 oreg->add( newBinaryOperator( "<", std::less<char>() ) ); 00214 oreg->add( newBinaryOperator( ">", std::greater<char>() ) ); 00215 oreg->add( newBinaryOperator( "<=", std::less_equal<char>() ) ); 00216 oreg->add( newBinaryOperator( ">=", std::greater_equal<char>() ) ); 00217 #if 0 00218 // causes memory allocation.... 00219 oreg->add( newUnaryOperator( "-", std::negate<const std::vector<double>&>() ) ); 00220 oreg->add( newBinaryOperator( "*", std::multiplies<const std::vector<double>&>() ) ); 00221 oreg->add( newBinaryOperator( "+", std::plus<const std::vector<double>&>() ) ); 00222 oreg->add( newBinaryOperator( "-", std::minus<const std::vector<double>&>() ) ); 00223 oreg->add( newBinaryOperator( "*", multiplies3<const std::vector<double>&, double, const std::vector<double>&>() ) ); 00224 oreg->add( newBinaryOperator( "*", multiplies3<const std::vector<double>&, const std::vector<double>&, double>() ) ); 00225 oreg->add( newBinaryOperator( "/", divides3<const std::vector<double>&, const std::vector<double>&, double>() ) ); 00226 #endif 00227 #endif 00228 00229 // FlowStatus 00230 oreg->add( newBinaryOperator( "==", std::equal_to<FlowStatus>() ) ); 00231 oreg->add( newBinaryOperator( "!=", std::not_equal_to< FlowStatus>() ) ); 00232 oreg->add( newBinaryOperator( "<", std::less<FlowStatus>() ) ); 00233 oreg->add( newBinaryOperator( ">", std::greater<FlowStatus>() ) ); 00234 oreg->add( newBinaryOperator( "<=", std::less_equal<FlowStatus>() ) ); 00235 oreg->add( newBinaryOperator( ">=", std::greater_equal<FlowStatus>() ) ); 00236 00237 // SendStatus 00238 oreg->add( newBinaryOperator( "==", std::equal_to<SendStatus>() ) ); 00239 oreg->add( newBinaryOperator( "!=", std::not_equal_to< SendStatus>() ) ); 00240 oreg->add( newBinaryOperator( "<", std::less<SendStatus>() ) ); 00241 oreg->add( newBinaryOperator( ">", std::greater<SendStatus>() ) ); 00242 oreg->add( newBinaryOperator( "<=", std::less_equal<SendStatus>() ) ); 00243 oreg->add( newBinaryOperator( ">=", std::greater_equal<SendStatus>() ) ); 00244 00245 return true; 00246 } 00247 }