19 #ifndef LUNCHBOX_BUFFER_H
20 #define LUNCHBOX_BUFFER_H
22 #include <lunchbox/debug.h>
23 #include <lunchbox/os.h>
47 Buffer() : _data(0), _size(0), _maxSize(0) {}
50 explicit Buffer(
const uint64_t size ) : _data(0), _size(0), _maxSize(0)
60 void clear() {
if( _data ) free( _data ); _data=0; _size=0; _maxSize=0; }
74 { LBASSERT( _size > position );
return _data[ position ]; }
78 { LBASSERT( _size > position );
return _data[ position ]; }
87 T*
resize(
const uint64_t newSize );
95 void grow(
const uint64_t newSize );
104 T*
reserve(
const uint64_t newSize );
113 T*
reset(
const uint64_t newSize );
116 void setZero() { ::lunchbox::setZero( _data, _size ); }
119 void append(
const T* data,
const uint64_t size );
122 void append(
const T& element );
125 void replace(
const void* data,
const uint64_t size );
147 bool setSize(
const uint64_t size );
173 #include "buffer.ipp"
175 #endif //LUNCHBOX_BUFFER_H
Buffer(const uint64_t size)
Construct a new buffer of the given size.
Basic type definitions not provided by the operating system.
T * reserve(const uint64_t newSize)
Ensure that the buffer contains at least newSize elements.
Buffer & operator=(const Buffer &from)
Assignment operator, copies data from Buffer.
void append(const T *data, const uint64_t size)
Append elements to the buffer, increasing the size.
uint64_t getMaxSize() const
bool setSize(const uint64_t size)
Set the size of the buffer without changing its allocation.
uint64_t getNumBytes() const
~Buffer()
Destruct the buffer.
void swap(Buffer &buffer)
Swap the buffer contents with another Buffer.
const T * getData() const
void clear()
Flush the buffer, deleting all data.
void grow(const uint64_t newSize)
Ensure that the buffer contains at least newSize elements.
void replace(const Buffer &from)
Replace the existing data.
T * resize(const uint64_t newSize)
Ensure that the buffer contains at least newSize elements.
void replace(const void *data, const uint64_t size)
Replace the existing data with new data.
T * reset(const uint64_t newSize)
Set the buffer size and malloc enough memory.
Buffer()
Construct a new, empty buffer.
T & operator[](const uint64_t position)
Direct access to the element at the given index.
void setZero()
Set the buffer content to 0.
A simple memory buffer with some helper functions.
T * pack()
Tighten the allocated memory to the size of the buffer.