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 
128  virtual void appendString(const char* str, int terminate = '\n') = 0;
129 
137  virtual void appendExternalBlock(const char* data, size_t len) = 0;
138 
145  virtual bool isTextMode() const = 0;
146 
152  virtual bool isBareMode() const = 0;
153 
161  virtual void declareSizes(int argc, int* argv) = 0;
162 
169  virtual void setReplyHandler(PortReader& reader) = 0;
170 
176  virtual void setReference(Portable* obj) = 0;
177 
178 
187  virtual bool convertTextMode() = 0;
188 
189 
194  virtual bool isValid() const = 0;
195 
200  virtual bool isActive() const = 0;
201 
208  virtual bool isError() const = 0;
209 
210 
216  virtual void requestDrop() = 0;
217 
223  virtual bool isNull() const;
224 
225 
231  virtual SizedWriter* getBuffer() const = 0;
232 
233 
234  virtual void appendRawString(const std::string& str)
235  {
236  appendInt32(static_cast<std::int32_t>(str.length()));
237  appendBlock((char*)str.c_str(), str.length());
238  }
239 
246  static ConnectionWriter* createBufferedConnectionWriter();
247 
248  static bool writeToStream(PortWriter& portable, OutputStream& os);
249 };
250 
251 } // namespace os
252 } // namespace yarp
253 
254 #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
#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.
virtual void appendRawString(const std::string &str)
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
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:308