19 #ifndef LUNCHBOX_BUFFER_H 20 #define LUNCHBOX_BUFFER_H 22 #include <lunchbox/debug.h> 23 #include <lunchbox/os.h> 47 Buffer() : _data( nullptr ), _size( 0 ), _maxSize( 0 ) {}
50 explicit Buffer(
const uint64_t size ) : _data(0), _size(0), _maxSize(0)
63 void clear() {
if( _data ) free( _data ); _data=0; _size=0; _maxSize=0; }
80 { LBASSERT( _size > position );
return _data[ position ]; }
84 { LBASSERT( _size > position );
return _data[ position ]; }
93 T*
resize(
const uint64_t newSize );
101 void grow(
const uint64_t newSize );
110 T*
reserve(
const uint64_t newSize );
119 T*
reset(
const uint64_t newSize );
122 void setZero() { ::lunchbox::setZero( _data, _size ); }
125 void append(
const T* data,
const uint64_t size );
128 void append(
const T& element );
131 void replace(
const void* data,
const uint64_t size );
153 bool setSize(
const uint64_t size );
179 #include "buffer.ipp" 181 #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.
Abstraction layer and common utilities for multi-threaded programming.
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.