YARP
Yet Another Robot Platform
MemoryOutputStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_OS_IMPL_MEMORYOUTPUTSTREAM_H
10 #define YARP_OS_IMPL_MEMORYOUTPUTSTREAM_H
11 
12 #include <yarp/os/Bytes.h>
13 #include <yarp/os/OutputStream.h>
14 
15 #include <cstring>
16 
17 namespace yarp {
18 namespace os {
19 namespace impl {
20 
26 {
27 public:
28  MemoryOutputStream(char* location) :
29  _location(location)
30  {
31  }
32 
34  void write(const yarp::os::Bytes& b) override
35  {
36  memcpy(_location, b.get(), b.length());
37  _location += b.length();
38  }
39 
40  void close() override
41  {
42  }
43 
44  bool isOk() const override
45  {
46  return true;
47  }
48 
49 private:
50  char* _location;
51 };
52 
53 } // namespace impl
54 } // namespace os
55 } // namespace yarp
56 
57 #endif // YARP_OS_IMPL_MEMORYOUTPUTSTREAM_H
yarp::os::OutputStream::write
virtual void write(char ch)
Write a single byte to the stream.
Definition: OutputStream.cpp:17
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
OutputStream.h
yarp::os::impl::MemoryOutputStream::close
void close() override
Terminate the stream.
Definition: MemoryOutputStream.h:40
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::impl::MemoryOutputStream::MemoryOutputStream
MemoryOutputStream(char *location)
Definition: MemoryOutputStream.h:28
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::impl::MemoryOutputStream::isOk
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: MemoryOutputStream.h:44
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
Bytes.h
yarp::os::impl::MemoryOutputStream::write
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
Definition: MemoryOutputStream.h:34
yarp::os::impl::MemoryOutputStream
An OutputStream that writes to a given memory buffer address.
Definition: MemoryOutputStream.h:26