template class EE::System::TScopedBuffer

Overview

Keep a pointer to a buffer and release it when the ScopedBuffer goes out of scope. More…

#include <scopedbuffer.hpp>

template <typename T>
class TScopedBuffer: private EE::NonCopyable {
public:
    // construction

    TScopedBuffer();
    TScopedBuffer(std::size_t length);
    TScopedBuffer(T* data, std::size_t length);
    ~TScopedBuffer();

    // methods

    void clear();
    T& operator[](std::size_t i) const;
    bool operator()() const;
    T* get() const;
    void swap(TScopedBuffer<T>& b);
    void reset(T* p = 0, const std::size_t& size = 0);
    void reset(const std::size_t& size = 0);
    void reset(const T* p = 0, const std::size_t& size = 0);
    bool isEmpty() const;
    const std::size_t& size() const;
    const std::size_t& length() const;
};

Detailed Documentation

Keep a pointer to a buffer and release it when the ScopedBuffer goes out of scope.

The TScopedBuffer class template stores a pointer to a dynamically allocated array. (Dynamically allocated arrays are allocated with the C++ new[] expression.) The array pointed to is guaranteed to be deleted, either on destruction of the TScopedBuffer, or via an explicit reset.

The TScopedBuffer template is a simple solution for simple needs. It supplies a basic “resource acquisition is initialization” facility, without shared-ownership or transfer-of-ownership semantics. Both its name and enforcement of semantics (by being NonCopyable) signal its intent to retain ownership solely within the current scope.

Construction

~TScopedBuffer()

The destructor deletes the buffer.

Methods

void reset(const T* p = 0, const std::size_t& size = 0)

creates a copy of p