Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

TArray< T > Class Template Reference

#include <TArray.h>

Inheritance diagram for TArray< T >:

Inheritance graph
[legend]
Collaboration diagram for TArray< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename T>
class TArray< T >

Templated subclass of LArray for managing pointers or small structs.

Warning:
The T& returned by both operator[] functions is a reference to pointer to data within a c++ array which will be reallocated on some additions to the array.
Note:
TArray knows intimately the allocation strategy of LArray, being a subclass and exposing the strategy through templated inlines.
Todo:
add full TArray interface


Public Types

enum  { index_Bad = 0, index_First = 1, index_Last = 0x7FFFFFFF }

Public Methods

 TArray ()
 TArray (LComparator *inComparator, Boolean inKeepSorted=false)
 TArray (UInt32 inItemCount, LComparator *inComparator=nil, Boolean inKeepSorted=false)
virtual ~TArray ()
T & operator[] (ArrayIndexT inAtIndex)
 performs no range checking.

const T & operator[] (ArrayIndexT inAtIndex) const
Boolean FetchItemAt (ArrayIndexT inAtIndex, T &outItem) const
ArrayIndexT AddItem (const T &inItem)
bool ValidIndex (ArrayIndexT &ioIndex) const
 Test an index, taking count of special value index_Last.

virtual void Remove (const void *iinItem, UInt32 inItemSize=0)
 Remove an item without knowing location.

void Lock () const
 do nothing as don''t have Handle that needs locking

void Unlock () const
 do nothing as don''t have Handle that needs locking

bool IsLocked () const
 do nothing as don''t have Handle that needs locking

virtual UInt32 GrabItemSize (ArrayIndexT inIndex) const
 Virtual base always returns fixed item size.

Uint32 GetCount () const
virtual Uint32 GetItemSize () const
virtual void * GetItemPtr (ArrayIndexT inAtIndex) const
 Returns a pointer to the start of an Items data within the internal storage.

virtual ArrayIndexT AddItem (const void *inItem, Uint32 inItemSize=0)
virtual Boolean FetchItemAt (ArrayIndexT, void *outItem) const
virtual ArrayIndexT FetchIndexOf (const void *iinItem, UInt32 iinItemSize=0) const
 Find the index of the specified item using best search possible.

virtual ArrayIndexT InsertItemsAt (Uint32 inCount, ArrayIndexT inAtIndex, const void *inItem, Uint32 inItemSize=0)
virtual void RemoveItemsAt (Uint32 inCount, ArrayIndexT inAtIndex)

Protected Methods

void DestroyArray ()
 Cleanup - is aware of the implementation stashing iterator head in mAllocItems.

void ExpandToInclude (ArrayIndexT indexToCover)
Iterator Support
void AttachIterator (LArrayIterator *inIterator) const
 Insert the given iterator into our list.

void DetachIterator (LArrayIterator *inIterator) const
 Go along the linked list of iterators and unlink the specified one.

void ItemsInserted (UInt32 inCount, ArrayIndexT inAtIndex)
 Tell any iterators we have inserted items.

void ItemsRemoved (UInt32 inCount, ArrayIndexT inAtIndex)
 Tell any iterators we have removed items.

LArrayIterator *& iteratorListHead () const
Searching
ArrayIndexT LinearSearch (const void *inItem, UInt32 inItemSize) const
 Search from beginning of array using user specified mComparator.


Protected Attributes

LComparatormComparator
bool mOwnsComparator
Uint32 mItemSize
Uint32 mItemCount
char * mItems
Uint32 mNumSlots
 ref to offset pointer within mAllocItems

Uint16 mExpansionChunk


Member Enumeration Documentation

anonymous enum [inherited]
 

Enumeration values:
index_Bad 
index_First 
index_Last 


Constructor & Destructor Documentation

template<typename T>
TArray< T >::TArray   [inline]
 

template<typename T>
TArray< T >::TArray LComparator   inComparator,
Boolean    inKeepSorted = false
[inline]
 

template<typename T>
TArray< T >::TArray UInt32    inItemCount,
LComparator   inComparator = nil,
Boolean    inKeepSorted = false
[inline]
 

template<typename T>
virtual TArray< T >::~TArray   [inline, virtual]
 


Member Function Documentation

ArrayIndexT LArray::AddItem const void *    inItem,
Uint32    inItemSize = 0
[virtual, inherited]
 

template<typename T>
ArrayIndexT TArray< T >::AddItem const T &    inItem [inline]
 

void LArray::AttachIterator LArrayIterator   inIterator const [protected, inherited]
 

Insert the given iterator into our list.

void LArray::DestroyArray   [protected, inherited]
 

Cleanup - is aware of the implementation stashing iterator head in mAllocItems.

void LArray::DetachIterator LArrayIterator   inIterator const [protected, inherited]
 

Go along the linked list of iterators and unlink the specified one.

void LArray::ExpandToInclude ArrayIndexT    indexToCover [protected, inherited]
 

ArrayIndexT LArray::FetchIndexOf const void *    inItem,
UInt32    inItemSize = 0
const [virtual, inherited]
 

Find the index of the specified item using best search possible.

Parameters:
inItemSize  allowed to be zero to indicate default to standard size
Returns :
index_Bad if no items or one-based index otherwise
Todo:
call BinarySearch when sorting implemented

Boolean LArray::FetchItemAt ArrayIndexT   ,
void *    outItem
const [virtual, inherited]
 

template<typename T>
Boolean TArray< T >::FetchItemAt ArrayIndexT    inAtIndex,
T &    outItem
const [inline]
 

Uint32 LArray::GetCount   const [inline, inherited]
 

void * LArray::GetItemPtr ArrayIndexT    inAtIndex const [virtual, inherited]
 

Returns a pointer to the start of an Items data within the internal storage.

Warning:
This routine performs no bounds checking. If index is not valid, routine may crash or return a pointer to arbitrary memory.
Warning:
For sorted Arrays, your updates may cause data to be out of order. If your changes alter the sorting order, call InvalidateSort() so that the Array's internal flags correctly reflect the sorting state. Then call Sort() afterwards if you still want the Array to be sorted.

virtual Uint32 LArray::GetItemSize   const [inline, virtual, inherited]
 

UInt32 LArray::GrabItemSize ArrayIndexT    inIndex const [inline, virtual, inherited]
 

Virtual base always returns fixed item size.

Virtual is inlined because much use of LArray is for local vars so compiler will still be able to use inline.

ArrayIndexT LArray::InsertItemsAt Uint32    inCount,
ArrayIndexT    inAtIndex,
const void *    inItem,
Uint32    inItemSize = 0
[virtual, inherited]
 

bool LArray::IsLocked   const [inline, inherited]
 

do nothing as don''t have Handle that needs locking

void LArray::ItemsInserted UInt32    inCount,
ArrayIndexT    inAtIndex
[protected, inherited]
 

Tell any iterators we have inserted items.

void LArray::ItemsRemoved UInt32    inCount,
ArrayIndexT    inAtIndex
[protected, inherited]
 

Tell any iterators we have removed items.

LArrayIterator *& LArray::iteratorListHead   const [inline, protected, inherited]
 

ArrayIndexT LArray::LinearSearch const void *    inItem,
UInt32    inItemSize
const [protected, inherited]
 

Search from beginning of array using user specified mComparator.

Uses equality tests only as assumes array unsorted. Assumes array doesn't change in size whilst searching.

void LArray::Lock   const [inline, inherited]
 

do nothing as don''t have Handle that needs locking

template<typename T>
const T& TArray< T >::operator[] ArrayIndexT    inAtIndex const [inline]
 

template<typename T>
T& TArray< T >::operator[] ArrayIndexT    inAtIndex [inline]
 

performs no range checking.

void LArray::Remove const void *    inItem,
UInt32    inItemSize = 0
[virtual, inherited]
 

Remove an item without knowing location.

Relies on search of FetchIndexOf so governed by its performance.

void LArray::RemoveItemsAt Uint32    inCount,
ArrayIndexT    inAtIndex
[virtual, inherited]
 

void LArray::Unlock   const [inline, inherited]
 

do nothing as don''t have Handle that needs locking

bool LArray::ValidIndex ArrayIndexT   ioIndex const [inherited]
 

Test an index, taking count of special value index_Last.

Parameters:
ioIndex  specifies index to test or request flag index_Last and may be updated.
Returns :
true if input index in range or requested last index and have items (mItemCount>0)
Warning:
assumes LArrayIterator uses negative values for special meaning.


Member Data Documentation

LComparator* LArray::mComparator [protected, inherited]
 

Uint16 LArray::mExpansionChunk [protected, inherited]
 

Uint32 LArray::mItemCount [protected, inherited]
 

char* LArray::mItems [protected, inherited]
 

Uint32 LArray::mItemSize [protected, inherited]
 

Uint32 LArray::mNumSlots [protected, inherited]
 

ref to offset pointer within mAllocItems

bool LArray::mOwnsComparator [protected, inherited]
 


The documentation for this class was generated from the following file:
Generated on Mon Jul 22 18:21:57 2002 for PP2MFC by doxygen1.2.17