YARP
Yet Another Robot Platform
MultiArrayLayout.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 "std_msgs/MultiArrayLayout" msg definition:
12 // # The multiarray declares a generic multi-dimensional array of a
13 // # particular data type. Dimensions are ordered from outer most
14 // # to inner most.
15 //
16 // MultiArrayDimension[] dim # Array of dimension properties
17 // uint32 data_offset # padding elements at front of data
18 //
19 // # Accessors should ALWAYS be written in terms of dimension stride
20 // # and specified outer-most dimension first.
21 // #
22 // # multiarray(i,j,k) = data[data_offset + dim_stride[1]*i + dim_stride[2]*j + k]
23 // #
24 // # A standard, 3-channel 640x480 image with interleaved color channels
25 // # would be specified as:
26 // #
27 // # dim[0].label = "height"
28 // # dim[0].size = 480
29 // # dim[0].stride = 3*640*480 = 921600 (note dim[0] stride is just size of image)
30 // # dim[1].label = "width"
31 // # dim[1].size = 640
32 // # dim[1].stride = 3*640 = 1920
33 // # dim[2].label = "channel"
34 // # dim[2].size = 3
35 // # dim[2].stride = 3
36 // #
37 // # multiarray(i,j,k) refers to the ith row, jth column, and kth channel.
38 // Instances of this class can be read and written with YARP ports,
39 // using a ROS-compatible format.
40 
41 #ifndef YARP_ROSMSG_std_msgs_MultiArrayLayout_h
42 #define YARP_ROSMSG_std_msgs_MultiArrayLayout_h
43 
44 #include <yarp/os/Wire.h>
45 #include <yarp/os/Type.h>
46 #include <yarp/os/idl/WireTypes.h>
47 #include <string>
48 #include <vector>
50 
51 namespace yarp {
52 namespace rosmsg {
53 namespace std_msgs {
54 
56 {
57 public:
58  std::vector<yarp::rosmsg::std_msgs::MultiArrayDimension> dim;
59  std::uint32_t data_offset;
60 
62  dim(),
63  data_offset(0)
64  {
65  }
66 
67  void clear()
68  {
69  // *** dim ***
70  dim.clear();
71 
72  // *** data_offset ***
73  data_offset = 0;
74  }
75 
76  bool readBare(yarp::os::ConnectionReader& connection) override
77  {
78  // *** dim ***
79  int len = connection.expectInt32();
80  dim.resize(len);
81  for (int i=0; i<len; i++) {
82  if (!dim[i].read(connection)) {
83  return false;
84  }
85  }
86 
87  // *** data_offset ***
88  data_offset = connection.expectInt32();
89 
90  return !connection.isError();
91  }
92 
93  bool readBottle(yarp::os::ConnectionReader& connection) override
94  {
95  connection.convertTextMode();
96  yarp::os::idl::WireReader reader(connection);
97  if (!reader.readListHeader(2)) {
98  return false;
99  }
100 
101  // *** dim ***
102  if (connection.expectInt32() != BOTTLE_TAG_LIST) {
103  return false;
104  }
105  int len = connection.expectInt32();
106  dim.resize(len);
107  for (int i=0; i<len; i++) {
108  if (!dim[i].read(connection)) {
109  return false;
110  }
111  }
112 
113  // *** data_offset ***
114  data_offset = reader.expectInt32();
115 
116  return !connection.isError();
117  }
118 
120  bool read(yarp::os::ConnectionReader& connection) override
121  {
122  return (connection.isBareMode() ? readBare(connection)
123  : readBottle(connection));
124  }
125 
126  bool writeBare(yarp::os::ConnectionWriter& connection) const override
127  {
128  // *** dim ***
129  connection.appendInt32(dim.size());
130  for (size_t i=0; i<dim.size(); i++) {
131  if (!dim[i].write(connection)) {
132  return false;
133  }
134  }
135 
136  // *** data_offset ***
137  connection.appendInt32(data_offset);
138 
139  return !connection.isError();
140  }
141 
142  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
143  {
144  connection.appendInt32(BOTTLE_TAG_LIST);
145  connection.appendInt32(2);
146 
147  // *** dim ***
148  connection.appendInt32(BOTTLE_TAG_LIST);
149  connection.appendInt32(dim.size());
150  for (size_t i=0; i<dim.size(); i++) {
151  if (!dim[i].write(connection)) {
152  return false;
153  }
154  }
155 
156  // *** data_offset ***
157  connection.appendInt32(BOTTLE_TAG_INT32);
158  connection.appendInt32(data_offset);
159 
160  connection.convertTextMode();
161  return !connection.isError();
162  }
163 
165  bool write(yarp::os::ConnectionWriter& connection) const override
166  {
167  return (connection.isBareMode() ? writeBare(connection)
168  : writeBottle(connection));
169  }
170 
171  // This class will serialize ROS style or YARP style depending on protocol.
172  // If you need to force a serialization style, use one of these classes:
175 
176  // The name for this message, ROS will need this
177  static constexpr const char* typeName = "std_msgs/MultiArrayLayout";
178 
179  // The checksum for this message, ROS will need this
180  static constexpr const char* typeChecksum = "0fed2a11c13e11c5571b4e2a995a91a3";
181 
182  // The source text for this message, ROS will need this
183  static constexpr const char* typeText = "\
184 # The multiarray declares a generic multi-dimensional array of a\n\
185 # particular data type. Dimensions are ordered from outer most\n\
186 # to inner most.\n\
187 \n\
188 MultiArrayDimension[] dim # Array of dimension properties\n\
189 uint32 data_offset # padding elements at front of data\n\
190 \n\
191 # Accessors should ALWAYS be written in terms of dimension stride\n\
192 # and specified outer-most dimension first.\n\
193 # \n\
194 # multiarray(i,j,k) = data[data_offset + dim_stride[1]*i + dim_stride[2]*j + k]\n\
195 #\n\
196 # A standard, 3-channel 640x480 image with interleaved color channels\n\
197 # would be specified as:\n\
198 #\n\
199 # dim[0].label = \"height\"\n\
200 # dim[0].size = 480\n\
201 # dim[0].stride = 3*640*480 = 921600 (note dim[0] stride is just size of image)\n\
202 # dim[1].label = \"width\"\n\
203 # dim[1].size = 640\n\
204 # dim[1].stride = 3*640 = 1920\n\
205 # dim[2].label = \"channel\"\n\
206 # dim[2].size = 3\n\
207 # dim[2].stride = 3\n\
208 #\n\
209 # multiarray(i,j,k) refers to the ith row, jth column, and kth channel.\n\
210 \n\
211 ================================================================================\n\
212 MSG: std_msgs/MultiArrayDimension\n\
213 string label # label of given dimension\n\
214 uint32 size # size of given dimension (in type units)\n\
215 uint32 stride # stride of given dimension\n\
216 ";
217 
218  yarp::os::Type getType() const override
219  {
221  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
222  typ.addProperty("message_definition", yarp::os::Value(typeText));
223  return typ;
224  }
225 };
226 
227 } // namespace std_msgs
228 } // namespace rosmsg
229 } // namespace yarp
230 
231 #endif // YARP_ROSMSG_std_msgs_MultiArrayLayout_h
yarp::rosmsg::std_msgs::MultiArrayLayout::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: MultiArrayLayout.h:120
yarp::rosmsg::std_msgs::MultiArrayLayout::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: MultiArrayLayout.h:93
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.
Wire.h
yarp::rosmsg::std_msgs::MultiArrayLayout::MultiArrayLayout
MultiArrayLayout()
Definition: MultiArrayLayout.h:61
yarp::rosmsg::std_msgs::MultiArrayLayout::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: MultiArrayLayout.h:142
yarp::rosmsg::std_msgs::MultiArrayLayout::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::std_msgs::MultiArrayLayout > bottleStyle
Definition: MultiArrayLayout.h:174
yarp::rosmsg::std_msgs::MultiArrayLayout::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::std_msgs::MultiArrayLayout > rosStyle
Definition: MultiArrayLayout.h:173
BOTTLE_TAG_INT32
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
yarp::rosmsg::std_msgs::MultiArrayLayout::dim
std::vector< yarp::rosmsg::std_msgs::MultiArrayDimension > dim
Definition: MultiArrayLayout.h:58
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
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
Type.h
std_msgs
Definition: Bool.h:22
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::rosmsg::std_msgs::MultiArrayLayout::typeName
static constexpr const char * typeName
Definition: MultiArrayLayout.h:177
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
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::rosmsg::std_msgs::MultiArrayLayout::clear
void clear()
Definition: MultiArrayLayout.h:67
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.
MultiArrayDimension.h
yarp::rosmsg::std_msgs::MultiArrayLayout::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: MultiArrayLayout.h:126
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::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::rosmsg::std_msgs::MultiArrayLayout
Definition: MultiArrayLayout.h:56
yarp::os::idl::BareStyle
Definition: BareStyle.h:22
yarp::os::idl::WireReader::expectInt32
std::int32_t expectInt32()
Definition: WireReader.h:99
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::rosmsg::std_msgs::MultiArrayLayout::getType
yarp::os::Type getType() const override
Definition: MultiArrayLayout.h:218
yarp::rosmsg::std_msgs::MultiArrayLayout::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: MultiArrayLayout.h:165
yarp::rosmsg::std_msgs::MultiArrayLayout::typeText
static constexpr const char * typeText
Definition: MultiArrayLayout.h:183
yarp::rosmsg::std_msgs::MultiArrayLayout::typeChecksum
static constexpr const char * typeChecksum
Definition: MultiArrayLayout.h:180
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yarp::rosmsg::std_msgs::MultiArrayLayout::data_offset
std::uint32_t data_offset
Definition: MultiArrayLayout.h:59
yarp::rosmsg::std_msgs::MultiArrayLayout::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: MultiArrayLayout.h:76
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