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