Array_t< T > Class Template Reference

Template dynamic sized circular array of T. More...

#include <UTLists.h>

List of all members.

Public Member Functions

 Array_t ()
 Array_t (T *stack_buffer, int stack_buffer_num_items_allcoated)
 ~Array_t ()
void InstallStackBuffer (T *stack_buffer, int stack_buffer_num_items_allcoated)
AddHead (const T &item)
AddTail (const T &item)
AddItemAt (const T &item, int index)
RemoveHead ()
RemoveTail ()
RemoveItemAt (int index)
int CountItems () const
int AllocatedItems () const
void SetNumValidItems (int count)
void GrowIfNeeded (int min_allocated_items, bool expect_more_growth=false)
Head () const
Tail () const
ItemAt (int index) const
T & operator[] (int index) const
void operator+= (const T &item)

Detailed Description

template<class T>
class Array_t< T >

Template dynamic sized array class, implemented as a circular array of T. T must be a simple type: a basic type, struct, or typedef based on a basic type or struct because memmove will be used to move elements around in the list. Therefore, T cannot be a class which has a constructor or destructor.

Definition at line 37 of file UTLists.h.


Constructor & Destructor Documentation

template<class T >
Array_t< T >::Array_t (  )  [inline]

Constructor for an empty array.

Definition at line 751 of file UTLists.h.

template<class T>
Array_t< T >::Array_t ( T *  stack_buffer,
int  stack_buffer_num_items_allcoated 
) [inline]

Constructor for an array 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 762 of file UTLists.h.

template<class T >
Array_t< T >::~Array_t (  )  [inline]

Destructor. The internal buffer will be deleted unless a stack buffer was provided in the constructor and the buffer never grew to the point of having been reallocated from the heap.

Definition at line 773 of file UTLists.h.


Member Function Documentation

template<class T>
void Array_t< T >::InstallStackBuffer ( T *  stack_buffer,
int  stack_buffer_num_items_allcoated 
) [inline]

Installs a stack buffer into an empty but already constructed Array_t.

Definition at line 782 of file UTLists.h.

template<class T>
T Array_t< T >::AddHead ( const T &  item  )  [inline]

Adds an item to the head of the list.

Definition at line 793 of file UTLists.h.

template<class T>
T Array_t< T >::AddTail ( const T &  item  )  [inline]

Adds an item to the end of the list.

Definition at line 851 of file UTLists.h.

template<class T>
T Array_t< T >::AddItemAt ( const T &  item,
int  index 
) [inline]

Adds an item at the specified position, where the head is index 0. The specified index must be within the range of valid items, or the next index after the last valid item. That way, no gaps of invalid items can be generated. If index is -1, the item will be added at the tail.

Definition at line 912 of file UTLists.h.

template<class T >
T Array_t< T >::RemoveHead (  )  [inline]

Removes and returns the item at the head of the list.

Definition at line 1232 of file UTLists.h.

template<class T >
T Array_t< T >::RemoveTail (  )  [inline]

Removes and returns the item at the end of the list.

Definition at line 1253 of file UTLists.h.

template<class T >
T Array_t< T >::RemoveItemAt ( int  index  )  [inline]

Removes and returns the item at the specified position in the list, where the head is index 0.

Definition at line 1273 of file UTLists.h.

template<class T >
int Array_t< T >::CountItems (  )  const [inline]

Returns the number of items in the list.

Definition at line 1408 of file UTLists.h.

template<class T >
int Array_t< T >::AllocatedItems (  )  const [inline]

Returns the number of allocated items in the underlying buffer, which is not necessarily the number of items which are valid.

Definition at line 1416 of file UTLists.h.

template<class T >
void Array_t< T >::SetNumValidItems ( int  count  )  [inline]

Sets the number of valid items. This is used to flag items which were previously valid as now being invalid, as will be reflected by CountItems. The item count must be less than or equal to the previous number of valid items.

Definition at line 1424 of file UTLists.h.

template<class T >
void Array_t< T >::GrowIfNeeded ( int  min_allocated_items,
bool  expect_more_growth = false 
) [inline]

Increases the allocated size of the array if necessary. If expect_more_growth is true, it will allocate some spare, unoccupied items in the underlying array. The items are not considered valid, space for them is merely reserved in the underlying array.

Definition at line 1433 of file UTLists.h.

template<class T >
T Array_t< T >::Head (  )  const [inline]

Returns the item at the head of the list.

Definition at line 1475 of file UTLists.h.

template<class T >
T Array_t< T >::Tail (  )  const [inline]

Returns the item at the end of the list.

Definition at line 1485 of file UTLists.h.

template<class T >
T Array_t< T >::ItemAt ( int  index  )  const [inline]

Returns the item at the specified position in the list, where the head is index 0. An item may only be accessed if it is a valid item. The item is returned by value, so the returned value is NOT a pointer to the internal storage allocated by Array_t. If that is needed, use operator [] instead.

Definition at line 1503 of file UTLists.h.

template<class T >
T & Array_t< T >::operator[] ( int  index  )  const [inline]

Returns the item at the specified position in the list by reference, where the head is index 0. An item may only be accessed if it is already a valid item or immediately after the last valid item. That way, no gaps of invalid items can be generated. The item is returned by reference, thus the internal storage of the array is accessible.

Reimplemented in List_t< T >, List_t< Window_t >, List_t< MenuNode_t >, and List_t< MessageDestination_t< QuitResponseMessage_t > >.

Definition at line 1520 of file UTLists.h.

template<class T>
void Array_t< T >::operator+= ( const T &  item  )  [inline]

Adds an item to the end of the array.

Definition at line 1540 of file UTLists.h.


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

Generated on Tue Dec 14 22:35:06 2010 for UT library by  doxygen 1.6.1