YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ManagedBytes.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_MANAGEDBYTES_H
8#define YARP_OS_MANAGEDBYTES_H
9
10#include <yarp/os/Bytes.h>
11#include <yarp/os/Network.h>
12#include <yarp/os/Portable.h>
13
14namespace yarp::os {
15
21{
22public:
26 explicit ManagedBytes();
27
33 explicit ManagedBytes(size_t len);
34
40 ManagedBytes(const Bytes& ext, bool owned = false);
41
47 ManagedBytes(ManagedBytes&& other) noexcept;
48
55 ManagedBytes& operator=(ManagedBytes&& other) noexcept;
56
63
70 const ManagedBytes& operator=(const ManagedBytes& alt);
71
75 virtual ~ManagedBytes();
76
82 void allocate(size_t len);
83
84 bool allocateOnNeed(size_t neededLen, size_t allocateLen);
85
89 void copy();
90
94 size_t length() const;
95
100 size_t used() const;
101
105 const char* get() const;
106
110 char* get();
111
115 void clear();
116
121 const Bytes& bytes() const;
122
126 Bytes& bytes();
127
132 Bytes usedBytes();
133
134
144 size_t setUsed(size_t used);
145
146 size_t resetUsed();
147
148 bool read(ConnectionReader& reader) override;
149
150 bool write(ConnectionWriter& writer) const override;
151
157 bool isOwner() const
158 {
159 return owned;
160 }
161
162private:
163 void moveOwnership(ManagedBytes& other);
164
165 Bytes b;
166 bool owned;
167 size_t use;
168 bool use_set;
169};
170
171} // namespace yarp::os
172
173#endif // YARP_OS_MANAGEDBYTES_H
A mini-server for performing network communication in the background.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
An interface for reading from a network connection.
An interface for writing to a network connection.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
An interface to the operating system, including Port based communication.
#define YARP_os_API
Definition api.h:18