Template derivative of Buffer_t providing the same functionality but for template type T. More...
#include <UTBuffer.h>
Public Member Functions | |
SimpleTypedBuffer_t () | |
SimpleTypedBuffer_t (T *stack_buffer, int num_elements) | |
void | InstallStackBuffer (T *stack_buffer, int num_elements) |
T * | ItemBuffer (int num_elements, bool expect_more_growth=false) |
const T * | ReadOnlyItemBuffer () const |
T & | operator[] (int index) |
const T & | ItemAt (int index) const |
int | NumValidItems () const |
void | SetNumValidItems (int count) |
int | AllocatedItems () const |
void | GrowIfNeeded (int min_allocated_items, bool expect_more_growth=false) |
Template derivative of Buffer_t providing the same functionality but for a template type T. T must be a basic type, pointer, pointer to complex type, or a complex type which has no constructor or destructor. This is because the underlying memory will be an arbitrary block of bytes, cast to T on sizeof(T) boundaries.
Definition at line 139 of file UTBuffer.h.
SimpleTypedBuffer_t< T >::SimpleTypedBuffer_t | ( | ) | [inline] |
Constructor for an empty buffer.
Definition at line 348 of file UTBuffer.h.
SimpleTypedBuffer_t< T >::SimpleTypedBuffer_t | ( | T * | stack_buffer, | |
int | num_elements | |||
) | [inline] |
Constructor for a buffer which initially uses a stack-allocated buffer of the specified size. If the required size grows beyond that size, the buffer will be reallocated from the heap.
Definition at line 355 of file UTBuffer.h.
void SimpleTypedBuffer_t< T >::InstallStackBuffer | ( | T * | stack_buffer, | |
int | num_elements | |||
) | [inline] |
Installs a stack buffer into a SimpleTypedBuffer_t, wiping out any previously existing contents.
Definition at line 362 of file UTBuffer.h.
T * SimpleTypedBuffer_t< T >::ItemBuffer | ( | int | num_elements, | |
bool | expect_more_growth = false | |||
) | [inline] |
Returns a pointer to the internal buffer if the currently allocated size is sufficient to satisfy the request, or reallocates the internal buffer to provide a pointer to a buffer of the requested size. If the new buffer is reallocated, the old contents are copied into the new internal buffer. Subsequent calls to ValidSize will return size unless the valid size was already larger than size.
Definition at line 370 of file UTBuffer.h.
const T * SimpleTypedBuffer_t< T >::ReadOnlyItemBuffer | ( | ) | const [inline] |
Returns a const pointer to the internal buffer. Only the portion up to the size indicated by the ValidSize function is actually valid. This function is provided for direct access to the internal buffer while dealing with const instances.
Definition at line 378 of file UTBuffer.h.
T & SimpleTypedBuffer_t< T >::operator[] | ( | int | index | ) | [inline] |
Accessor to read or write the item of template type T at the specified index. The internal buffer will grow if needed. If the internal buffer does need to grow, it will grow beyond index to make incremental access by operator [] more efficient. To grow the buffer to an exact size, use the ItemBuffer function instead.
Reimplemented from Buffer_t.
Definition at line 386 of file UTBuffer.h.
const T & SimpleTypedBuffer_t< T >::ItemAt | ( | int | index | ) | const [inline] |
Returns the value of the item of template type T at the specified index. The index must be within the size considered valid by virtue of having been explicitly requested by the ItemBuffer function, or having been accessed by operator [].
Definition at line 394 of file UTBuffer.h.
int SimpleTypedBuffer_t< T >::NumValidItems | ( | ) | const [inline] |
Returns the number of items of template type T in the buffer which are considered to be valid by virtue of having been explicitly requested by the ItemBuffer function, or having been accessed by operator [].
Definition at line 403 of file UTBuffer.h.
void SimpleTypedBuffer_t< T >::SetNumValidItems | ( | int | count | ) | [inline] |
Used for optimization of subsequent requests for a buffer of a larger size to ensure that if reallocation is needed, it will only copy what is needed. Note that this is typically unnecessary, since the ItemBuffer function and operator [] keep track of what data has been touched. Optimization with SetValidSize would only be useful if the Buffer function had been used to preallocate a conservative size, not all of which proved to be necessary at the conclusion of the operation which necessitated operating on the buffer.
Definition at line 411 of file UTBuffer.h.
int SimpleTypedBuffer_t< T >::AllocatedItems | ( | ) | const [inline] |
Returns the number of allocated items, which is not necessarily the number of valid items.
Definition at line 419 of file UTBuffer.h.
void SimpleTypedBuffer_t< T >::GrowIfNeeded | ( | int | min_allocated_items, | |
bool | expect_more_growth = false | |||
) | [inline] |
Increases the size of the buffer used to store items if needed, reallocating from the heap. This does not affect the number of items considered to be valid.
Reimplemented from Buffer_t.
Definition at line 427 of file UTBuffer.h.