ros_primitives_typekit_plugin.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 * This file is part of the OROCOS toolchain ROS project *
3 * *
4 * (C) 2010 Ruben Smits, ruben.smits@mech.kuleuven.be *
5 * Steven Bellens, steven.bellens@mech.kuleuven.be *
6 * Department of Mechanical Engineering, *
7 * Katholieke Universiteit Leuven, Belgium. *
8 * *
9 * You may redistribute this software and/or modify it under either the *
10 * terms of the GNU Lesser General Public License version 2.1 (LGPLv2.1 *
11 * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>) or (at your *
12 * discretion) of the Modified BSD License: *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * 1. Redistributions of source code must retain the above copyright *
17 * notice, this list of conditions and the following disclaimer. *
18 * 2. Redistributions in binary form must reproduce the above copyright *
19 * notice, this list of conditions and the following disclaimer in the *
20 * documentation and/or other materials provided with the distribution. *
21 * 3. The name of the author may not be used to endorse or promote *
22 * products derived from this software without specific prior written *
23 * permission. *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,*
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING *
33 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
34 * POSSIBILITY OF SUCH DAMAGE. *
35 * *
36 *******************************************************************************/
37 
39 
40 namespace ros_integration {
41 
42  double float_to_double( float val ) {return double(val);}
43  float double_to_float( double val ) {return float(val);}
44  int32_t float_to_int(float f) { return int32_t(f); }
45  float int_to_float(int i) { return float(i); }
46  int32_t double_to_int(double f) { return int32_t(f); }
47  double int_to_double(int32_t i) { return double(i); }
48  uint32_t int_to_uint(int32_t i) { return (uint32_t)(i); }
49  int uint_to_int(uint32_t ui) { return int32_t(ui); }
50  bool int_to_bool(int32_t i) { return bool(i); }
51 
52  template<class T,class R>
53  R a_to_b( T t ) { return R(t); }
54 
55  struct string_ctor
56  : public std::unary_function<int, const std::string&>
57  {
58  mutable boost::shared_ptr< std::string > ptr;
59  typedef const std::string& (Signature)( int );
61  : ptr( new std::string() ) {}
62  const std::string& operator()( int size ) const
63  {
64  ptr->resize( size );
65  return *(ptr);
66  }
67  };
68 
69  void loadTimeTypes();
70 
71  void loadUInt8Types();
72  void loadInt8Types();
73 
74  void loadUInt16Types();
75  void loadInt16Types();
76 
77  void loadUInt32Types();
78  void loadInt32Types();
79 
80  void loadUInt64Types();
81  void loadInt64Types();
82 
83  void loadFloat32Types();
84  void loadFloat64Types();
85 
86  void loadStringTypes();
87 
89  return "ros-primitives";
90  }
91 
93  loadTimeTypes();
94 
95  loadInt8Types();
97 
100 
101  loadInt32Types();
102  loadUInt32Types();
103 
104  loadInt64Types();
105  loadUInt64Types();
106 
109 
110  loadStringTypes();
111 
112  return true;
113  }
116  types::TypeInfoRepository::shared_ptr ti = types::TypeInfoRepository::Instance();
117  // x to float64
118  ti->type("float64")->addConstructor( newConstructor( &float_to_double, true ));
119  ti->type("float64")->addConstructor( newConstructor( &int_to_double, true ));
120 
121  // x to float
122  ti->type("float")->addConstructor( newConstructor( &int_to_float, true ));
123  ti->type("float")->addConstructor( newConstructor( &double_to_float, true ));
124 
125  // x to int
126  ti->type("int32")->addConstructor( newConstructor( &float_to_int, false ));
127  ti->type("int32")->addConstructor( newConstructor( &double_to_int, false ));
128 
129  // we certainly need int32/uint32 to 8/16 since the RTT parser only knows 32bit wide ints.
130 
131  // x to uint8_t (ROS' bool)
132  ti->type("uint8")->addConstructor( newConstructor( &a_to_b<int8_t,uint8_t>, false ));
133  ti->type("uint8")->addConstructor( newConstructor( &a_to_b<int16_t,uint8_t>, false ));
134  ti->type("uint8")->addConstructor( newConstructor( &a_to_b<int32_t,uint8_t>, false ));
135  ti->type("uint8")->addConstructor( newConstructor( &a_to_b<uint16_t,uint8_t>, false ));
136  ti->type("uint8")->addConstructor( newConstructor( &a_to_b<uint32_t,uint8_t>, false ));
137 
138  ti->type("int8")->addConstructor( newConstructor( &a_to_b<uint8_t,int8_t>, false ));
139  ti->type("int8")->addConstructor( newConstructor( &a_to_b<uint16_t,int8_t>, false ));
140  ti->type("int8")->addConstructor( newConstructor( &a_to_b<uint32_t,int8_t>, false ));
141  ti->type("int8")->addConstructor( newConstructor( &a_to_b<int16_t,int8_t>, false ));
142  ti->type("int8")->addConstructor( newConstructor( &a_to_b<int32_t,int8_t>, false ));
143 
144  // x to uint16_t
145  ti->type("uint16")->addConstructor( newConstructor( &a_to_b<int8_t,uint16_t>, false ));
146  ti->type("uint16")->addConstructor( newConstructor( &a_to_b<int16_t,uint16_t>, false ));
147  ti->type("uint16")->addConstructor( newConstructor( &a_to_b<int32_t,uint16_t>, false ));
148  ti->type("uint16")->addConstructor( newConstructor( &a_to_b<uint8_t,uint16_t>, true ));
149  ti->type("uint16")->addConstructor( newConstructor( &a_to_b<uint32_t,uint16_t>, false ));
150 
151  ti->type("int16")->addConstructor( newConstructor( &a_to_b<uint8_t,int16_t>, true ));
152  ti->type("int16")->addConstructor( newConstructor( &a_to_b<uint16_t,int16_t>, false ));
153  ti->type("int16")->addConstructor( newConstructor( &a_to_b<uint32_t,int16_t>, false ));
154  ti->type("int16")->addConstructor( newConstructor( &a_to_b<int8_t,int16_t>, true ));
155  ti->type("int16")->addConstructor( newConstructor( &a_to_b<int32_t,int16_t>, false ));
156 
157  // x to uint32_t
158  ti->type("uint32")->addConstructor( newConstructor( &a_to_b<int8_t,uint32_t>, false ));
159  ti->type("uint32")->addConstructor( newConstructor( &a_to_b<int16_t,uint32_t>, false ));
160  ti->type("uint32")->addConstructor( newConstructor( &a_to_b<int32_t,uint32_t>, true ));
161  ti->type("uint32")->addConstructor( newConstructor( &a_to_b<uint8_t,uint32_t>, true ));
162  ti->type("uint32")->addConstructor( newConstructor( &a_to_b<uint16_t,uint32_t>, true ));
163 
164  ti->type("int32")->addConstructor( newConstructor( &a_to_b<uint8_t,int32_t>, true ));
165  ti->type("int32")->addConstructor( newConstructor( &a_to_b<uint16_t,int32_t>, true ));
166  ti->type("int32")->addConstructor( newConstructor( &a_to_b<uint32_t,int32_t>, true ));
167  ti->type("int32")->addConstructor( newConstructor( &a_to_b<int8_t,int32_t>, true ));
168  ti->type("int32")->addConstructor( newConstructor( &a_to_b<int16_t,int32_t>, true ));
169 
170  ti->type("string")->addConstructor( newConstructor( string_ctor() ) );
171  ti->type("duration")->addConstructor( newConstructor ( &a_to_b<double,ros::Duration>, true));
172  ti->type("time")->addConstructor( newConstructor ( &a_to_b<double,ros::Time>, true));
173  return true;
174  }
175 }
176 
178 
boost::shared_ptr< std::string > ptr
#define ORO_TYPEKIT_PLUGIN(TYPEKIT)
const std::string & operator()(int size) const
uint32_t int_to_uint(int32_t i)
TypeConstructor * newConstructor(Function *foo, bool automatic=false)
boost::shared_ptr< TypeInfoRepository > shared_ptr


rtt_ros
Author(s): Ruben Smits
autogenerated on Sat Jun 8 2019 18:04:54