YARP
Yet Another Robot Platform
ManagedBytes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_MANAGEDBYTES_H
11 #define YARP_OS_MANAGEDBYTES_H
12 
13 #include <yarp/os/Bytes.h>
14 #include <yarp/os/Network.h>
15 #include <yarp/os/Portable.h>
16 
17 namespace yarp {
18 namespace os {
19 
25 {
26 public:
30  explicit ManagedBytes();
31 
37  explicit ManagedBytes(size_t len);
38 
44  ManagedBytes(const Bytes& ext, bool owned = false);
45 
51  ManagedBytes(ManagedBytes&& other) noexcept;
52 
59  ManagedBytes& operator=(ManagedBytes&& other) noexcept;
60 
66  ManagedBytes(const ManagedBytes& alt);
67 
74  const ManagedBytes& operator=(const ManagedBytes& alt);
75 
79  virtual ~ManagedBytes();
80 
86  void allocate(size_t len);
87 
88  bool allocateOnNeed(size_t neededLen, size_t allocateLen);
89 
93  void copy();
94 
98  size_t length() const;
99 
104  size_t used() const;
105 
109  const char* get() const;
110 
114  char* get();
115 
119  void clear();
120 
125  const Bytes& bytes() const;
126 
130  Bytes& bytes();
131 
136  Bytes usedBytes();
137 
138 
148  size_t setUsed(size_t used);
149 
150  size_t resetUsed();
151 
152  bool read(ConnectionReader& reader) override;
153 
154  bool write(ConnectionWriter& writer) const override;
155 
161  bool isOwner() const
162  {
163  return owned;
164  }
165 
166 private:
167  void moveOwnership(ManagedBytes& other);
168 
169  Bytes b;
170  bool owned;
171  size_t use;
172  bool use_set;
173 };
174 
175 } // namespace os
176 } // namespace yarp
177 
178 #endif // YARP_OS_MANAGEDBYTES_H
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
Network.h
yarp::sig::file::read
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:827
yarp::os::ManagedBytes::isOwner
bool isOwner() const
Definition: ManagedBytes.h:161
Portable.h
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::ManagedBytes
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
Definition: ManagedBytes.h:25
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
Bytes.h
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971