YARP
Yet Another Robot Platform
ConnectionWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_CONNECTIONWRITER_H
11 #define YARP_OS_CONNECTIONWRITER_H
12 
13 #include <yarp/conf/numeric.h>
14 
15 #include <yarp/os/api.h>
16 
17 #include <string>
18 
19 namespace yarp {
20 namespace os {
21 class ConnectionReader;
22 class PortReader;
23 class PortWriter;
24 class Portable;
25 class SizedWriter;
26 class OutputStream;
27 } // namespace os
28 } // namespace yarp
29 
30 
31 namespace yarp {
32 namespace os {
33 
40 {
41 public:
45  virtual ~ConnectionWriter();
46 
57  virtual void appendBlock(const char* data, size_t len) = 0;
58 
64  YARP_DEPRECATED_INTERNAL_MSG("Use appendInt32 instead") // Since YARP 3.0.0
65  virtual void appendInt(int data) final
66  {
67  appendInt32(static_cast<std::int32_t>(data));
68  }
69 
74  virtual void appendInt8(std::int8_t data) = 0;
75 
80  virtual void appendInt16(std::int16_t data) = 0;
81 
86  virtual void appendInt32(std::int32_t data) = 0;
87 
92  virtual void appendInt64(std::int64_t data) = 0;
93 
101  YARP_DEPRECATED_INTERNAL_MSG("Use appendFloat64 instead") // Since YARP 3.0.0
102  virtual void appendDouble(double data)
103  {
104  appendFloat64(static_cast<yarp::conf::float64_t>(data));
105  }
106 
113  virtual void appendFloat32(yarp::conf::float32_t data) = 0;
114 
121  virtual void appendFloat64(yarp::conf::float64_t data) = 0;
122 
123 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
124 
130  YARP_DEPRECATED_MSG("Use appendText() instead")
131  virtual void appendString(const char* str, const char terminate = '\n') final
132  {
133  appendText({str}, terminate);
134  }
135 #endif
136 
146  virtual void appendText(const std::string& str, const char terminate = '\n') = 0;
147 
148 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2
149  YARP_DEPRECATED_MSG("Use appendString() instead")
150  virtual void appendRawString(const std::string& str) final
151  {
152  appendString(str);
153  }
154 #endif
155 
165  void appendString(const std::string& str)
166  {
167  appendInt32(static_cast<std::int32_t>(str.length()));
168  appendBlock((char*)str.c_str(), str.length());
169  }
170 
178  virtual void appendExternalBlock(const char* data, size_t len) = 0;
179 
186  virtual bool isTextMode() const = 0;
187 
193  virtual bool isBareMode() const = 0;
194 
202  virtual void declareSizes(int argc, int* argv) = 0;
203 
210  virtual void setReplyHandler(PortReader& reader) = 0;
211 
217  virtual void setReference(Portable* obj) = 0;
218 
219 
228  virtual bool convertTextMode() = 0;
229 
230 
235  virtual bool isValid() const = 0;
236 
241  virtual bool isActive() const = 0;
242 
249  virtual bool isError() const = 0;
250 
251 
257  virtual void requestDrop() = 0;
258 
264  virtual bool isNull() const;
265 
266 
272  virtual SizedWriter* getBuffer() const = 0;
273 
280  static ConnectionWriter* createBufferedConnectionWriter();
281 
282  static bool writeToStream(PortWriter& portable, OutputStream& os);
283 };
284 
285 } // namespace os
286 } // namespace yarp
287 
288 #endif // YARP_OS_CONNECTIONWRITER_H
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:28
STL namespace.
#define YARP_OS_API
Definition: api.h:19
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:26
The main, catch-all namespace for YARP.
Definition: numeric.h:47
An interface for writing to a network connection.
void appendString(const std::string &str)
Send a string to the network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:27
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:24
double float64_t
Definition: numeric.h:51
float float32_t
Definition: numeric.h:50
#define YARP_DEPRECATED_INTERNAL_MSG(X)
Definition: api.h:139
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:35
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2852
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:309