YARP
Yet Another Robot Platform
SolidPrimitive.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 // This is an automatically generated file.
7 
8 // Generated from the following "shape_msgs/SolidPrimitive" msg definition:
9 // # Define box, sphere, cylinder, cone
10 // # All shapes are defined to have their bounding boxes centered around 0,0,0.
11 //
12 // uint8 BOX=1
13 // uint8 SPHERE=2
14 // uint8 CYLINDER=3
15 // uint8 CONE=4
16 //
17 // # The type of the shape
18 // uint8 type
19 //
20 //
21 // # The dimensions of the shape
22 // float64[] dimensions
23 //
24 // # The meaning of the shape dimensions: each constant defines the index in the 'dimensions' array
25 //
26 // # For the BOX type, the X, Y, and Z dimensions are the length of the corresponding
27 // # sides of the box.
28 // uint8 BOX_X=0
29 // uint8 BOX_Y=1
30 // uint8 BOX_Z=2
31 //
32 //
33 // # For the SPHERE type, only one component is used, and it gives the radius of
34 // # the sphere.
35 // uint8 SPHERE_RADIUS=0
36 //
37 //
38 // # For the CYLINDER and CONE types, the center line is oriented along
39 // # the Z axis. Therefore the CYLINDER_HEIGHT (CONE_HEIGHT) component
40 // # of dimensions gives the height of the cylinder (cone). The
41 // # CYLINDER_RADIUS (CONE_RADIUS) component of dimensions gives the
42 // # radius of the base of the cylinder (cone). Cone and cylinder
43 // # primitives are defined to be circular. The tip of the cone is
44 // # pointing up, along +Z axis.
45 //
46 // uint8 CYLINDER_HEIGHT=0
47 // uint8 CYLINDER_RADIUS=1
48 //
49 // uint8 CONE_HEIGHT=0
50 // uint8 CONE_RADIUS=1
51 // Instances of this class can be read and written with YARP ports,
52 // using a ROS-compatible format.
53 
54 #ifndef YARP_ROSMSG_shape_msgs_SolidPrimitive_h
55 #define YARP_ROSMSG_shape_msgs_SolidPrimitive_h
56 
57 #include <yarp/os/Wire.h>
58 #include <yarp/os/Type.h>
59 #include <yarp/os/idl/WireTypes.h>
60 #include <string>
61 #include <vector>
62 
63 namespace yarp {
64 namespace rosmsg {
65 namespace shape_msgs {
66 
68 {
69 public:
70  static const std::uint8_t BOX = 1;
71  static const std::uint8_t SPHERE = 2;
72  static const std::uint8_t CYLINDER = 3;
73  static const std::uint8_t CONE = 4;
74  std::uint8_t type;
75  std::vector<yarp::conf::float64_t> dimensions;
76  static const std::uint8_t BOX_X = 0;
77  static const std::uint8_t BOX_Y = 1;
78  static const std::uint8_t BOX_Z = 2;
79  static const std::uint8_t SPHERE_RADIUS = 0;
80  static const std::uint8_t CYLINDER_HEIGHT = 0;
81  static const std::uint8_t CYLINDER_RADIUS = 1;
82  static const std::uint8_t CONE_HEIGHT = 0;
83  static const std::uint8_t CONE_RADIUS = 1;
84 
86  type(0),
87  dimensions()
88  {
89  }
90 
91  void clear()
92  {
93  // *** BOX ***
94 
95  // *** SPHERE ***
96 
97  // *** CYLINDER ***
98 
99  // *** CONE ***
100 
101  // *** type ***
102  type = 0;
103 
104  // *** dimensions ***
105  dimensions.clear();
106 
107  // *** BOX_X ***
108 
109  // *** BOX_Y ***
110 
111  // *** BOX_Z ***
112 
113  // *** SPHERE_RADIUS ***
114 
115  // *** CYLINDER_HEIGHT ***
116 
117  // *** CYLINDER_RADIUS ***
118 
119  // *** CONE_HEIGHT ***
120 
121  // *** CONE_RADIUS ***
122  }
123 
124  bool readBare(yarp::os::ConnectionReader& connection) override
125  {
126  // *** type ***
127  type = connection.expectInt8();
128 
129  // *** dimensions ***
130  int len = connection.expectInt32();
131  dimensions.resize(len);
132  if (len > 0 && !connection.expectBlock((char*)&dimensions[0], sizeof(yarp::conf::float64_t)*len)) {
133  return false;
134  }
135 
136  return !connection.isError();
137  }
138 
139  bool readBottle(yarp::os::ConnectionReader& connection) override
140  {
141  connection.convertTextMode();
142  yarp::os::idl::WireReader reader(connection);
143  if (!reader.readListHeader(14)) {
144  return false;
145  }
146 
147  // *** type ***
148  type = reader.expectInt8();
149 
150  // *** dimensions ***
151  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT64)) {
152  return false;
153  }
154  int len = connection.expectInt32();
155  dimensions.resize(len);
156  for (int i=0; i<len; i++) {
158  }
159 
160  return !connection.isError();
161  }
162 
164  bool read(yarp::os::ConnectionReader& connection) override
165  {
166  return (connection.isBareMode() ? readBare(connection)
167  : readBottle(connection));
168  }
169 
170  bool writeBare(yarp::os::ConnectionWriter& connection) const override
171  {
172  // *** type ***
173  connection.appendInt8(type);
174 
175  // *** dimensions ***
176  connection.appendInt32(dimensions.size());
177  if (dimensions.size()>0) {
178  connection.appendExternalBlock((char*)&dimensions[0], sizeof(yarp::conf::float64_t)*dimensions.size());
179  }
180 
181  return !connection.isError();
182  }
183 
184  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
185  {
186  connection.appendInt32(BOTTLE_TAG_LIST);
187  connection.appendInt32(14);
188 
189  // *** type ***
190  connection.appendInt32(BOTTLE_TAG_INT8);
191  connection.appendInt8(type);
192 
193  // *** dimensions ***
195  connection.appendInt32(dimensions.size());
196  for (size_t i=0; i<dimensions.size(); i++) {
197  connection.appendFloat64(dimensions[i]);
198  }
199 
200  connection.convertTextMode();
201  return !connection.isError();
202  }
203 
205  bool write(yarp::os::ConnectionWriter& connection) const override
206  {
207  return (connection.isBareMode() ? writeBare(connection)
208  : writeBottle(connection));
209  }
210 
211  // This class will serialize ROS style or YARP style depending on protocol.
212  // If you need to force a serialization style, use one of these classes:
215 
216  // The name for this message, ROS will need this
217  static constexpr const char* typeName = "shape_msgs/SolidPrimitive";
218 
219  // The checksum for this message, ROS will need this
220  static constexpr const char* typeChecksum = "d8f8cbc74c5ff283fca29569ccefb45d";
221 
222  // The source text for this message, ROS will need this
223  static constexpr const char* typeText = "\
224 # Define box, sphere, cylinder, cone \n\
225 # All shapes are defined to have their bounding boxes centered around 0,0,0.\n\
226 \n\
227 uint8 BOX=1\n\
228 uint8 SPHERE=2\n\
229 uint8 CYLINDER=3\n\
230 uint8 CONE=4\n\
231 \n\
232 # The type of the shape\n\
233 uint8 type\n\
234 \n\
235 \n\
236 # The dimensions of the shape\n\
237 float64[] dimensions\n\
238 \n\
239 # The meaning of the shape dimensions: each constant defines the index in the 'dimensions' array\n\
240 \n\
241 # For the BOX type, the X, Y, and Z dimensions are the length of the corresponding\n\
242 # sides of the box.\n\
243 uint8 BOX_X=0\n\
244 uint8 BOX_Y=1\n\
245 uint8 BOX_Z=2\n\
246 \n\
247 \n\
248 # For the SPHERE type, only one component is used, and it gives the radius of\n\
249 # the sphere.\n\
250 uint8 SPHERE_RADIUS=0\n\
251 \n\
252 \n\
253 # For the CYLINDER and CONE types, the center line is oriented along\n\
254 # the Z axis. Therefore the CYLINDER_HEIGHT (CONE_HEIGHT) component\n\
255 # of dimensions gives the height of the cylinder (cone). The\n\
256 # CYLINDER_RADIUS (CONE_RADIUS) component of dimensions gives the\n\
257 # radius of the base of the cylinder (cone). Cone and cylinder\n\
258 # primitives are defined to be circular. The tip of the cone is\n\
259 # pointing up, along +Z axis.\n\
260 \n\
261 uint8 CYLINDER_HEIGHT=0\n\
262 uint8 CYLINDER_RADIUS=1\n\
263 \n\
264 uint8 CONE_HEIGHT=0\n\
265 uint8 CONE_RADIUS=1\n\
266 ";
267 
268  yarp::os::Type getType() const override
269  {
271  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
272  typ.addProperty("message_definition", yarp::os::Value(typeText));
273  return typ;
274  }
275 };
276 
277 } // namespace shape_msgs
278 } // namespace rosmsg
279 } // namespace yarp
280 
281 #endif // YARP_ROSMSG_shape_msgs_SolidPrimitive_h
#define BOTTLE_TAG_INT8
Definition: Bottle.h:19
#define BOTTLE_TAG_FLOAT64
Definition: Bottle.h:25
#define BOTTLE_TAG_LIST
Definition: Bottle.h:28
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool isError() const =0
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
An interface for writing to a network connection.
virtual bool isError() const =0
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual void appendInt8(std::int8_t data)=0
Send a representation of a 8-bit integer to the network connection.
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
static Type byName(const char *name)
Definition: Type.cpp:171
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:134
A single value (typically within a Bottle).
Definition: Value.h:45
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:23
virtual bool read(yarp::os::idl::WireReader &reader)
virtual bool write(const yarp::os::idl::WireWriter &writer) const
IDL-friendly connection reader.
Definition: WireReader.h:30
std::int8_t expectInt8()
Definition: WireReader.h:80
bool writeBare(yarp::os::ConnectionWriter &connection) const override
bool readBare(yarp::os::ConnectionReader &connection) override
yarp::os::idl::BottleStyle< yarp::rosmsg::shape_msgs::SolidPrimitive > bottleStyle
static const std::uint8_t CONE_HEIGHT
static const std::uint8_t CYLINDER
yarp::os::idl::BareStyle< yarp::rosmsg::shape_msgs::SolidPrimitive > rosStyle
bool readBottle(yarp::os::ConnectionReader &connection) override
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
static const std::uint8_t SPHERE_RADIUS
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * typeChecksum
static const std::uint8_t CYLINDER_HEIGHT
static constexpr const char * typeName
yarp::os::Type getType() const override
static const std::uint8_t CYLINDER_RADIUS
static constexpr const char * typeText
std::vector< yarp::conf::float64_t > dimensions
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
static const std::uint8_t CONE_RADIUS
double float64_t
Definition: numeric.h:77
The main, catch-all namespace for YARP.
Definition: dirs.h:16