Public Member Functions

glv::Buffer< T, Alloc > Class Template Reference

Array optimized for dynamically changing its size. More...

#include <glv_util.h>

List of all members.

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.

Detailed Description

template<class T, class Alloc = std::allocator<T>>
class glv::Buffer< T, Alloc >

Array optimized for dynamically changing its size.


Constructor & Destructor Documentation

template<class T, class Alloc = std::allocator<T>>
glv::Buffer< T, Alloc >::Buffer ( int  capacity = 0  )  [inline, explicit]
Parameters:
[in] capacity capacity of buffer

Member Function Documentation

template<class T, class Alloc = std::allocator<T>>
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.

template<class T, class Alloc = std::allocator<T>>
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.

template<class T, class Alloc = std::allocator<T>>
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.


The documentation for this class was generated from the following file: