Buffer
template <class T> class Buffer : private Moveable< Buffer<T> >
class Buffer
T Type of elements stored in Buffer.
Buffer is a simple class used to manage a fixed size plain old C dynamically allocated vector of elements of a specified type. The size of the buffer is specified as a constructor parameter and it can be also reallocated with new size, while loosing all current data.
Buffer is a moveable type with pick (only) transfer semantics. Calling methods of picked Buffer is logic error with the exceptions of
void Alloc(int size);
void Alloc(int size, const T& in);
void Clear();
void operator=(pick_ Buffer& v);
Derived from Moveable< Buffer<T> >
Buffer()
Constructs an empty buffer.
Buffer(int size)
Constructs the Buffer.
T must have default constructor.
Buffer(int size, const T& init)
Constructs the Buffer initializing the elements to the specified value.
T must have deep copy constructor.
|
init |
Initialization value. |
Buffer(pick_ Buffer& v)
Pick constructor.
void operator=(pick_ Buffer& v)
Pick operator.
|
v |
Source buffer to be picked. |
operator T*()
|
Return value |
Returns a pointer to the first element of the Buffer or NULL if the Buffer is empty. |
operator const T*() const
|
Return value |
Returns a pointer to the first element of the Buffer or NULL if the Buffer is empty. |
T *operator~()
|
Return value |
Returns a pointer to the first element of the Buffer or NULL if the Buffer is empty. |
const T *operator~() const
|
Return value |
Returns a pointer to the first element of the Buffer or NULL if the Buffer is empty. |
void Alloc(int size)
Clears the buffer and allocates it with the new size. All current elements are lost.
T must have default constructor.
void Alloc(int size, const T& in)
Clears the buffer and allocates it with the new size, using the initialization value. All current elements are lost.
T must have deep copy constructor.
void Clear()
Clears the buffer to the same state as default constructor. All current elements are destroyed.
|