YARP
Yet Another Robot Platform
SensorMetadata.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 <SensorMetadata.h>
15 
16 // Default constructor
18  WirePortable(),
19  name(""),
20  frameName(""),
21  additionalMetadata("")
22 {
23 }
24 
25 // Constructor with field values
26 SensorMetadata::SensorMetadata(const std::string& name,
27  const std::string& frameName,
28  const std::string& additionalMetadata) :
29  WirePortable(),
30  name(name),
31  frameName(frameName),
32  additionalMetadata(additionalMetadata)
33 {
34 }
35 
36 // Read structure on a Wire
38 {
39  if (!read_name(reader)) {
40  return false;
41  }
42  if (!read_frameName(reader)) {
43  return false;
44  }
45  if (!read_additionalMetadata(reader)) {
46  return false;
47  }
48  return !reader.isError();
49 }
50 
51 // Read structure on a Connection
53 {
54  yarp::os::idl::WireReader reader(connection);
55  if (!reader.readListHeader(3)) {
56  return false;
57  }
58  return read(reader);
59 }
60 
61 // Write structure on a Wire
63 {
64  if (!write_name(writer)) {
65  return false;
66  }
67  if (!write_frameName(writer)) {
68  return false;
69  }
70  if (!write_additionalMetadata(writer)) {
71  return false;
72  }
73  return !writer.isError();
74 }
75 
76 // Write structure on a Connection
78 {
79  yarp::os::idl::WireWriter writer(connection);
80  if (!writer.writeListHeader(3)) {
81  return false;
82  }
83  return write(writer);
84 }
85 
86 // Convert to a printable string
87 std::string SensorMetadata::toString() const
88 {
90  b.read(*this);
91  return b.toString();
92 }
93 
94 // Editor: default constructor
96 {
97  group = 0;
98  obj_owned = true;
99  obj = new SensorMetadata;
100  dirty_flags(false);
101  yarp().setOwner(*this);
102 }
103 
104 // Editor: constructor with base class
106 {
107  group = 0;
108  obj_owned = false;
109  edit(obj, false);
110  yarp().setOwner(*this);
111 }
112 
113 // Editor: destructor
115 {
116  if (obj_owned) {
117  delete obj;
118  }
119 }
120 
121 // Editor: edit
123 {
124  if (obj_owned) {
125  delete this->obj;
126  }
127  this->obj = &obj;
128  obj_owned = false;
129  dirty_flags(dirty);
130  return true;
131 }
132 
133 // Editor: validity check
135 {
136  return obj != nullptr;
137 }
138 
139 // Editor: state
141 {
142  return *obj;
143 }
144 
145 // Editor: grouping begin
147 {
148  group++;
149 }
150 
151 // Editor: grouping end
153 {
154  group--;
155  if (group == 0 && is_dirty) {
156  communicate();
157  }
158 }
159 // Editor: name setter
160 void SensorMetadata::Editor::set_name(const std::string& name)
161 {
162  will_set_name();
163  obj->name = name;
164  mark_dirty_name();
165  communicate();
166  did_set_name();
167 }
168 
169 // Editor: name getter
170 const std::string& SensorMetadata::Editor::get_name() const
171 {
172  return obj->name;
173 }
174 
175 // Editor: name will_set
177 {
178  return true;
179 }
180 
181 // Editor: name did_set
183 {
184  return true;
185 }
186 
187 // Editor: frameName setter
189 {
190  will_set_frameName();
191  obj->frameName = frameName;
192  mark_dirty_frameName();
193  communicate();
194  did_set_frameName();
195 }
196 
197 // Editor: frameName getter
198 const std::string& SensorMetadata::Editor::get_frameName() const
199 {
200  return obj->frameName;
201 }
202 
203 // Editor: frameName will_set
205 {
206  return true;
207 }
208 
209 // Editor: frameName did_set
211 {
212  return true;
213 }
214 
215 // Editor: additionalMetadata setter
217 {
218  will_set_additionalMetadata();
219  obj->additionalMetadata = additionalMetadata;
220  mark_dirty_additionalMetadata();
221  communicate();
222  did_set_additionalMetadata();
223 }
224 
225 // Editor: additionalMetadata getter
227 {
228  return obj->additionalMetadata;
229 }
230 
231 // Editor: additionalMetadata will_set
233 {
234  return true;
235 }
236 
237 // Editor: additionalMetadata did_set
239 {
240  return true;
241 }
242 
243 // Editor: clean
245 {
246  dirty_flags(false);
247 }
248 
249 // Editor: read
251 {
252  if (!isValid()) {
253  return false;
254  }
255  yarp::os::idl::WireReader reader(connection);
256  reader.expectAccept();
257  if (!reader.readListHeader()) {
258  return false;
259  }
260  int len = reader.getLength();
261  if (len == 0) {
262  yarp::os::idl::WireWriter writer(reader);
263  if (writer.isNull()) {
264  return true;
265  }
266  if (!writer.writeListHeader(1)) {
267  return false;
268  }
269  writer.writeString("send: 'help' or 'patch (param1 val1) (param2 val2)'");
270  return true;
271  }
272  std::string tag;
273  if (!reader.readString(tag)) {
274  return false;
275  }
276  if (tag == "help") {
277  yarp::os::idl::WireWriter writer(reader);
278  if (writer.isNull()) {
279  return true;
280  }
281  if (!writer.writeListHeader(2)) {
282  return false;
283  }
284  if (!writer.writeTag("many", 1, 0)) {
285  return false;
286  }
287  if (reader.getLength() > 0) {
288  std::string field;
289  if (!reader.readString(field)) {
290  return false;
291  }
292  if (field == "name") {
293  if (!writer.writeListHeader(1)) {
294  return false;
295  }
296  if (!writer.writeString("std::string name")) {
297  return false;
298  }
299  }
300  if (field == "frameName") {
301  if (!writer.writeListHeader(1)) {
302  return false;
303  }
304  if (!writer.writeString("std::string frameName")) {
305  return false;
306  }
307  }
308  if (field == "additionalMetadata") {
309  if (!writer.writeListHeader(1)) {
310  return false;
311  }
312  if (!writer.writeString("std::string additionalMetadata")) {
313  return false;
314  }
315  }
316  }
317  if (!writer.writeListHeader(4)) {
318  return false;
319  }
320  writer.writeString("*** Available fields:");
321  writer.writeString("name");
322  writer.writeString("frameName");
323  writer.writeString("additionalMetadata");
324  return true;
325  }
326  bool nested = true;
327  bool have_act = false;
328  if (tag != "patch") {
329  if (((len - 1) % 2) != 0) {
330  return false;
331  }
332  len = 1 + ((len - 1) / 2);
333  nested = false;
334  have_act = true;
335  }
336  for (int i = 1; i < len; ++i) {
337  if (nested && !reader.readListHeader(3)) {
338  return false;
339  }
340  std::string act;
341  std::string key;
342  if (have_act) {
343  act = tag;
344  } else if (!reader.readString(act)) {
345  return false;
346  }
347  if (!reader.readString(key)) {
348  return false;
349  }
350  if (key == "name") {
351  will_set_name();
352  if (!obj->nested_read_name(reader)) {
353  return false;
354  }
355  did_set_name();
356  } else if (key == "frameName") {
357  will_set_frameName();
358  if (!obj->nested_read_frameName(reader)) {
359  return false;
360  }
361  did_set_frameName();
362  } else if (key == "additionalMetadata") {
363  will_set_additionalMetadata();
364  if (!obj->nested_read_additionalMetadata(reader)) {
365  return false;
366  }
367  did_set_additionalMetadata();
368  } else {
369  // would be useful to have a fallback here
370  }
371  }
372  reader.accept();
373  yarp::os::idl::WireWriter writer(reader);
374  if (writer.isNull()) {
375  return true;
376  }
377  writer.writeListHeader(1);
378  writer.writeVocab(yarp::os::createVocab('o', 'k'));
379  return true;
380 }
381 
382 // Editor: write
384 {
385  if (!isValid()) {
386  return false;
387  }
388  yarp::os::idl::WireWriter writer(connection);
389  if (!writer.writeListHeader(dirty_count + 1)) {
390  return false;
391  }
392  if (!writer.writeString("patch")) {
393  return false;
394  }
395  if (is_dirty_name) {
396  if (!writer.writeListHeader(3)) {
397  return false;
398  }
399  if (!writer.writeString("set")) {
400  return false;
401  }
402  if (!writer.writeString("name")) {
403  return false;
404  }
405  if (!obj->nested_write_name(writer)) {
406  return false;
407  }
408  }
409  if (is_dirty_frameName) {
410  if (!writer.writeListHeader(3)) {
411  return false;
412  }
413  if (!writer.writeString("set")) {
414  return false;
415  }
416  if (!writer.writeString("frameName")) {
417  return false;
418  }
419  if (!obj->nested_write_frameName(writer)) {
420  return false;
421  }
422  }
423  if (is_dirty_additionalMetadata) {
424  if (!writer.writeListHeader(3)) {
425  return false;
426  }
427  if (!writer.writeString("set")) {
428  return false;
429  }
430  if (!writer.writeString("additionalMetadata")) {
431  return false;
432  }
433  if (!obj->nested_write_additionalMetadata(writer)) {
434  return false;
435  }
436  }
437  return !writer.isError();
438 }
439 
440 // Editor: send if possible
441 void SensorMetadata::Editor::communicate()
442 {
443  if (group != 0) {
444  return;
445  }
446  if (yarp().canWrite()) {
447  yarp().write(*this);
448  clean();
449  }
450 }
451 
452 // Editor: mark dirty overall
453 void SensorMetadata::Editor::mark_dirty()
454 {
455  is_dirty = true;
456 }
457 
458 // Editor: name mark_dirty
459 void SensorMetadata::Editor::mark_dirty_name()
460 {
461  if (is_dirty_name) {
462  return;
463  }
464  dirty_count++;
465  is_dirty_name = true;
466  mark_dirty();
467 }
468 
469 // Editor: frameName mark_dirty
470 void SensorMetadata::Editor::mark_dirty_frameName()
471 {
472  if (is_dirty_frameName) {
473  return;
474  }
475  dirty_count++;
476  is_dirty_frameName = true;
477  mark_dirty();
478 }
479 
480 // Editor: additionalMetadata mark_dirty
481 void SensorMetadata::Editor::mark_dirty_additionalMetadata()
482 {
483  if (is_dirty_additionalMetadata) {
484  return;
485  }
486  dirty_count++;
487  is_dirty_additionalMetadata = true;
488  mark_dirty();
489 }
490 
491 // Editor: dirty_flags
492 void SensorMetadata::Editor::dirty_flags(bool flag)
493 {
494  is_dirty = flag;
495  is_dirty_name = flag;
496  is_dirty_frameName = flag;
497  is_dirty_additionalMetadata = flag;
498  dirty_count = flag ? 3 : 0;
499 }
500 
501 // read name field
502 bool SensorMetadata::read_name(yarp::os::idl::WireReader& reader)
503 {
504  if (!reader.readString(name)) {
505  reader.fail();
506  return false;
507  }
508  return true;
509 }
510 
511 // write name field
512 bool SensorMetadata::write_name(const yarp::os::idl::WireWriter& writer) const
513 {
514  if (!writer.writeString(name)) {
515  return false;
516  }
517  return true;
518 }
519 
520 // read (nested) name field
521 bool SensorMetadata::nested_read_name(yarp::os::idl::WireReader& reader)
522 {
523  if (!reader.readString(name)) {
524  reader.fail();
525  return false;
526  }
527  return true;
528 }
529 
530 // write (nested) name field
531 bool SensorMetadata::nested_write_name(const yarp::os::idl::WireWriter& writer) const
532 {
533  if (!writer.writeString(name)) {
534  return false;
535  }
536  return true;
537 }
538 
539 // read frameName field
540 bool SensorMetadata::read_frameName(yarp::os::idl::WireReader& reader)
541 {
542  if (!reader.readString(frameName)) {
543  reader.fail();
544  return false;
545  }
546  return true;
547 }
548 
549 // write frameName field
550 bool SensorMetadata::write_frameName(const yarp::os::idl::WireWriter& writer) const
551 {
552  if (!writer.writeString(frameName)) {
553  return false;
554  }
555  return true;
556 }
557 
558 // read (nested) frameName field
559 bool SensorMetadata::nested_read_frameName(yarp::os::idl::WireReader& reader)
560 {
561  if (!reader.readString(frameName)) {
562  reader.fail();
563  return false;
564  }
565  return true;
566 }
567 
568 // write (nested) frameName field
569 bool SensorMetadata::nested_write_frameName(const yarp::os::idl::WireWriter& writer) const
570 {
571  if (!writer.writeString(frameName)) {
572  return false;
573  }
574  return true;
575 }
576 
577 // read additionalMetadata field
578 bool SensorMetadata::read_additionalMetadata(yarp::os::idl::WireReader& reader)
579 {
580  if (!reader.readString(additionalMetadata)) {
581  reader.fail();
582  return false;
583  }
584  return true;
585 }
586 
587 // write additionalMetadata field
588 bool SensorMetadata::write_additionalMetadata(const yarp::os::idl::WireWriter& writer) const
589 {
590  if (!writer.writeString(additionalMetadata)) {
591  return false;
592  }
593  return true;
594 }
595 
596 // read (nested) additionalMetadata field
597 bool SensorMetadata::nested_read_additionalMetadata(yarp::os::idl::WireReader& reader)
598 {
599  if (!reader.readString(additionalMetadata)) {
600  reader.fail();
601  return false;
602  }
603  return true;
604 }
605 
606 // write (nested) additionalMetadata field
607 bool SensorMetadata::nested_write_additionalMetadata(const yarp::os::idl::WireWriter& writer) const
608 {
609  if (!writer.writeString(additionalMetadata)) {
610  return false;
611  }
612  return true;
613 }
SensorMetadata::Editor::Editor
Editor()
Definition: SensorMetadata.cpp:95
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
SensorMetadata::toString
std::string toString() const
Definition: SensorMetadata.cpp:87
SensorMetadata::Editor::did_set_frameName
virtual bool did_set_frameName()
Definition: SensorMetadata.cpp:210
SensorMetadata.h
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
SensorMetadata::Editor::get_frameName
const std::string & get_frameName() const
Definition: SensorMetadata.cpp:198
SensorMetadata::frameName
std::string frameName
Definition: SensorMetadata.h:26
SensorMetadata::Editor::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: SensorMetadata.cpp:250
SensorMetadata::Editor::state
SensorMetadata & state()
Definition: SensorMetadata.cpp:140
yarp::os::Time::isValid
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:317
SensorMetadata::Editor::set_frameName
void set_frameName(const std::string &frameName)
Definition: SensorMetadata.cpp:188
yarp::os::idl::WireWriter::writeString
bool writeString(const std::string &tag) const
Definition: WireWriter.cpp:166
SensorMetadata::Editor::will_set_name
virtual bool will_set_name()
Definition: SensorMetadata.cpp:176
SensorMetadata::Editor::set_additionalMetadata
void set_additionalMetadata(const std::string &additionalMetadata)
Definition: SensorMetadata.cpp:216
SensorMetadata::Editor::stop_editing
void stop_editing()
Definition: SensorMetadata.cpp:152
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::os::idl::WireWriter::writeListHeader
bool writeListHeader(int len) const
Definition: WireWriter.cpp:183
SensorMetadata::additionalMetadata
std::string additionalMetadata
Definition: SensorMetadata.h:27
yarp::os::idl::WireWriter
IDL-friendly connection writer.
Definition: WireWriter.h:33
SensorMetadata::Editor::clean
void clean()
Definition: SensorMetadata.cpp:244
SensorMetadata::Editor::set_name
void set_name(const std::string &name)
Definition: SensorMetadata.cpp:160
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
SensorMetadata::Editor::get_additionalMetadata
const std::string & get_additionalMetadata() const
Definition: SensorMetadata.cpp:226
SensorMetadata::Editor::edit
bool edit(SensorMetadata &obj, bool dirty=true)
Definition: SensorMetadata.cpp:122
SensorMetadata::Editor::get_name
const std::string & get_name() const
Definition: SensorMetadata.cpp:170
SensorMetadata::Editor::will_set_additionalMetadata
virtual bool will_set_additionalMetadata()
Definition: SensorMetadata.cpp:232
SensorMetadata::Editor::did_set_name
virtual bool did_set_name()
Definition: SensorMetadata.cpp:182
SensorMetadata::name
std::string name
Definition: SensorMetadata.h:25
yarp::os::idl::WireWriter::writeTag
bool writeTag(const char *tag, int split, int len) const
Definition: WireWriter.cpp:141
SensorMetadata::Editor::~Editor
~Editor() override
Definition: SensorMetadata.cpp:114
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
SensorMetadata
Definition: SensorMetadata.h:22
SensorMetadata::Editor::isValid
bool isValid() const
Definition: SensorMetadata.cpp:134
yarp::os::idl::WireWriter::writeVocab
bool writeVocab(std::int32_t x) const
Definition: WireWriter.cpp:124
SensorMetadata::Editor::did_set_additionalMetadata
virtual bool did_set_additionalMetadata()
Definition: SensorMetadata.cpp:238
yarp::os::idl::WireReader::accept
void accept()
Definition: WireReader.cpp:49
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
SensorMetadata::SensorMetadata
SensorMetadata()
Definition: SensorMetadata.cpp:17
SensorMetadata::read
bool read(yarp::os::idl::WireReader &reader) override
Definition: SensorMetadata.cpp:37
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
SensorMetadata::Editor::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: SensorMetadata.cpp:383
SensorMetadata::Editor::start_editing
void start_editing()
Definition: SensorMetadata.cpp:146
SensorMetadata::write
bool write(const yarp::os::idl::WireWriter &writer) const override
Definition: SensorMetadata.cpp:62
SensorMetadata::Editor::will_set_frameName
virtual bool will_set_frameName()
Definition: SensorMetadata.cpp:204
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WireReader::isError
bool isError()
Definition: WireReader.cpp:547