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