iCub-main
rawValuesDataVectorsMap.cpp
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 // Autogenerated by Thrift Compiler (0.14.1-yarped)
7 //
8 // This is an automatically generated file.
9 // It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
10 
12 
13 namespace iCub {
14 
15 // Constructor with field values
16 rawValuesDataVectorsMap::rawValuesDataVectorsMap(const std::map<std::string, std::vector<std::int32_t>>& vectorsMap) :
17  WirePortable(),
18  vectorsMap(vectorsMap)
19 {
20 }
21 
22 // Read structure on a Wire
23 bool rawValuesDataVectorsMap::read(yarp::os::idl::WireReader& reader)
24 {
25  if (!read_vectorsMap(reader)) {
26  return false;
27  }
28  if (reader.isError()) {
29  return false;
30  }
31  return true;
32 }
33 
34 // Read structure on a Connection
35 bool rawValuesDataVectorsMap::read(yarp::os::ConnectionReader& connection)
36 {
37  yarp::os::idl::WireReader reader(connection);
38  if (!reader.readListHeader(1)) {
39  return false;
40  }
41  if (!read(reader)) {
42  return false;
43  }
44  return true;
45 }
46 
47 // Write structure on a Wire
48 bool rawValuesDataVectorsMap::write(const yarp::os::idl::WireWriter& writer) const
49 {
50  if (!write_vectorsMap(writer)) {
51  return false;
52  }
53  if (writer.isError()) {
54  return false;
55  }
56  return true;
57 }
58 
59 // Write structure on a Connection
60 bool rawValuesDataVectorsMap::write(yarp::os::ConnectionWriter& connection) const
61 {
62  yarp::os::idl::WireWriter writer(connection);
63  if (!writer.writeListHeader(1)) {
64  return false;
65  }
66  if (!write(writer)) {
67  return false;
68  }
69  return true;
70 }
71 
72 // Convert to a printable string
74 {
75  yarp::os::Bottle b;
76  if (!yarp::os::Portable::copyPortable(*this, b)) {
77  return {};
78  }
79  return b.toString();
80 }
81 
82 // read vectorsMap field
83 bool rawValuesDataVectorsMap::read_vectorsMap(yarp::os::idl::WireReader& reader)
84 {
85  if (reader.noMore()) {
86  reader.fail();
87  return false;
88  }
89  size_t _csize;
90  yarp::os::idl::WireState _ktype;
91  yarp::os::idl::WireState _vtype;
92  reader.readMapBegin(_ktype, _vtype, _csize);
93  for (size_t _i = 0; _i < _csize; ++_i) {
94  size_t _msize;
95  yarp::os::idl::WireState _lst;
96  reader.readListBegin(_lst, _msize);
97  std::string _key;
98  if (reader.noMore()) {
99  reader.fail();
100  return false;
101  }
102  if (!reader.readString(_key)) {
103  reader.fail();
104  return false;
105  }
106  std::vector<std::int32_t>& _val = vectorsMap[_key];
107  if (reader.noMore()) {
108  reader.fail();
109  return false;
110  }
111  size_t _csize;
112  yarp::os::idl::WireState _etype;
113  reader.readListBegin(_etype, _csize);
114  // WireReader removes BOTTLE_TAG_LIST from the tag
115  constexpr int expected_tag = ((BOTTLE_TAG_INT32) & (~BOTTLE_TAG_LIST));
116  if constexpr (expected_tag != 0) {
117  if (_csize != 0 && _etype.code != expected_tag) {
118  return false;
119  }
120  }
121  _val.resize(_csize);
122  if (_csize != 0 && !reader.readBlock(reinterpret_cast<char*>(_val.data()), _val.size() * sizeof(std::int32_t))) {
123  return false;
124  }
125  reader.readListEnd();
126  reader.readListEnd();
127  }
128  reader.readMapEnd();
129  return true;
130 }
131 
132 // write vectorsMap field
133 bool rawValuesDataVectorsMap::write_vectorsMap(const yarp::os::idl::WireWriter& writer) const
134 {
135  if (!writer.writeMapBegin(BOTTLE_TAG_STRING, BOTTLE_TAG_LIST | BOTTLE_TAG_INT32, vectorsMap.size())) {
136  return false;
137  }
138  for (const auto& _item : vectorsMap) {
139  if (!writer.writeListBegin(0,2)) {
140  return false;
141  }
142  if (!writer.writeString(_item.first)) {
143  return false;
144  }
145  if (!writer.writeListBegin(BOTTLE_TAG_INT32, _item.second.size())) {
146  return false;
147  }
148  if (!writer.writeBlock(reinterpret_cast<const char*>(_item.second.data()), _item.second.size() * sizeof(std::int32_t))) {
149  return false;
150  }
151  if (!writer.writeListEnd()) {
152  return false;
153  }
154  if (!writer.writeListEnd()) {
155  return false;
156  }
157  }
158  if (!writer.writeMapEnd()) {
159  return false;
160  }
161  return true;
162 }
163 
164 // read (nested) vectorsMap field
165 bool rawValuesDataVectorsMap::nested_read_vectorsMap(yarp::os::idl::WireReader& reader)
166 {
167  if (reader.noMore()) {
168  reader.fail();
169  return false;
170  }
171  size_t _csize;
172  yarp::os::idl::WireState _ktype;
173  yarp::os::idl::WireState _vtype;
174  reader.readMapBegin(_ktype, _vtype, _csize);
175  for (size_t _i = 0; _i < _csize; ++_i) {
176  size_t _msize;
177  yarp::os::idl::WireState _lst;
178  reader.readListBegin(_lst, _msize);
179  std::string _key;
180  if (reader.noMore()) {
181  reader.fail();
182  return false;
183  }
184  if (!reader.readString(_key)) {
185  reader.fail();
186  return false;
187  }
188  std::vector<std::int32_t>& _val = vectorsMap[_key];
189  if (reader.noMore()) {
190  reader.fail();
191  return false;
192  }
193  size_t _csize;
194  yarp::os::idl::WireState _etype;
195  reader.readListBegin(_etype, _csize);
196  // WireReader removes BOTTLE_TAG_LIST from the tag
197  constexpr int expected_tag = ((BOTTLE_TAG_INT32) & (~BOTTLE_TAG_LIST));
198  if constexpr (expected_tag != 0) {
199  if (_csize != 0 && _etype.code != expected_tag) {
200  return false;
201  }
202  }
203  _val.resize(_csize);
204  if (_csize != 0 && !reader.readBlock(reinterpret_cast<char*>(_val.data()), _val.size() * sizeof(std::int32_t))) {
205  return false;
206  }
207  reader.readListEnd();
208  reader.readListEnd();
209  }
210  reader.readMapEnd();
211  return true;
212 }
213 
214 // write (nested) vectorsMap field
215 bool rawValuesDataVectorsMap::nested_write_vectorsMap(const yarp::os::idl::WireWriter& writer) const
216 {
217  if (!writer.writeMapBegin(BOTTLE_TAG_STRING, BOTTLE_TAG_LIST | BOTTLE_TAG_INT32, vectorsMap.size())) {
218  return false;
219  }
220  for (const auto& _item : vectorsMap) {
221  if (!writer.writeListBegin(0,2)) {
222  return false;
223  }
224  if (!writer.writeString(_item.first)) {
225  return false;
226  }
227  if (!writer.writeListBegin(BOTTLE_TAG_INT32, _item.second.size())) {
228  return false;
229  }
230  if (!writer.writeBlock(reinterpret_cast<const char*>(_item.second.data()), _item.second.size() * sizeof(std::int32_t))) {
231  return false;
232  }
233  if (!writer.writeListEnd()) {
234  return false;
235  }
236  if (!writer.writeListEnd()) {
237  return false;
238  }
239  }
240  if (!writer.writeMapEnd()) {
241  return false;
242  }
243  return true;
244 }
245 
246 } // namespace iCub
bool write(const yarp::os::idl::WireWriter &writer) const override
bool read(yarp::os::idl::WireReader &reader) override
std::map< std::string, std::vector< std::int32_t > > vectorsMap
contain a map of vectors of the raw data as <string, vector> the user wanna send from low to higher l...
yarp::sig::Vector & map(yarp::sig::Vector &v, double(op)(double))
Performs a unary operator inplace on each element of a vector.
Definition: Math.cpp:305
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.