YARP
Yet Another Robot Platform
String.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 "std_msgs/String" msg definition:
12 // string data
13 // Instances of this class can be read and written with YARP ports,
14 // using a ROS-compatible format.
15 
16 #ifndef YARP_ROSMSG_std_msgs_String_h
17 #define YARP_ROSMSG_std_msgs_String_h
18 
19 #include <yarp/os/Wire.h>
20 #include <yarp/os/Type.h>
21 #include <yarp/os/idl/WireTypes.h>
22 #include <string>
23 #include <vector>
24 
25 namespace yarp {
26 namespace rosmsg {
27 namespace std_msgs {
28 
30 {
31 public:
32  std::string data;
33 
34  String() :
35  data("")
36  {
37  }
38 
39  void clear()
40  {
41  // *** data ***
42  data = "";
43  }
44 
45  bool readBare(yarp::os::ConnectionReader& connection) override
46  {
47  // *** data ***
48  int len = connection.expectInt32();
49  data.resize(len);
50  if (!connection.expectBlock((char*)data.c_str(), len)) {
51  return false;
52  }
53 
54  return !connection.isError();
55  }
56 
57  bool readBottle(yarp::os::ConnectionReader& connection) override
58  {
59  connection.convertTextMode();
60  yarp::os::idl::WireReader reader(connection);
61  if (!reader.readListHeader(1)) {
62  return false;
63  }
64 
65  // *** data ***
66  if (!reader.readString(data)) {
67  return false;
68  }
69 
70  return !connection.isError();
71  }
72 
74  bool read(yarp::os::ConnectionReader& connection) override
75  {
76  return (connection.isBareMode() ? readBare(connection)
77  : readBottle(connection));
78  }
79 
80  bool writeBare(yarp::os::ConnectionWriter& connection) const override
81  {
82  // *** data ***
83  connection.appendInt32(data.length());
84  connection.appendExternalBlock((char*)data.c_str(), data.length());
85 
86  return !connection.isError();
87  }
88 
89  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
90  {
91  connection.appendInt32(BOTTLE_TAG_LIST);
92  connection.appendInt32(1);
93 
94  // *** data ***
95  connection.appendInt32(BOTTLE_TAG_STRING);
96  connection.appendInt32(data.length());
97  connection.appendExternalBlock((char*)data.c_str(), data.length());
98 
99  connection.convertTextMode();
100  return !connection.isError();
101  }
102 
104  bool write(yarp::os::ConnectionWriter& connection) const override
105  {
106  return (connection.isBareMode() ? writeBare(connection)
107  : writeBottle(connection));
108  }
109 
110  // This class will serialize ROS style or YARP style depending on protocol.
111  // If you need to force a serialization style, use one of these classes:
114 
115  // The name for this message, ROS will need this
116  static constexpr const char* typeName = "std_msgs/String";
117 
118  // The checksum for this message, ROS will need this
119  static constexpr const char* typeChecksum = "992ce8a1687cec8c8bd883ec73ca41d1";
120 
121  // The source text for this message, ROS will need this
122  static constexpr const char* typeText = "\
123 string data\n\
124 ";
125 
126  yarp::os::Type getType() const override
127  {
129  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
130  typ.addProperty("message_definition", yarp::os::Value(typeText));
131  return typ;
132  }
133 };
134 
135 } // namespace std_msgs
136 } // namespace rosmsg
137 } // namespace yarp
138 
139 #endif // YARP_ROSMSG_std_msgs_String_h
yarp::os::idl::WireReader::readString
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:339
yarp::rosmsg::std_msgs::String::typeText
static constexpr const char * typeText
Definition: String.h:122
WireTypes.h
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
yarp::os::idl::BottleStyle
Definition: BottleStyle.h:22
yarp::os::Type
Definition: Type.h:24
yarp::rosmsg::std_msgs::String::writeBottle
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: String.h:89
yarp::os::idl::WirePortable::read
virtual bool read(yarp::os::idl::WireReader &reader)
Definition: WirePortable.cpp:14
yarp::rosmsg::std_msgs::String::readBare
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: String.h:45
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::std_msgs::String
Definition: String.h:30
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::rosmsg::std_msgs::String::typeChecksum
static constexpr const char * typeChecksum
Definition: String.h:119
yarp::os::Type::byName
static Type byName(const char *name)
Definition: Type.cpp:174
yarp::rosmsg::std_msgs::String::String
String()
Definition: String.h:34
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::Type::addProperty
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:137
Type.h
std_msgs
Definition: Bool.h:22
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::rosmsg::std_msgs::String::data
std::string data
Definition: String.h:32
yarp::rosmsg::std_msgs::String::typeName
static constexpr const char * typeName
Definition: String.h:116
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::std_msgs::String::write
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: String.h:104
yarp::rosmsg::std_msgs::String::writeBare
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: String.h:80
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::std_msgs::String::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: String.h:74
yarp::rosmsg::std_msgs::String::bottleStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::std_msgs::String > bottleStyle
Definition: String.h:113
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::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::std_msgs::String::readBottle
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: String.h:57
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::rosmsg::std_msgs::String::clear
void clear()
Definition: String.h:39
yarp::rosmsg::std_msgs::String::rosStyle
yarp::os::idl::BareStyle< yarp::rosmsg::std_msgs::String > rosStyle
Definition: String.h:112
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::std_msgs::String::getType
yarp::os::Type getType() const override
Definition: String.h:126
yarp::os::idl::WireReader::readListHeader
bool readListHeader()
Definition: WireReader.cpp:470
yarp::os::idl::WirePortable::write
virtual bool write(const yarp::os::idl::WireWriter &writer) const
Definition: WirePortable.cpp:20