19 #ifndef LUNCHBOX_BUFFER_H 
   20 #define LUNCHBOX_BUFFER_H 
   22 #include <lunchbox/debug.h>        
   44         Buffer() : _data(0), _size(0), _maxSize(0) {}
 
   47         Buffer( 
const uint64_t size ) : _data(0), _size(0), _maxSize(0)
 
   53                 _data = from._data; _size = from._size; _maxSize =from._maxSize;
 
   54                 from._data = 0; from._size = 0; from._maxSize = 0;
 
   62             { 
if( _data ) free( _data ); _data=0; _size=0; _maxSize=0; }
 
   71                 if( _maxSize != _size )
 
   73                     _data = 
static_cast< T* 
>( realloc( _data,
 
   74                                                         _size * 
sizeof( T )));
 
   89             { LBASSERT( _size > position ); 
return _data[ position ]; }
 
   93             { LBASSERT( _size > position ); 
return _data[ position ]; }
 
  105                 if( newSize <= _maxSize )
 
  109                 const uint64_t nElems = newSize + (newSize >> 3);
 
  110                 const uint64_t nBytes = nElems * 
sizeof( T );
 
  111                 _data = 
static_cast< T* 
>( realloc( _data, nBytes ));
 
  122         void grow( 
const uint64_t newSize )
 
  124                 if( newSize > _size )
 
  137                 if( newSize <= _maxSize )
 
  140                 _data = 
static_cast< T* 
>( realloc( _data, newSize*
sizeof(T)));
 
  160         void append( 
const T* data, 
const uint64_t size )
 
  165                 const uint64_t oldSize = _size;
 
  167                 memcpy( _data + oldSize, data, size * 
sizeof( T ));
 
  174                 _data[ _size - 1 ] = element;
 
  178         void replace( 
const void* data, 
const uint64_t size )
 
  184                 memcpy( _data, data, size * 
sizeof( T ));
 
  190             { 
replace( from._data, from._size ); }
 
  195                 T*             tmpData    = buffer._data;
 
  196                 const uint64_t tmpSize    = buffer._size;
 
  197                 const uint64_t tmpMaxSize = buffer._maxSize;
 
  199                 buffer._data = _data;
 
  200                 buffer._size = _size;
 
  201                 buffer._maxSize = _maxSize;
 
  205                 _maxSize = tmpMaxSize;
 
  224                 LBASSERT( size <= _maxSize );
 
  225                 if( size > _maxSize )
 
  255 #endif //LUNCHBOX_BUFFER_H