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