Array optimized for dynamically changing its size. More...
#include <glv_util.h>
Public Member Functions | |
Buffer (int capacity=0) | |
T & | operator[] (int i) |
Get mutable element at index. | |
const T & | operator[] (int i) const |
Get const element at index. | |
int | capacity () const |
Returns number of elements before needing to allocate more memory. | |
int | size () const |
Returns number of elements. | |
void | assign (int n, const T &v) |
Assign value to elements. | |
void | clear () |
Empty buffer. | |
void | reset () |
Set size of buffer back to 0. | |
void | resize (int n) |
Resize buffer. | |
void | size (int n) |
Set size of buffer avoiding memory reallocation when possible. | |
void | append (const T &v, double growFactor=2) |
Appends element to end of buffer growing its size if necessary. |
Array optimized for dynamically changing its size.
glv::Buffer< T, Alloc >::Buffer | ( | int | capacity = 0 |
) | [inline, explicit] |
[in] | capacity | capacity of buffer |
void glv::Buffer< T, Alloc >::assign | ( | int | n, | |
const T & | v | |||
) | [inline] |
Assign value to elements.
This function fills a Buffer with n copies of the given value. Note that the assignment completely changes the buffer and that the resulting size is the same as the number of elements assigned. Old data may be lost.
void glv::Buffer< T, Alloc >::resize | ( | int | n | ) | [inline] |
Resize buffer.
This will set both the size and capacity of the buffer to the requested size. If the number is smaller than the current size the buffer is truncated, otherwise the buffer is extended and new elements are default-constructed.
void glv::Buffer< T, Alloc >::size | ( | int | n | ) | [inline] |
Set size of buffer avoiding memory reallocation when possible.
If the requested size is larger than the current capacity, then the buffer will be resized.