YARP
Yet Another Robot Platform
Map2DLocationData.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 
15 
16 namespace yarp {
17 namespace dev {
18 
19 // Default constructor
21  WirePortable(),
22  map_id(""),
23  x(0),
24  y(0),
25  theta(0)
26 {
27 }
28 
29 // Constructor with field values
30 Map2DLocationData::Map2DLocationData(const std::string& map_id,
31  const double x,
32  const double y,
33  const double theta) :
34  WirePortable(),
35  map_id(map_id),
36  x(x),
37  y(y),
38  theta(theta)
39 {
40 }
41 
42 // Read structure on a Wire
44 {
45  if (!read_map_id(reader)) {
46  return false;
47  }
48  if (!read_x(reader)) {
49  return false;
50  }
51  if (!read_y(reader)) {
52  return false;
53  }
54  if (!read_theta(reader)) {
55  return false;
56  }
57  return !reader.isError();
58 }
59 
60 // Read structure on a Connection
62 {
63  yarp::os::idl::WireReader reader(connection);
64  if (!reader.readListHeader(4)) {
65  return false;
66  }
67  return read(reader);
68 }
69 
70 // Write structure on a Wire
72 {
73  if (!write_map_id(writer)) {
74  return false;
75  }
76  if (!write_x(writer)) {
77  return false;
78  }
79  if (!write_y(writer)) {
80  return false;
81  }
82  if (!write_theta(writer)) {
83  return false;
84  }
85  return !writer.isError();
86 }
87 
88 // Write structure on a Connection
90 {
91  yarp::os::idl::WireWriter writer(connection);
92  if (!writer.writeListHeader(4)) {
93  return false;
94  }
95  return write(writer);
96 }
97 
98 // Convert to a printable string
99 std::string Map2DLocationData::toString() const
100 {
102  b.read(*this);
103  return b.toString();
104 }
105 
106 // Editor: default constructor
108 {
109  group = 0;
110  obj_owned = true;
111  obj = new Map2DLocationData;
112  dirty_flags(false);
113  yarp().setOwner(*this);
114 }
115 
116 // Editor: constructor with base class
118 {
119  group = 0;
120  obj_owned = false;
121  edit(obj, false);
122  yarp().setOwner(*this);
123 }
124 
125 // Editor: destructor
127 {
128  if (obj_owned) {
129  delete obj;
130  }
131 }
132 
133 // Editor: edit
135 {
136  if (obj_owned) {
137  delete this->obj;
138  }
139  this->obj = &obj;
140  obj_owned = false;
141  dirty_flags(dirty);
142  return true;
143 }
144 
145 // Editor: validity check
147 {
148  return obj != nullptr;
149 }
150 
151 // Editor: state
153 {
154  return *obj;
155 }
156 
157 // Editor: grouping begin
159 {
160  group++;
161 }
162 
163 // Editor: grouping end
165 {
166  group--;
167  if (group == 0 && is_dirty) {
168  communicate();
169  }
170 }
171 // Editor: map_id setter
173 {
174  will_set_map_id();
175  obj->map_id = map_id;
176  mark_dirty_map_id();
177  communicate();
178  did_set_map_id();
179 }
180 
181 // Editor: map_id getter
182 const std::string& Map2DLocationData::Editor::get_map_id() const
183 {
184  return obj->map_id;
185 }
186 
187 // Editor: map_id will_set
189 {
190  return true;
191 }
192 
193 // Editor: map_id did_set
195 {
196  return true;
197 }
198 
199 // Editor: x setter
201 {
202  will_set_x();
203  obj->x = x;
204  mark_dirty_x();
205  communicate();
206  did_set_x();
207 }
208 
209 // Editor: x getter
211 {
212  return obj->x;
213 }
214 
215 // Editor: x will_set
217 {
218  return true;
219 }
220 
221 // Editor: x did_set
223 {
224  return true;
225 }
226 
227 // Editor: y setter
229 {
230  will_set_y();
231  obj->y = y;
232  mark_dirty_y();
233  communicate();
234  did_set_y();
235 }
236 
237 // Editor: y getter
239 {
240  return obj->y;
241 }
242 
243 // Editor: y will_set
245 {
246  return true;
247 }
248 
249 // Editor: y did_set
251 {
252  return true;
253 }
254 
255 // Editor: theta setter
257 {
258  will_set_theta();
259  obj->theta = theta;
260  mark_dirty_theta();
261  communicate();
262  did_set_theta();
263 }
264 
265 // Editor: theta getter
267 {
268  return obj->theta;
269 }
270 
271 // Editor: theta will_set
273 {
274  return true;
275 }
276 
277 // Editor: theta did_set
279 {
280  return true;
281 }
282 
283 // Editor: clean
285 {
286  dirty_flags(false);
287 }
288 
289 // Editor: read
291 {
292  if (!isValid()) {
293  return false;
294  }
295  yarp::os::idl::WireReader reader(connection);
296  reader.expectAccept();
297  if (!reader.readListHeader()) {
298  return false;
299  }
300  int len = reader.getLength();
301  if (len == 0) {
302  yarp::os::idl::WireWriter writer(reader);
303  if (writer.isNull()) {
304  return true;
305  }
306  if (!writer.writeListHeader(1)) {
307  return false;
308  }
309  writer.writeString("send: 'help' or 'patch (param1 val1) (param2 val2)'");
310  return true;
311  }
312  std::string tag;
313  if (!reader.readString(tag)) {
314  return false;
315  }
316  if (tag == "help") {
317  yarp::os::idl::WireWriter writer(reader);
318  if (writer.isNull()) {
319  return true;
320  }
321  if (!writer.writeListHeader(2)) {
322  return false;
323  }
324  if (!writer.writeTag("many", 1, 0)) {
325  return false;
326  }
327  if (reader.getLength() > 0) {
328  std::string field;
329  if (!reader.readString(field)) {
330  return false;
331  }
332  if (field == "map_id") {
333  if (!writer.writeListHeader(1)) {
334  return false;
335  }
336  if (!writer.writeString("std::string map_id")) {
337  return false;
338  }
339  }
340  if (field == "x") {
341  if (!writer.writeListHeader(1)) {
342  return false;
343  }
344  if (!writer.writeString("double x")) {
345  return false;
346  }
347  }
348  if (field == "y") {
349  if (!writer.writeListHeader(1)) {
350  return false;
351  }
352  if (!writer.writeString("double y")) {
353  return false;
354  }
355  }
356  if (field == "theta") {
357  if (!writer.writeListHeader(1)) {
358  return false;
359  }
360  if (!writer.writeString("double theta")) {
361  return false;
362  }
363  }
364  }
365  if (!writer.writeListHeader(5)) {
366  return false;
367  }
368  writer.writeString("*** Available fields:");
369  writer.writeString("map_id");
370  writer.writeString("x");
371  writer.writeString("y");
372  writer.writeString("theta");
373  return true;
374  }
375  bool nested = true;
376  bool have_act = false;
377  if (tag != "patch") {
378  if (((len - 1) % 2) != 0) {
379  return false;
380  }
381  len = 1 + ((len - 1) / 2);
382  nested = false;
383  have_act = true;
384  }
385  for (int i = 1; i < len; ++i) {
386  if (nested && !reader.readListHeader(3)) {
387  return false;
388  }
389  std::string act;
390  std::string key;
391  if (have_act) {
392  act = tag;
393  } else if (!reader.readString(act)) {
394  return false;
395  }
396  if (!reader.readString(key)) {
397  return false;
398  }
399  if (key == "map_id") {
400  will_set_map_id();
401  if (!obj->nested_read_map_id(reader)) {
402  return false;
403  }
404  did_set_map_id();
405  } else if (key == "x") {
406  will_set_x();
407  if (!obj->nested_read_x(reader)) {
408  return false;
409  }
410  did_set_x();
411  } else if (key == "y") {
412  will_set_y();
413  if (!obj->nested_read_y(reader)) {
414  return false;
415  }
416  did_set_y();
417  } else if (key == "theta") {
418  will_set_theta();
419  if (!obj->nested_read_theta(reader)) {
420  return false;
421  }
422  did_set_theta();
423  } else {
424  // would be useful to have a fallback here
425  }
426  }
427  reader.accept();
428  yarp::os::idl::WireWriter writer(reader);
429  if (writer.isNull()) {
430  return true;
431  }
432  writer.writeListHeader(1);
433  writer.writeVocab(yarp::os::createVocab('o', 'k'));
434  return true;
435 }
436 
437 // Editor: write
439 {
440  if (!isValid()) {
441  return false;
442  }
443  yarp::os::idl::WireWriter writer(connection);
444  if (!writer.writeListHeader(dirty_count + 1)) {
445  return false;
446  }
447  if (!writer.writeString("patch")) {
448  return false;
449  }
450  if (is_dirty_map_id) {
451  if (!writer.writeListHeader(3)) {
452  return false;
453  }
454  if (!writer.writeString("set")) {
455  return false;
456  }
457  if (!writer.writeString("map_id")) {
458  return false;
459  }
460  if (!obj->nested_write_map_id(writer)) {
461  return false;
462  }
463  }
464  if (is_dirty_x) {
465  if (!writer.writeListHeader(3)) {
466  return false;
467  }
468  if (!writer.writeString("set")) {
469  return false;
470  }
471  if (!writer.writeString("x")) {
472  return false;
473  }
474  if (!obj->nested_write_x(writer)) {
475  return false;
476  }
477  }
478  if (is_dirty_y) {
479  if (!writer.writeListHeader(3)) {
480  return false;
481  }
482  if (!writer.writeString("set")) {
483  return false;
484  }
485  if (!writer.writeString("y")) {
486  return false;
487  }
488  if (!obj->nested_write_y(writer)) {
489  return false;
490  }
491  }
492  if (is_dirty_theta) {
493  if (!writer.writeListHeader(3)) {
494  return false;
495  }
496  if (!writer.writeString("set")) {
497  return false;
498  }
499  if (!writer.writeString("theta")) {
500  return false;
501  }
502  if (!obj->nested_write_theta(writer)) {
503  return false;
504  }
505  }
506  return !writer.isError();
507 }
508 
509 // Editor: send if possible
510 void Map2DLocationData::Editor::communicate()
511 {
512  if (group != 0) {
513  return;
514  }
515  if (yarp().canWrite()) {
516  yarp().write(*this);
517  clean();
518  }
519 }
520 
521 // Editor: mark dirty overall
522 void Map2DLocationData::Editor::mark_dirty()
523 {
524  is_dirty = true;
525 }
526 
527 // Editor: map_id mark_dirty
528 void Map2DLocationData::Editor::mark_dirty_map_id()
529 {
530  if (is_dirty_map_id) {
531  return;
532  }
533  dirty_count++;
534  is_dirty_map_id = true;
535  mark_dirty();
536 }
537 
538 // Editor: x mark_dirty
539 void Map2DLocationData::Editor::mark_dirty_x()
540 {
541  if (is_dirty_x) {
542  return;
543  }
544  dirty_count++;
545  is_dirty_x = true;
546  mark_dirty();
547 }
548 
549 // Editor: y mark_dirty
550 void Map2DLocationData::Editor::mark_dirty_y()
551 {
552  if (is_dirty_y) {
553  return;
554  }
555  dirty_count++;
556  is_dirty_y = true;
557  mark_dirty();
558 }
559 
560 // Editor: theta mark_dirty
561 void Map2DLocationData::Editor::mark_dirty_theta()
562 {
563  if (is_dirty_theta) {
564  return;
565  }
566  dirty_count++;
567  is_dirty_theta = true;
568  mark_dirty();
569 }
570 
571 // Editor: dirty_flags
572 void Map2DLocationData::Editor::dirty_flags(bool flag)
573 {
574  is_dirty = flag;
575  is_dirty_map_id = flag;
576  is_dirty_x = flag;
577  is_dirty_y = flag;
578  is_dirty_theta = flag;
579  dirty_count = flag ? 4 : 0;
580 }
581 
582 // read map_id field
583 bool Map2DLocationData::read_map_id(yarp::os::idl::WireReader& reader)
584 {
585  if (!reader.readString(map_id)) {
586  reader.fail();
587  return false;
588  }
589  return true;
590 }
591 
592 // write map_id field
593 bool Map2DLocationData::write_map_id(const yarp::os::idl::WireWriter& writer) const
594 {
595  if (!writer.writeString(map_id)) {
596  return false;
597  }
598  return true;
599 }
600 
601 // read (nested) map_id field
602 bool Map2DLocationData::nested_read_map_id(yarp::os::idl::WireReader& reader)
603 {
604  if (!reader.readString(map_id)) {
605  reader.fail();
606  return false;
607  }
608  return true;
609 }
610 
611 // write (nested) map_id field
612 bool Map2DLocationData::nested_write_map_id(const yarp::os::idl::WireWriter& writer) const
613 {
614  if (!writer.writeString(map_id)) {
615  return false;
616  }
617  return true;
618 }
619 
620 // read x field
621 bool Map2DLocationData::read_x(yarp::os::idl::WireReader& reader)
622 {
623  if (!reader.readFloat64(x)) {
624  reader.fail();
625  return false;
626  }
627  return true;
628 }
629 
630 // write x field
631 bool Map2DLocationData::write_x(const yarp::os::idl::WireWriter& writer) const
632 {
633  if (!writer.writeFloat64(x)) {
634  return false;
635  }
636  return true;
637 }
638 
639 // read (nested) x field
640 bool Map2DLocationData::nested_read_x(yarp::os::idl::WireReader& reader)
641 {
642  if (!reader.readFloat64(x)) {
643  reader.fail();
644  return false;
645  }
646  return true;
647 }
648 
649 // write (nested) x field
650 bool Map2DLocationData::nested_write_x(const yarp::os::idl::WireWriter& writer) const
651 {
652  if (!writer.writeFloat64(x)) {
653  return false;
654  }
655  return true;
656 }
657 
658 // read y field
659 bool Map2DLocationData::read_y(yarp::os::idl::WireReader& reader)
660 {
661  if (!reader.readFloat64(y)) {
662  reader.fail();
663  return false;
664  }
665  return true;
666 }
667 
668 // write y field
669 bool Map2DLocationData::write_y(const yarp::os::idl::WireWriter& writer) const
670 {
671  if (!writer.writeFloat64(y)) {
672  return false;
673  }
674  return true;
675 }
676 
677 // read (nested) y field
678 bool Map2DLocationData::nested_read_y(yarp::os::idl::WireReader& reader)
679 {
680  if (!reader.readFloat64(y)) {
681  reader.fail();
682  return false;
683  }
684  return true;
685 }
686 
687 // write (nested) y field
688 bool Map2DLocationData::nested_write_y(const yarp::os::idl::WireWriter& writer) const
689 {
690  if (!writer.writeFloat64(y)) {
691  return false;
692  }
693  return true;
694 }
695 
696 // read theta field
697 bool Map2DLocationData::read_theta(yarp::os::idl::WireReader& reader)
698 {
699  if (!reader.readFloat64(theta)) {
700  reader.fail();
701  return false;
702  }
703  return true;
704 }
705 
706 // write theta field
707 bool Map2DLocationData::write_theta(const yarp::os::idl::WireWriter& writer) const
708 {
709  if (!writer.writeFloat64(theta)) {
710  return false;
711  }
712  return true;
713 }
714 
715 // read (nested) theta field
716 bool Map2DLocationData::nested_read_theta(yarp::os::idl::WireReader& reader)
717 {
718  if (!reader.readFloat64(theta)) {
719  reader.fail();
720  return false;
721  }
722  return true;
723 }
724 
725 // write (nested) theta field
726 bool Map2DLocationData::nested_write_theta(const yarp::os::idl::WireWriter& writer) const
727 {
728  if (!writer.writeFloat64(theta)) {
729  return false;
730  }
731  return true;
732 }
733 
734 } // namespace yarp
735 } // namespace dev
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Map2DLocationData.h
yarp::dev::Map2DLocationData::Editor::state
Map2DLocationData & state()
Definition: Map2DLocationData.cpp:152
yarp::dev::Map2DLocationData::Editor::edit
bool edit(Map2DLocationData &obj, bool dirty=true)
Definition: Map2DLocationData.cpp:134
yarp::dev::Map2DLocationData::Editor::will_set_theta
virtual bool will_set_theta()
Definition: Map2DLocationData.cpp:272
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::Map2DLocationData::Editor::did_set_theta
virtual bool did_set_theta()
Definition: Map2DLocationData.cpp:278
yarp::dev::Map2DLocationData::read
bool read(yarp::os::idl::WireReader &reader) override
Definition: Map2DLocationData.cpp:43
yarp::os::idl::WireWriter::writeFloat64
bool writeFloat64(yarp::conf::float64_t x) const
Definition: WireWriter.cpp:117
yarp::dev::Map2DLocationData::y
double y
Definition: Map2DLocationData.h:32
yarp::dev::Map2DLocationData::Editor::will_set_x
virtual bool will_set_x()
Definition: Map2DLocationData.cpp:216
yarp::dev::Map2DLocationData::Editor::~Editor
~Editor() override
Definition: Map2DLocationData.cpp:126
yarp::dev::Map2DLocationData::Editor::start_editing
void start_editing()
Definition: Map2DLocationData.cpp:158
yarp::os::Time::isValid
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:317
yarp::dev::Map2DLocationData::write
bool write(const yarp::os::idl::WireWriter &writer) const override
Definition: Map2DLocationData.cpp:71
yarp::dev::Map2DLocationData::Editor::get_theta
double get_theta() const
Definition: Map2DLocationData.cpp:266
yarp::os::idl::WireWriter::writeString
bool writeString(const std::string &tag) const
Definition: WireWriter.cpp:166
yarp::dev::Map2DLocationData::Editor::clean
void clean()
Definition: Map2DLocationData.cpp:284
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::Map2DLocationData::theta
double theta
Definition: Map2DLocationData.h:33
yarp::os::idl::WireWriter::writeListHeader
bool writeListHeader(int len) const
Definition: WireWriter.cpp:183
yarp::dev::Map2DLocationData::Editor::did_set_y
virtual bool did_set_y()
Definition: Map2DLocationData.cpp:250
yarp::os::idl::WireWriter
IDL-friendly connection writer.
Definition: WireWriter.h:33
yarp::dev::Map2DLocationData::Editor::set_x
void set_x(const double x)
Definition: Map2DLocationData.cpp:200
yarp::dev::Map2DLocationData::Editor::Editor
Editor()
Definition: Map2DLocationData.cpp:107
yarp::dev::Map2DLocationData::Editor::get_y
double get_y() const
Definition: Map2DLocationData.cpp:238
yarp::dev::Map2DLocationData::toString
std::string toString() const
Definition: Map2DLocationData.cpp:99
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::Map2DLocationData
Definition: Map2DLocationData.h:27
yarp::dev::Map2DLocationData::Editor::get_map_id
const std::string & get_map_id() const
Definition: Map2DLocationData.cpp:182
yarp::dev::Map2DLocationData::Editor::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Map2DLocationData.cpp:290
yarp::dev::Map2DLocationData::Editor::did_set_map_id
virtual bool did_set_map_id()
Definition: Map2DLocationData.cpp:194
yarp::os::idl::WireWriter::writeTag
bool writeTag(const char *tag, int split, int len) const
Definition: WireWriter.cpp:141
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::dev::Map2DLocationData::Editor::set_map_id
void set_map_id(const std::string &map_id)
Definition: Map2DLocationData.cpp:172
yarp::os::idl::WireReader::fail
void fail()
Definition: WireReader.cpp:74
yarp::dev::Map2DLocationData::Editor::isValid
bool isValid() const
Definition: Map2DLocationData.cpp:146
yarp::os::Wire::yarp
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:34
yarp::dev::Map2DLocationData::Editor::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Map2DLocationData.cpp:438
yarp::os::idl::WireWriter::writeVocab
bool writeVocab(std::int32_t x) const
Definition: WireWriter.cpp:124
yarp::dev::Map2DLocationData::Editor::set_theta
void set_theta(const double theta)
Definition: Map2DLocationData.cpp:256
yarp::os::idl::WireReader::accept
void accept()
Definition: WireReader.cpp:49
yarp::dev::Map2DLocationData::Editor::set_y
void set_y(const double y)
Definition: Map2DLocationData.cpp:228
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::dev::Map2DLocationData::Editor::get_x
double get_x() const
Definition: Map2DLocationData.cpp:210
yarp::dev::Map2DLocationData::Editor::did_set_x
virtual bool did_set_x()
Definition: Map2DLocationData.cpp:222
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::dev::Map2DLocationData::Map2DLocationData
Map2DLocationData()
Definition: Map2DLocationData.cpp:20
yarp::dev::Map2DLocationData::x
double x
Definition: Map2DLocationData.h:31
yarp::dev::Map2DLocationData::Editor::stop_editing
void stop_editing()
Definition: Map2DLocationData.cpp:164
yarp::os::idl::WireReader::getLength
int getLength() const
Definition: WireReader.h:153
yarp::dev::Map2DLocationData::Editor::will_set_map_id
virtual bool will_set_map_id()
Definition: Map2DLocationData.cpp:188
yarp::os::idl::WireReader::readFloat64
bool readFloat64(yarp::conf::float64_t &x)
Definition: WireReader.cpp:279
yarp::dev::Map2DLocationData::Editor::will_set_y
virtual bool will_set_y()
Definition: Map2DLocationData.cpp:244
yarp::dev::Map2DLocationData::map_id
std::string map_id
Definition: Map2DLocationData.h:30
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WireReader::isError
bool isError()
Definition: WireReader.cpp:547