YARP
Yet Another Robot Platform
StringOutputStream.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_STRINGOUTPUTSTREAM_H
8 #define YARP_OS_STRINGOUTPUTSTREAM_H
9 
10 #include <yarp/os/Bytes.h>
11 #include <yarp/os/OutputStream.h>
12 
13 #include <string>
14 
15 namespace yarp {
16 namespace os {
17 
22 {
23 public:
24  using OutputStream::write;
25 
27  {
28  }
29 
30  std::string toString() const
31  {
32  return data;
33  }
34 
35  void reset()
36  {
37  data = "";
38  }
39 
40  void write(const Bytes& b) override
41  {
42  std::string tmp((char*)b.get(), b.length());
43  data += tmp;
44  }
45 
46  void close() override
47  {
48  }
49 
50  bool isOk() const override
51  {
52  return true;
53  }
54 
55  const std::string& str() const
56  {
57  return data;
58  }
59 
60 private:
62 };
63 
64 } // namespace os
65 } // namespace yarp
66 
67 #endif // YARP_OS_STRINGOUTPUTSTREAM_H
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
size_t length() const
Definition: Bytes.cpp:22
const char * get() const
Definition: Bytes.cpp:27
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
virtual void write(char ch)
Write a single byte to the stream.
An OutputStream that produces a string.
bool isOk() const override
Check if the stream is ok or in an error state.
void close() override
Terminate the stream.
void write(const Bytes &b) override
Write a block of bytes to the stream.
const std::string & str() const
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