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