YARP
Yet Another Robot Platform
MemoryOutputStream.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_OS_IMPL_MEMORYOUTPUTSTREAM_H
7 #define YARP_OS_IMPL_MEMORYOUTPUTSTREAM_H
8 
9 #include <yarp/os/Bytes.h>
10 #include <yarp/os/OutputStream.h>
11 
12 #include <cstring>
13 
14 namespace yarp {
15 namespace os {
16 namespace impl {
17 
23 {
24 public:
25  MemoryOutputStream(char* location) :
26  _location(location)
27  {
28  }
29 
31  void write(const yarp::os::Bytes& b) override
32  {
33  memcpy(_location, b.get(), b.length());
34  _location += b.length();
35  }
36 
37  void close() override
38  {
39  }
40 
41  bool isOk() const override
42  {
43  return true;
44  }
45 
46 private:
47  char* _location;
48 };
49 
50 } // namespace impl
51 } // namespace os
52 } // namespace yarp
53 
54 #endif // YARP_OS_IMPL_MEMORYOUTPUTSTREAM_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 writes to a given memory buffer address.
void close() override
Terminate the stream.
bool isOk() const override
Check if the stream is ok or in an error state.
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
The main, catch-all namespace for YARP.
Definition: dirs.h:16