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