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>
11
12#include <cstring>
13
14namespace yarp::os::impl {
15
21{
22public:
23 MemoryOutputStream(char* location) :
24 _location(location)
25 {
26 }
27
29 void write(const yarp::os::Bytes& b) override
30 {
31 memcpy(_location, b.get(), b.length());
32 _location += b.length();
33 }
34
35 void close() override
36 {
37 }
38
39 bool isOk() const override
40 {
41 return true;
42 }
43
44private:
45 char* _location;
46};
47
48} // namespace yarp::os::impl
49
50#endif // YARP_OS_IMPL_MEMORYOUTPUTSTREAM_H
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
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:21
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 components from which ports and connections are built.