YARP
Yet Another Robot Platform
KeyValue.h
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 // This is an automatically generated file.
10 
11 // Generated from the following "diagnostic_msgs/KeyValue" msg definition:
12 // string key # what to label this value when viewing
13 // string value # a value to track over time
14 // Instances of this class can be read and written with YARP ports,
15 // using a ROS-compatible format.
16 
17 #ifndef YARP_ROSMSG_diagnostic_msgs_KeyValue_h
18 #define YARP_ROSMSG_diagnostic_msgs_KeyValue_h
19 
20 #include <yarp/os/Wire.h>
21 #include <yarp/os/Type.h>
22 #include <yarp/os/idl/WireTypes.h>
23 #include <string>
24 #include <vector>
25 
26 namespace yarp {
27 namespace rosmsg {
28 namespace diagnostic_msgs {
29 
31 {
32 public:
33  std::string key;
34  std::string value;
35 
37  key(""),
38  value("")
39  {
40  }
41 
42  void clear()
43  {
44  // *** key ***
45  key = "";
46 
47  // *** value ***
48  value = "";
49  }
50 
51  bool readBare(yarp::os::ConnectionReader& connection) override
52  {
53  // *** key ***
54  int len = connection.expectInt32();
55  key.resize(len);
56  if (!connection.expectBlock((char*)key.c_str(), len)) {
57  return false;
58  }
59 
60  // *** value ***
61  len = connection.expectInt32();
62  value.resize(len);
63  if (!connection.expectBlock((char*)value.c_str(), len)) {
64  return false;
65  }
66 
67  return !connection.isError();
68  }
69 
70  bool readBottle(yarp::os::ConnectionReader& connection) override
71  {
72  connection.convertTextMode();
73  yarp::os::idl::WireReader reader(connection);
74  if (!reader.readListHeader(2)) {
75  return false;
76  }
77 
78  // *** key ***
79  if (!reader.readString(key)) {
80  return false;
81  }
82 
83  // *** value ***
84  if (!reader.readString(value)) {
85  return false;
86  }
87 
88  return !connection.isError();
89  }
90 
92  bool read(yarp::os::ConnectionReader& connection) override
93  {
94  return (connection.isBareMode() ? readBare(connection)
95  : readBottle(connection));
96  }
97 
98  bool writeBare(yarp::os::ConnectionWriter& connection) const override
99  {
100  // *** key ***
101  connection.appendInt32(key.length());
102  connection.appendExternalBlock((char*)key.c_str(), key.length());
103 
104  // *** value ***
105  connection.appendInt32(value.length());
106  connection.appendExternalBlock((char*)value.c_str(), value.length());
107 
108  return !connection.isError();
109  }
110 
111  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
112  {
113  connection.appendInt32(BOTTLE_TAG_LIST);
114  connection.appendInt32(2);
115 
116  // *** key ***
117  connection.appendInt32(BOTTLE_TAG_STRING);
118  connection.appendInt32(key.length());
119  connection.appendExternalBlock((char*)key.c_str(), key.length());
120 
121  // *** value ***
122  connection.appendInt32(BOTTLE_TAG_STRING);
123  connection.appendInt32(value.length());
124  connection.appendExternalBlock((char*)value.c_str(), value.length());
125 
126  connection.convertTextMode();
127  return !connection.isError();
128  }
129 
131  bool write(yarp::os::ConnectionWriter& connection) const override
132  {
133  return (connection.isBareMode() ? writeBare(connection)
134  : writeBottle(connection));
135  }
136 
137  // This class will serialize ROS style or YARP style depending on protocol.
138  // If you need to force a serialization style, use one of these classes:
141 
142  // The name for this message, ROS will need this
143  static constexpr const char* typeName = "diagnostic_msgs/KeyValue";
144 
145  // The checksum for this message, ROS will need this
146  static constexpr const char* typeChecksum = "cf57fdc6617a881a88c16e768132149c";
147 
148  // The source text for this message, ROS will need this
149  static constexpr const char* typeText = "\
150 string key # what to label this value when viewing\n\
151 string value # a value to track over time\n\
152 ";
153 
154  yarp::os::Type getType() const override
155  {
157  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
158  typ.addProperty("message_definition", yarp::os::Value(typeText));
159  return typ;
160  }
161 };
162 
163 } // namespace diagnostic_msgs
164 } // namespace rosmsg
165 } // namespace yarp
166 
167 #endif // YARP_ROSMSG_diagnostic_msgs_KeyValue_h
yarp::os::idl::WireReader::readString
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:339
yarp::rosmsg::diagnostic_msgs::KeyValue::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: KeyValue.h:98
yarp::rosmsg::diagnostic_msgs::KeyValue::typeText
static constexpr const char * typeText
Definition: KeyValue.h:149
yarp::rosmsg::diagnostic_msgs::KeyValue::getType
yarp::os::Type getType() const override
Definition: KeyValue.h:154
WireTypes.h
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
yarp::os::idl::BottleStyle
Definition: BottleStyle.h:22
yarp::rosmsg::diagnostic_msgs::KeyValue::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::diagnostic_msgs::KeyValue > bottleStyle
Definition: KeyValue.h:140
yarp::os::Type
Definition: Type.h:24
yarp::os::idl::WirePortable::read
virtual bool read(yarp::os::idl::WireReader &reader)
Definition: WirePortable.cpp:14
yarp::os::ConnectionReader::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
BOTTLE_TAG_STRING
#define BOTTLE_TAG_STRING
Definition: Bottle.h:28
Wire.h
yarp::rosmsg::diagnostic_msgs::KeyValue
Definition: KeyValue.h:31
yarp::rosmsg::diagnostic_msgs::KeyValue::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: KeyValue.h:131
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::rosmsg::diagnostic_msgs::KeyValue::typeName
static constexpr const char * typeName
Definition: KeyValue.h:143
yarp::os::Type::byName
static Type byName(const char *name)
Definition: Type.cpp:174
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::rosmsg::diagnostic_msgs::KeyValue::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: KeyValue.h:51
yarp::os::Type::addProperty
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:137
Type.h
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::rosmsg::diagnostic_msgs::KeyValue::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: KeyValue.h:111
yarp::os::ConnectionReader::isError
virtual bool isError() const =0
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::rosmsg::diagnostic_msgs::KeyValue::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: KeyValue.h:70
yarp::os::idl::WirePortable
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:26
yarp::os::ConnectionWriter::isBareMode
virtual bool isBareMode() const =0
Check if the connection is bare mode.
yarp::rosmsg::diagnostic_msgs::KeyValue::value
std::string value
Definition: KeyValue.h:34
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
yarp::rosmsg::diagnostic_msgs::KeyValue::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::diagnostic_msgs::KeyValue > rosStyle
Definition: KeyValue.h:139
yarp::rosmsg::diagnostic_msgs::KeyValue::typeChecksum
static constexpr const char * typeChecksum
Definition: KeyValue.h:146
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::BareStyle
Definition: BareStyle.h:22
yarp::rosmsg::diagnostic_msgs::KeyValue::KeyValue
KeyValue()
Definition: KeyValue.h:36
diagnostic_msgs
Definition: AddDiagnostics.h:22
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::ConnectionWriter::appendExternalBlock
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
yarp::os::ConnectionReader::expectBlock
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yarp::rosmsg::diagnostic_msgs::KeyValue::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: KeyValue.h:92
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::rosmsg::diagnostic_msgs::KeyValue::key
std::string key
Definition: KeyValue.h:33
yarp::rosmsg::diagnostic_msgs::KeyValue::clear
void clear()
Definition: KeyValue.h:42
yarp::os::idl::WirePortable::write
virtual bool write(const yarp::os::idl::WireWriter &writer) const
Definition: WirePortable.cpp:20