YARP
Yet Another Robot Platform
ConnectionWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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 
138  virtual void appendExternalBlock(const char* data, size_t len) = 0;
139 
146  virtual bool isTextMode() const = 0;
147 
153  virtual bool isBareMode() const = 0;
154 
162  virtual void declareSizes(int argc, int* argv) = 0;
163 
170  virtual void setReplyHandler(PortReader& reader) = 0;
171 
177  virtual void setReference(Portable* obj) = 0;
178 
179 
188  virtual bool convertTextMode() = 0;
189 
190 
195  virtual bool isValid() const = 0;
196 
201  virtual bool isActive() const = 0;
202 
209  virtual bool isError() const = 0;
210 
211 
217  virtual void requestDrop() = 0;
218 
224  virtual bool isNull() const;
225 
226 
232  virtual SizedWriter* getBuffer() const = 0;
233 
234 
235  virtual void appendRawString(const std::string& str)
236  {
237  appendInt32(static_cast<std::int32_t>(str.length()));
238  appendBlock((char*)str.c_str(), str.length());
239  }
240 
247  static ConnectionWriter* createBufferedConnectionWriter();
248 
249  static bool writeToStream(PortWriter& portable, OutputStream& os);
250 };
251 
252 } // namespace os
253 } // namespace yarp
254 
255 #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