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

LArray Class Reference
["Arrays" Arrays and Iterators]

#include <LArray.h>

Inheritance diagram for LArray:

Inheritance graph
[legend]
Collaboration diagram for LArray:

Collaboration graph
[legend]
List of all members.

Detailed Description

Partial version of PP LArray class but not based on Handle.

No need to lock contents as uses C++ arrays.

Doesn't require mutable keyword, unlike PP version because stashes pointer to iterator head at top of mItems.

Todo:
add full LArray interface so can finish TArray


Public Types

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

Public Methods

 LArray (Uint32 inItemSize=sizeof(long), Uint16 expandBySlots=4)
 Always alloc so have some leading space in dynamic alloc for iterator head.

 LArray (UInt32 inItemSize, LComparator *inComparator, Boolean inKeepSorted)
 LArray (UInt32 inItemCount, UInt32 inItemSize, LComparator *inComparator, Boolean inKeepSorted)
 LArray (const LArray &)
LArray & operator= (const LArray &)
virtual ~LArray ()
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

Friends

class LArrayIterator


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
index_Bad 
index_First 
index_Last 


Constructor & Destructor Documentation

LArray::LArray Uint32    inItemSize = sizeof(long),
Uint16    expandBySlots = 4
 

Always alloc so have some leading space in dynamic alloc for iterator head.

LArray::LArray UInt32    inItemSize,
LComparator   inComparator,
Boolean    inKeepSorted
 

LArray::LArray UInt32    inItemCount,
UInt32    inItemSize,
LComparator   inComparator,
Boolean    inKeepSorted
 

LArray::LArray const LArray &   
 

LArray::~LArray   [virtual]
 


Member Function Documentation

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

void LArray::AttachIterator LArrayIterator   inIterator const [protected]
 

Insert the given iterator into our list.

void LArray::DestroyArray   [protected]
 

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

void LArray::DetachIterator LArrayIterator   inIterator const [protected]
 

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

void LArray::ExpandToInclude ArrayIndexT    indexToCover [protected]
 

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

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]
 

Uint32 LArray::GetCount   const [inline]
 

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

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]
 

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

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]
 

bool LArray::IsLocked   const [inline]
 

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

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

Tell any iterators we have inserted items.

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

Tell any iterators we have removed items.

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

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

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]
 

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

LArray & LArray::operator= const LArray &   
 

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

Remove an item without knowing location.

Relies on search of FetchIndexOf so governed by its performance.

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

void LArray::Unlock   const [inline]
 

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

bool LArray::ValidIndex ArrayIndexT   ioIndex const
 

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.


Friends And Related Function Documentation

friend class LArrayIterator [friend]
 

Todo:
implement properly now we have smarter LArrayIterator.


Member Data Documentation

LComparator* LArray::mComparator [protected]
 

Uint16 LArray::mExpansionChunk [protected]
 

Uint32 LArray::mItemCount [protected]
 

char* LArray::mItems [protected]
 

Uint32 LArray::mItemSize [protected]
 

Uint32 LArray::mNumSlots [protected]
 

ref to offset pointer within mAllocItems

bool LArray::mOwnsComparator [protected]
 


The documentation for this class was generated from the following files:
Generated on Mon Jul 22 18:20:41 2002 for PP2MFC by doxygen1.2.17