YARP
Yet Another Robot Platform
Map2DPathData.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 
11 #include <yarp/dev/Map2DPathData.h>
12 
13 namespace yarp {
14 namespace dev {
15 
16 // Default constructor
18  WirePortable(),
19  waypoints()
20 {
21 }
22 
23 // Constructor with field values
24 Map2DPathData::Map2DPathData(const std::vector<yarp::dev::Nav2D::Map2DLocation>& waypoints) :
25  WirePortable(),
26  waypoints(waypoints)
27 {
28 }
29 
30 // Read structure on a Wire
32 {
33  if (!read_waypoints(reader)) {
34  return false;
35  }
36  return !reader.isError();
37 }
38 
39 // Read structure on a Connection
41 {
42  yarp::os::idl::WireReader reader(connection);
43  if (!reader.readListHeader(1)) {
44  return false;
45  }
46  return read(reader);
47 }
48 
49 // Write structure on a Wire
51 {
52  if (!write_waypoints(writer)) {
53  return false;
54  }
55  return !writer.isError();
56 }
57 
58 // Write structure on a Connection
60 {
61  yarp::os::idl::WireWriter writer(connection);
62  if (!writer.writeListHeader(1)) {
63  return false;
64  }
65  return write(writer);
66 }
67 
68 // Convert to a printable string
69 std::string Map2DPathData::toString() const
70 {
72  b.read(*this);
73  return b.toString();
74 }
75 
76 // Editor: default constructor
78 {
79  group = 0;
80  obj_owned = true;
81  obj = new Map2DPathData;
82  dirty_flags(false);
83  yarp().setOwner(*this);
84 }
85 
86 // Editor: constructor with base class
88 {
89  group = 0;
90  obj_owned = false;
91  edit(obj, false);
92  yarp().setOwner(*this);
93 }
94 
95 // Editor: destructor
97 {
98  if (obj_owned) {
99  delete obj;
100  }
101 }
102 
103 // Editor: edit
105 {
106  if (obj_owned) {
107  delete this->obj;
108  }
109  this->obj = &obj;
110  obj_owned = false;
111  dirty_flags(dirty);
112  return true;
113 }
114 
115 // Editor: validity check
117 {
118  return obj != nullptr;
119 }
120 
121 // Editor: state
123 {
124  return *obj;
125 }
126 
127 // Editor: grouping begin
129 {
130  group++;
131 }
132 
133 // Editor: grouping end
135 {
136  group--;
137  if (group == 0 && is_dirty) {
138  communicate();
139  }
140 }
141 // Editor: waypoints setter
142 void Map2DPathData::Editor::set_waypoints(const std::vector<yarp::dev::Nav2D::Map2DLocation>& waypoints)
143 {
144  will_set_waypoints();
145  obj->waypoints = waypoints;
146  mark_dirty_waypoints();
147  communicate();
148  did_set_waypoints();
149 }
150 
151 // Editor: waypoints setter (list)
153 {
154  will_set_waypoints();
155  obj->waypoints[index] = elem;
156  mark_dirty_waypoints();
157  communicate();
158  did_set_waypoints();
159 }
160 
161 // Editor: waypoints getter
162 const std::vector<yarp::dev::Nav2D::Map2DLocation>& Map2DPathData::Editor::get_waypoints() const
163 {
164  return obj->waypoints;
165 }
166 
167 // Editor: waypoints will_set
169 {
170  return true;
171 }
172 
173 // Editor: waypoints did_set
175 {
176  return true;
177 }
178 
179 // Editor: clean
181 {
182  dirty_flags(false);
183 }
184 
185 // Editor: read
187 {
188  if (!isValid()) {
189  return false;
190  }
191  yarp::os::idl::WireReader reader(connection);
192  reader.expectAccept();
193  if (!reader.readListHeader()) {
194  return false;
195  }
196  int len = reader.getLength();
197  if (len == 0) {
198  yarp::os::idl::WireWriter writer(reader);
199  if (writer.isNull()) {
200  return true;
201  }
202  if (!writer.writeListHeader(1)) {
203  return false;
204  }
205  writer.writeString("send: 'help' or 'patch (param1 val1) (param2 val2)'");
206  return true;
207  }
208  std::string tag;
209  if (!reader.readString(tag)) {
210  return false;
211  }
212  if (tag == "help") {
213  yarp::os::idl::WireWriter writer(reader);
214  if (writer.isNull()) {
215  return true;
216  }
217  if (!writer.writeListHeader(2)) {
218  return false;
219  }
220  if (!writer.writeTag("many", 1, 0)) {
221  return false;
222  }
223  if (reader.getLength() > 0) {
224  std::string field;
225  if (!reader.readString(field)) {
226  return false;
227  }
228  if (field == "waypoints") {
229  if (!writer.writeListHeader(1)) {
230  return false;
231  }
232  if (!writer.writeString("std::vector<yarp::dev::Nav2D::Map2DLocation> waypoints")) {
233  return false;
234  }
235  }
236  }
237  if (!writer.writeListHeader(2)) {
238  return false;
239  }
240  writer.writeString("*** Available fields:");
241  writer.writeString("waypoints");
242  return true;
243  }
244  bool nested = true;
245  bool have_act = false;
246  if (tag != "patch") {
247  if (((len - 1) % 2) != 0) {
248  return false;
249  }
250  len = 1 + ((len - 1) / 2);
251  nested = false;
252  have_act = true;
253  }
254  for (int i = 1; i < len; ++i) {
255  if (nested && !reader.readListHeader(3)) {
256  return false;
257  }
258  std::string act;
259  std::string key;
260  if (have_act) {
261  act = tag;
262  } else if (!reader.readString(act)) {
263  return false;
264  }
265  if (!reader.readString(key)) {
266  return false;
267  }
268  if (key == "waypoints") {
269  will_set_waypoints();
270  if (!obj->nested_read_waypoints(reader)) {
271  return false;
272  }
273  did_set_waypoints();
274  } else {
275  // would be useful to have a fallback here
276  }
277  }
278  reader.accept();
279  yarp::os::idl::WireWriter writer(reader);
280  if (writer.isNull()) {
281  return true;
282  }
283  writer.writeListHeader(1);
284  writer.writeVocab32('o', 'k');
285  return true;
286 }
287 
288 // Editor: write
290 {
291  if (!isValid()) {
292  return false;
293  }
294  yarp::os::idl::WireWriter writer(connection);
295  if (!writer.writeListHeader(dirty_count + 1)) {
296  return false;
297  }
298  if (!writer.writeString("patch")) {
299  return false;
300  }
301  if (is_dirty_waypoints) {
302  if (!writer.writeListHeader(3)) {
303  return false;
304  }
305  if (!writer.writeString("set")) {
306  return false;
307  }
308  if (!writer.writeString("waypoints")) {
309  return false;
310  }
311  if (!obj->nested_write_waypoints(writer)) {
312  return false;
313  }
314  }
315  return !writer.isError();
316 }
317 
318 // Editor: send if possible
319 void Map2DPathData::Editor::communicate()
320 {
321  if (group != 0) {
322  return;
323  }
324  if (yarp().canWrite()) {
325  yarp().write(*this);
326  clean();
327  }
328 }
329 
330 // Editor: mark dirty overall
331 void Map2DPathData::Editor::mark_dirty()
332 {
333  is_dirty = true;
334 }
335 
336 // Editor: waypoints mark_dirty
337 void Map2DPathData::Editor::mark_dirty_waypoints()
338 {
339  if (is_dirty_waypoints) {
340  return;
341  }
342  dirty_count++;
343  is_dirty_waypoints = true;
344  mark_dirty();
345 }
346 
347 // Editor: dirty_flags
348 void Map2DPathData::Editor::dirty_flags(bool flag)
349 {
350  is_dirty = flag;
351  is_dirty_waypoints = flag;
352  dirty_count = flag ? 1 : 0;
353 }
354 
355 // read waypoints field
356 bool Map2DPathData::read_waypoints(yarp::os::idl::WireReader& reader)
357 {
358  waypoints.clear();
359  uint32_t _size0;
360  yarp::os::idl::WireState _etype3;
361  reader.readListBegin(_etype3, _size0);
362  waypoints.resize(_size0);
363  for (size_t _i4 = 0; _i4 < _size0; ++_i4) {
364  if (!reader.readNested(waypoints[_i4])) {
365  reader.fail();
366  return false;
367  }
368  }
369  reader.readListEnd();
370  return true;
371 }
372 
373 // write waypoints field
374 bool Map2DPathData::write_waypoints(const yarp::os::idl::WireWriter& writer) const
375 {
376  if (!writer.writeListBegin(BOTTLE_TAG_LIST, static_cast<uint32_t>(waypoints.size()))) {
377  return false;
378  }
379  for (const auto& _item5 : waypoints) {
380  if (!writer.writeNested(_item5)) {
381  return false;
382  }
383  }
384  if (!writer.writeListEnd()) {
385  return false;
386  }
387  return true;
388 }
389 
390 // read (nested) waypoints field
391 bool Map2DPathData::nested_read_waypoints(yarp::os::idl::WireReader& reader)
392 {
393  waypoints.clear();
394  uint32_t _size6;
395  yarp::os::idl::WireState _etype9;
396  reader.readListBegin(_etype9, _size6);
397  waypoints.resize(_size6);
398  for (size_t _i10 = 0; _i10 < _size6; ++_i10) {
399  if (!reader.readNested(waypoints[_i10])) {
400  reader.fail();
401  return false;
402  }
403  }
404  reader.readListEnd();
405  return true;
406 }
407 
408 // write (nested) waypoints field
409 bool Map2DPathData::nested_write_waypoints(const yarp::os::idl::WireWriter& writer) const
410 {
411  if (!writer.writeListBegin(BOTTLE_TAG_LIST, static_cast<uint32_t>(waypoints.size()))) {
412  return false;
413  }
414  for (const auto& _item11 : waypoints) {
415  if (!writer.writeNested(_item11)) {
416  return false;
417  }
418  }
419  if (!writer.writeListEnd()) {
420  return false;
421  }
422  return true;
423 }
424 
425 } // namespace yarp
426 } // namespace dev
#define BOTTLE_TAG_LIST
Definition: Bottle.h:28
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void set_waypoints(const std::vector< yarp::dev::Nav2D::Map2DLocation > &waypoints)
bool edit(Map2DPathData &obj, bool dirty=true)
const std::vector< yarp::dev::Nav2D::Map2DLocation > & get_waypoints() const
std::string toString() const
bool write(const yarp::os::idl::WireWriter &writer) const override
std::vector< yarp::dev::Nav2D::Map2DLocation > waypoints
Definition: Map2DPathData.h:28
bool read(yarp::os::idl::WireReader &reader) override
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition: Bottle.cpp:240
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
An interface for reading from a network connection.
An interface for writing to a network connection.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:29
IDL-friendly connection reader.
Definition: WireReader.h:30
bool readNested(WirePortable &obj)
Definition: WireReader.cpp:88
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:382
void readListBegin(yarp::os::idl::WireState &nstate, std::uint32_t &len)
Definition: WireReader.cpp:632
IDL-friendly state.
Definition: WireState.h:19
IDL-friendly connection writer.
Definition: WireWriter.h:30
bool writeVocab32(yarp::conf::vocab32_t x) const
Definition: WireWriter.cpp:141
bool writeListHeader(int len) const
Definition: WireWriter.cpp:206
bool writeTag(const char *tag, int split, int len) const
Definition: WireWriter.cpp:164
bool writeListBegin(int tag, std::uint32_t len) const
Definition: WireWriter.cpp:227
bool writeString(const std::string &tag) const
Definition: WireWriter.cpp:189
bool writeNested(const WirePortable &obj) const
Definition: WireWriter.cpp:62
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:314
The main, catch-all namespace for YARP.
Definition: dirs.h:16