YARP
Yet Another Robot Platform
WireReader.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 #ifndef YARP_OS_IDL_WIREREADER_H
10 #define YARP_OS_IDL_WIREREADER_H
11 
12 #include <yarp/conf/numeric.h>
13 
14 #include <yarp/os/Bottle.h>
17 #include <yarp/os/Vocab.h>
19 #include <yarp/os/idl/WireState.h>
20 #include <yarp/os/idl/WireVocab.h>
21 
22 #include <string>
23 
24 namespace yarp {
25 namespace os {
26 namespace idl {
27 
33 {
34 public:
36 
37  ~WireReader();
38 
39  void expectAccept();
40 
41  void accept();
42 
43  void allowGetMode();
44 
45  bool clear();
46 
47  void fail();
48 
49  bool read(WirePortable& obj);
50 
51  bool read(yarp::os::PortReader& obj);
52 
53  bool readNested(WirePortable& obj);
54 
55  bool readNested(yarp::os::PortReader& obj);
56 
57  bool readBool(bool& x);
58 
59  bool readI8(std::int8_t& x);
60 
61  bool readI16(std::int16_t& x);
62 
63  bool readI32(std::int32_t& x);
64 
65  bool readI64(std::int64_t& x);
66 
67  bool readFloat32(yarp::conf::float32_t& x);
68 
69  bool readFloat64(yarp::conf::float64_t& x);
70 
71  bool readVocab(std::int32_t& x);
72 
73 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
74  YARP_DEPRECATED_MSG("Use readI8 instead")
75  bool readByte(std::int8_t& x)
76  {
77  return readI8(x);
78  }
79 
80  YARP_DEPRECATED_MSG("Use readFloat64 instead")
81  bool readDouble(double& x)
82  {
83  return readFloat64(x);
84  }
85 #endif // YARP_NO_DEPRECATED
86 
87  std::int8_t expectInt8()
88  {
89  std::int8_t x;
90  readI8(x);
91  return x;
92  }
93  std::int16_t expectInt16()
94  {
95  std::int16_t x;
96  readI16(x);
97  return x;
98  }
99  std::int32_t expectInt32()
100  {
101  std::int32_t x;
102  readI32(x);
103  return x;
104  }
105 
106  std::int64_t expectInt64()
107  {
108  std::int64_t x;
109  readI64(x);
110  return x;
111  }
112 
114  {
116  readFloat32(x);
117  return x;
118  }
119 
121  {
123  readFloat64(x);
124  return x;
125  }
126 
127 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
128  YARP_DEPRECATED_MSG("Use expectInt32 instead")
129  int expectInt()
130  {
131  return static_cast<int>(expectInt32());
132  }
133 
134  YARP_DEPRECATED_MSG("Use expectFloat64 instead")
135  double expectDouble()
136  {
137  return static_cast<double>(expectFloat64());
138  }
139 #endif // YARP_NO_DEPRECATED
140 
141  bool readString(std::string& str, bool* is_vocab = nullptr);
142 
143  bool readBinary(std::string& str);
144 
145  bool readEnum(std::int32_t& x, yarp::os::idl::WireVocab& converter);
146 
147  bool readListHeader();
148 
149  bool readListHeader(int len);
150 
151  bool readListReturn();
152 
153  int getLength() const
154  {
155  return state->len;
156  }
157 
158  ConnectionWriter& getWriter();
159 
160  bool isValid();
161 
162  bool isError();
163 
164  std::string readTag();
165 
166  void readListBegin(yarp::os::idl::WireState& nstate, std::uint32_t& len);
167 
168  void readSetBegin(yarp::os::idl::WireState& nstate, std::uint32_t& len);
169 
170  void readMapBegin(yarp::os::idl::WireState& nstate, yarp::os::idl::WireState& nstate2, std::uint32_t& len);
171 
172  void readListEnd();
173 
174  void readSetEnd();
175 
176  void readMapEnd();
177 
178  bool noMore();
179 
180  bool getMode() const;
181 
182  bool getIsVocab() const;
183 
184  const std::string& getString() const;
185 
186 private:
187  NullConnectionWriter null_writer;
188  ConnectionReader& reader;
189  WireState baseState;
190  WireState* state;
191  bool flush_if_needed;
192  bool support_get_mode;
193  bool expecting;
194  bool get_is_vocab;
195  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) get_string;
196  bool get_mode;
197 
198 
199  void scanString(std::string& str, bool is_vocab);
200 };
201 
202 } // namespace idl
203 } // namespace os
204 } // namespace yarp
205 
206 
207 #endif // YARP_OS_IDL_WIREREADER_H
yarp::sig::file::read
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:827
yarp::os::idl::WireReader::expectFloat64
yarp::conf::float64_t expectFloat64()
Definition: WireReader.h:120
yarp::os::idl::WireReader::expectFloat32
yarp::conf::float32_t expectFloat32()
Definition: WireReader.h:113
NullConnectionWriter.h
yarp::os::Time::isValid
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:317
numeric.h
YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:339
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::idl::WireReader::expectInt64
std::int64_t expectInt64()
Definition: WireReader.h:106
yarp::os::idl::WireVocab
Definition: WireVocab.h:19
yarp::os::impl::Terminal::readString
std::string readString(bool *eof)
Definition: Terminal.cpp:79
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::NullConnectionWriter
A dummy ConnectionWriter that consumes data without effect.
Definition: NullConnectionWriter.h:25
yarp::os::idl::WirePortable
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:26
WireState.h
yarp::os::idl::WireState
IDL-friendly state.
Definition: WireState.h:22
yarp::conf::float32_t
float float32_t
Definition: numeric.h:50
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::expectInt32
std::int32_t expectInt32()
Definition: WireReader.h:99
YARP_DEPRECATED_MSG
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2883
WireVocab.h
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
Vocab.h
WirePortable.h
NullConnectionReader.h
yarp::os::idl::WireReader::expectInt8
std::int8_t expectInt8()
Definition: WireReader.h:87
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
yarp::os::idl::WireReader::getLength
int getLength() const
Definition: WireReader.h:153
yarp::os::idl::WireReader::expectInt16
std::int16_t expectInt16()
Definition: WireReader.h:93
Bottle.h