19template <
typename BufferPool>
struct ManagedBuffer {
21 using CondyBuffer = void;
23 ManagedBuffer() =
default;
24 ManagedBuffer(
void *data,
size_t size, BufferPool *pool)
25 : data_(data), size_(size), pool_(pool) {}
26 ManagedBuffer(ManagedBuffer &&other) noexcept
27 : data_(std::exchange(other.data_,
nullptr)),
28 size_(std::exchange(other.size_, 0)),
29 pool_(std::exchange(other.pool_,
nullptr)) {}
30 ManagedBuffer &operator=(ManagedBuffer &&other)
noexcept {
33 data_ = std::exchange(other.data_,
nullptr);
34 size_ = std::exchange(other.size_, 0);
35 pool_ = std::exchange(other.pool_,
nullptr);
40 ~ManagedBuffer() { reset(); }
42 CONDY_DELETE_COPY(ManagedBuffer);
48 void *data() const noexcept {
return data_; }
53 size_t size() const noexcept {
return size_; }
58 void reset() noexcept {
59 if (pool_ !=
nullptr) {
60 pool_->add_buffer_back(data_, size_);
70 bool owns_buffer() const noexcept {
return pool_ !=
nullptr; }
73 void *data_ =
nullptr;
75 BufferPool *pool_ =
nullptr;
The main namespace for the Condy library.
Internal utility classes and functions used by Condy.