YARP
Yet Another Robot Platform
StringOutputStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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_STRINGOUTPUTSTREAM_H
11 #define YARP_OS_STRINGOUTPUTSTREAM_H
12 
13 #include <yarp/os/Bytes.h>
14 #include <yarp/os/OutputStream.h>
15 
16 #include <string>
17 
18 namespace yarp {
19 namespace os {
20 
25 {
26 public:
27  using OutputStream::write;
28 
30  {
31  }
32 
33  std::string toString() const
34  {
35  return data;
36  }
37 
38  void reset()
39  {
40  data = "";
41  }
42 
43  void write(const Bytes& b) override
44  {
45  std::string tmp((char*)b.get(), b.length());
46  data += tmp;
47  }
48 
49  void close() override
50  {
51  }
52 
53  bool isOk() const override
54  {
55  return true;
56  }
57 
58  const std::string& str() const
59  {
60  return data;
61  }
62 
63 private:
65 };
66 
67 } // namespace os
68 } // namespace yarp
69 
70 #endif // YARP_OS_STRINGOUTPUTSTREAM_H
yarp::os::StringOutputStream::write
void write(const Bytes &b) override
Write a block of bytes to the stream.
Definition: StringOutputStream.h:43
yarp::os::OutputStream::write
virtual void write(char ch)
Write a single byte to the stream.
Definition: OutputStream.cpp:17
yarp::os::StringOutputStream::StringOutputStream
StringOutputStream()
Definition: StringOutputStream.h:29
yarp::os::StringOutputStream::toString
std::string toString() const
Definition: StringOutputStream.h:33
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:339
OutputStream.h
yarp::os::StringOutputStream::reset
void reset()
Definition: StringOutputStream.h:38
yarp::os::StringOutputStream
An OutputStream that produces a string.
Definition: StringOutputStream.h:25
yarp::os::Bytes::get
const char * get() const
Definition: Bytes.cpp:30
yarp::os::Bytes::length
size_t length() const
Definition: Bytes.cpp:25
yarp::os::StringOutputStream::isOk
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: StringOutputStream.h:53
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::StringOutputStream::str
const std::string & str() const
Definition: StringOutputStream.h:58
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
Bytes.h
yarp::os::StringOutputStream::close
void close() override
Terminate the stream.
Definition: StringOutputStream.h:49