YARP
Yet Another Robot Platform
ChannelFloat32.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 // This is an automatically generated file.
10 
11 // Generated from the following "sensor_msgs/ChannelFloat32" msg definition:
12 // # This message is used by the PointCloud message to hold optional data
13 // # associated with each point in the cloud. The length of the values
14 // # array should be the same as the length of the points array in the
15 // # PointCloud, and each value should be associated with the corresponding
16 // # point.
17 //
18 // # Channel names in existing practice include:
19 // # "u", "v" - row and column (respectively) in the left stereo image.
20 // # This is opposite to usual conventions but remains for
21 // # historical reasons. The newer PointCloud2 message has no
22 // # such problem.
23 // # "rgb" - For point clouds produced by color stereo cameras. uint8
24 // # (R,G,B) values packed into the least significant 24 bits,
25 // # in order.
26 // # "intensity" - laser or pixel intensity.
27 // # "distance"
28 //
29 // # The channel name should give semantics of the channel (e.g.
30 // # "intensity" instead of "value").
31 // string name
32 //
33 // # The values array should be 1-1 with the elements of the associated
34 // # PointCloud.
35 // float32[] values
36 // Instances of this class can be read and written with YARP ports,
37 // using a ROS-compatible format.
38 
39 #ifndef YARP_ROSMSG_sensor_msgs_ChannelFloat32_h
40 #define YARP_ROSMSG_sensor_msgs_ChannelFloat32_h
41 
42 #include <yarp/os/Wire.h>
43 #include <yarp/os/Type.h>
44 #include <yarp/os/idl/WireTypes.h>
45 #include <string>
46 #include <vector>
47 
48 namespace yarp {
49 namespace rosmsg {
50 namespace sensor_msgs {
51 
53 {
54 public:
55  std::string name;
56  std::vector<yarp::conf::float32_t> values;
57 
59  name(""),
60  values()
61  {
62  }
63 
64  void clear()
65  {
66  // *** name ***
67  name = "";
68 
69  // *** values ***
70  values.clear();
71  }
72 
73  bool readBare(yarp::os::ConnectionReader& connection) override
74  {
75  // *** name ***
76  int len = connection.expectInt32();
77  name.resize(len);
78  if (!connection.expectBlock((char*)name.c_str(), len)) {
79  return false;
80  }
81 
82  // *** values ***
83  len = connection.expectInt32();
84  values.resize(len);
85  if (len > 0 && !connection.expectBlock((char*)&values[0], sizeof(yarp::conf::float32_t)*len)) {
86  return false;
87  }
88 
89  return !connection.isError();
90  }
91 
92  bool readBottle(yarp::os::ConnectionReader& connection) override
93  {
94  connection.convertTextMode();
95  yarp::os::idl::WireReader reader(connection);
96  if (!reader.readListHeader(2)) {
97  return false;
98  }
99 
100  // *** name ***
101  if (!reader.readString(name)) {
102  return false;
103  }
104 
105  // *** values ***
106  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT32)) {
107  return false;
108  }
109  int len = connection.expectInt32();
110  values.resize(len);
111  for (int i=0; i<len; i++) {
112  values[i] = (yarp::conf::float32_t)connection.expectFloat32();
113  }
114 
115  return !connection.isError();
116  }
117 
119  bool read(yarp::os::ConnectionReader& connection) override
120  {
121  return (connection.isBareMode() ? readBare(connection)
122  : readBottle(connection));
123  }
124 
125  bool writeBare(yarp::os::ConnectionWriter& connection) const override
126  {
127  // *** name ***
128  connection.appendInt32(name.length());
129  connection.appendExternalBlock((char*)name.c_str(), name.length());
130 
131  // *** values ***
132  connection.appendInt32(values.size());
133  if (values.size()>0) {
134  connection.appendExternalBlock((char*)&values[0], sizeof(yarp::conf::float32_t)*values.size());
135  }
136 
137  return !connection.isError();
138  }
139 
140  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
141  {
142  connection.appendInt32(BOTTLE_TAG_LIST);
143  connection.appendInt32(2);
144 
145  // *** name ***
146  connection.appendInt32(BOTTLE_TAG_STRING);
147  connection.appendInt32(name.length());
148  connection.appendExternalBlock((char*)name.c_str(), name.length());
149 
150  // *** values ***
152  connection.appendInt32(values.size());
153  for (size_t i=0; i<values.size(); i++) {
154  connection.appendFloat32(values[i]);
155  }
156 
157  connection.convertTextMode();
158  return !connection.isError();
159  }
160 
162  bool write(yarp::os::ConnectionWriter& connection) const override
163  {
164  return (connection.isBareMode() ? writeBare(connection)
165  : writeBottle(connection));
166  }
167 
168  // This class will serialize ROS style or YARP style depending on protocol.
169  // If you need to force a serialization style, use one of these classes:
172 
173  // The name for this message, ROS will need this
174  static constexpr const char* typeName = "sensor_msgs/ChannelFloat32";
175 
176  // The checksum for this message, ROS will need this
177  static constexpr const char* typeChecksum = "3d40139cdd33dfedcb71ffeeeb42ae7f";
178 
179  // The source text for this message, ROS will need this
180  static constexpr const char* typeText = "\
181 # This message is used by the PointCloud message to hold optional data\n\
182 # associated with each point in the cloud. The length of the values\n\
183 # array should be the same as the length of the points array in the\n\
184 # PointCloud, and each value should be associated with the corresponding\n\
185 # point.\n\
186 \n\
187 # Channel names in existing practice include:\n\
188 # \"u\", \"v\" - row and column (respectively) in the left stereo image.\n\
189 # This is opposite to usual conventions but remains for\n\
190 # historical reasons. The newer PointCloud2 message has no\n\
191 # such problem.\n\
192 # \"rgb\" - For point clouds produced by color stereo cameras. uint8\n\
193 # (R,G,B) values packed into the least significant 24 bits,\n\
194 # in order.\n\
195 # \"intensity\" - laser or pixel intensity.\n\
196 # \"distance\"\n\
197 \n\
198 # The channel name should give semantics of the channel (e.g.\n\
199 # \"intensity\" instead of \"value\").\n\
200 string name\n\
201 \n\
202 # The values array should be 1-1 with the elements of the associated\n\
203 # PointCloud.\n\
204 float32[] values\n\
205 ";
206 
207  yarp::os::Type getType() const override
208  {
210  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
211  typ.addProperty("message_definition", yarp::os::Value(typeText));
212  return typ;
213  }
214 };
215 
216 } // namespace sensor_msgs
217 } // namespace rosmsg
218 } // namespace yarp
219 
220 #endif // YARP_ROSMSG_sensor_msgs_ChannelFloat32_h
yarp::os::ConnectionWriter::appendFloat32
virtual void appendFloat32(yarp::conf::float32_t data)=0
Send a representation of a 32-bit floating point number to the network connection.
yarp::rosmsg::sensor_msgs::ChannelFloat32::ChannelFloat32
ChannelFloat32()
Definition: ChannelFloat32.h:58
yarp::os::idl::WireReader::readString
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:339
yarp::rosmsg::sensor_msgs::ChannelFloat32::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: ChannelFloat32.h:119
yarp::rosmsg::sensor_msgs::ChannelFloat32::typeChecksum
static constexpr const char * typeChecksum
Definition: ChannelFloat32.h:177
WireTypes.h
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
yarp::os::idl::BottleStyle
Definition: BottleStyle.h:22
yarp::os::Type
Definition: Type.h:24
yarp::os::idl::WirePortable::read
virtual bool read(yarp::os::idl::WireReader &reader)
Definition: WirePortable.cpp:14
yarp::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
BOTTLE_TAG_STRING
#define BOTTLE_TAG_STRING
Definition: Bottle.h:28
Wire.h
yarp::rosmsg::sensor_msgs::ChannelFloat32::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: ChannelFloat32.h:125
yarp::rosmsg::sensor_msgs::ChannelFloat32::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::ChannelFloat32 > rosStyle
Definition: ChannelFloat32.h:170
yarp::rosmsg::sensor_msgs::ChannelFloat32::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: ChannelFloat32.h:140
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
BOTTLE_TAG_FLOAT32
#define BOTTLE_TAG_FLOAT32
Definition: Bottle.h:26
yarp::os::Type::byName
static Type byName(const char *name)
Definition: Type.cpp:174
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::Type::addProperty
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:137
yarp::rosmsg::sensor_msgs::ChannelFloat32
Definition: ChannelFloat32.h:53
Type.h
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
yarp::rosmsg::sensor_msgs::ChannelFloat32::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::ChannelFloat32 > bottleStyle
Definition: ChannelFloat32.h:171
yarp::rosmsg::sensor_msgs::ChannelFloat32::getType
yarp::os::Type getType() const override
Definition: ChannelFloat32.h:207
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::os::idl::WirePortable
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:26
yarp::os::ConnectionWriter::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
yarp::os::idl::WireReader
IDL-friendly connection reader.
Definition: WireReader.h:33
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::idl::BareStyle
Definition: BareStyle.h:22
yarp::rosmsg::sensor_msgs::ChannelFloat32::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: ChannelFloat32.h:73
yarp::rosmsg::sensor_msgs::ChannelFloat32::clear
void clear()
Definition: ChannelFloat32.h:64
yarp::rosmsg::sensor_msgs::ChannelFloat32::name
std::string name
Definition: ChannelFloat32.h:55
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::ConnectionReader::expectFloat32
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
yarp::rosmsg::sensor_msgs::ChannelFloat32::values
std::vector< yarp::conf::float32_t > values
Definition: ChannelFloat32.h:56
yarp::os::ConnectionWriter::appendExternalBlock
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::rosmsg::sensor_msgs::ChannelFloat32::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: ChannelFloat32.h:92
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
sensor_msgs
Definition: BatteryState.h:22
yarp::rosmsg::sensor_msgs::ChannelFloat32::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: ChannelFloat32.h:162
yarp::rosmsg::sensor_msgs::ChannelFloat32::typeName
static constexpr const char * typeName
Definition: ChannelFloat32.h:174
yarp::rosmsg::sensor_msgs::ChannelFloat32::typeText
static constexpr const char * typeText
Definition: ChannelFloat32.h:180
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WirePortable::write
virtual bool write(const yarp::os::idl::WireWriter &writer) const
Definition: WirePortable.cpp:20