YARP
Yet Another Robot Platform
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 
14 namespace yarp {
15 namespace os {
16 
22 {
23 public:
27  explicit ManagedBytes();
28 
34  explicit ManagedBytes(size_t len);
35 
41  ManagedBytes(const Bytes& ext, bool owned = false);
42 
48  ManagedBytes(ManagedBytes&& other) noexcept;
49 
56  ManagedBytes& operator=(ManagedBytes&& other) noexcept;
57 
63  ManagedBytes(const ManagedBytes& alt);
64 
71  const ManagedBytes& operator=(const ManagedBytes& alt);
72 
76  virtual ~ManagedBytes();
77 
83  void allocate(size_t len);
84 
85  bool allocateOnNeed(size_t neededLen, size_t allocateLen);
86 
90  void copy();
91 
95  size_t length() const;
96 
101  size_t used() const;
102 
106  const char* get() const;
107 
111  char* get();
112 
116  void clear();
117 
122  const Bytes& bytes() const;
123 
127  Bytes& bytes();
128 
133  Bytes usedBytes();
134 
135 
145  size_t setUsed(size_t used);
146 
147  size_t resetUsed();
148 
149  bool read(ConnectionReader& reader) override;
150 
151  bool write(ConnectionWriter& writer) const override;
152 
158  bool isOwner() const
159  {
160  return owned;
161  }
162 
163 private:
164  void moveOwnership(ManagedBytes& other);
165 
166  Bytes b;
167  bool owned;
168  size_t use;
169  bool use_set;
170 };
171 
172 } // namespace os
173 } // namespace yarp
174 
175 #endif // YARP_OS_MANAGEDBYTES_H
A simple abstraction for a block of bytes.
Definition: Bytes.h:25
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...
Definition: ManagedBytes.h:22
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:923
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1099
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18