CrystalSpace

Public API Reference

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

csArray< T, ElementHandler, MemoryAllocator > Class Template Reference

A templated array class. More...

#include <array.h>

List of all members.

Public Types

typedef int ArrayCompareFunction (T const &item1, T const &item2)
 This function prototype is used for csArray::InsertSorted().

typedef int ArrayCompareKeyFunction (T const &item1, void *item2)
 This function prototype is used for csArray::FindKey().


Public Methods

 csArray (int icapacity=0, int ithreshold=0)
 Initialize object to have initial capacity of 'icapacity' elements, and to increase storage by 'ithreshold' each time the upper bound is exceeded.

 csArray (const csArray &source)
 Copy constructor.

csArray< T > & operator= (const csArray &other)
 Assignment operator.

int Length () const
 Return the number of elements in the Array.

int Capacity () const
 Query vector capacity. Note that you should rarely need to do this.

void TransferTo (csArray &destination)
 Transfer the entire contents of one array to the other.

void SetLength (int n, T const &what)
 Set the actual number of items in this array.

void SetLength (int n)
 Set vector length to n.

T & Get (int n)
 Get an element (non-const).

T const & Get (int n) const
 Get an element (const).

T & GetExtend (int n)
 Get an item from the array.

T & operator[] (int n)
 Get an element (non-const).

T const & operator[] (int n) const
 Get a const reference.

void Put (int n, T const &what)
 Put an element at some position.

int FindKey (void *key, ArrayCompareKeyFunction *comparekey) const
 Find an element based on some key.

int Push (T const &what)
 Push an element onto the tail end of the array. Returns index of element.

Pop ()
 Pop an element from tail end of array.

T const & Top () const
 Return the top element but do not remove it.

T & Top ()
 Return the top element but do not remove it.

bool Insert (int n, T const &item)
 Insert element 'item' before element 'n'.

csArray< T > Section (int low, int high) const
 Get the portion of the array between low and high inclusive.

int FindSortedKey (void *key, ArrayCompareKeyFunction *comparekey=DefaultCompareKey, int *candidate=0) const
 Find an element based on some key, using a csArrayCompareKeyFunction.

int InsertSorted (const T &item, ArrayCompareFunction *compare=DefaultCompare, int *equal_index=0)
 Insert an element at a sorted position, using a csArrayCompareFunction.

int Find (T const &which) const
 Find a element in array and return its index (or -1 if not found).

void Sort (ArraySortCompareFunction *compare)
 Sort array.

void DeleteAll ()
 Clear entire vector.

void Truncate (int n)
 Truncate array to specified number of elements.

void Empty ()
 Remove all elements.

void SetCapacity (int n)
 Set vector capacity to approximately 'n' elements.

void ShrinkBestFit ()
 Make the array just as big as it needs to be.

bool DeleteIndex (int n)
 Delete element number 'n' from vector.

void DeleteRange (int start, int end)
 Delete a given range (inclusive).

bool Delete (T const &item)
 Delete the given element from vector.

Iterator GetIterator () const
 Returns an Iterator which traverses the Array.


Static Public Methods

int DefaultCompare (T const &item1, T const &item2)
 The default ArrayCompareFunction for InsertSorted().

int DefaultCompareKey (T const &item1, void *p)
 The default ArrayCompareKeyFunction for FindKey().


Protected Methods

void InitRegion (int start, int count)
 Initialize a region.


Detailed Description

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
class csArray< T, ElementHandler, MemoryAllocator >

A templated array class.

The objects in this class are constructed via copy-constructor and are destroyed when they are removed from the array or the array is destroyed. Note: If you want to store reference-counted object pointers (such as iSomething*), then you should look at csRefArray instead of this class.

Definition at line 137 of file array.h.


Member Typedef Documentation

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
typedef int csArray< T, ElementHandler, MemoryAllocator >::ArrayCompareFunction(T const& item1, T const& item2)
 

This function prototype is used for csArray::InsertSorted().

Definition at line 195 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::InsertSorted().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
typedef int csArray< T, ElementHandler, MemoryAllocator >::ArrayCompareKeyFunction(T const& item1, void* item2)
 

This function prototype is used for csArray::FindKey().

Definition at line 197 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::FindKey(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::FindSortedKey().


Constructor & Destructor Documentation

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
csArray< T, ElementHandler, MemoryAllocator >::csArray int    icapacity = 0,
int    ithreshold = 0
[inline]
 

Initialize object to have initial capacity of 'icapacity' elements, and to increase storage by 'ithreshold' each time the upper bound is exceeded.

Definition at line 203 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
csArray< T, ElementHandler, MemoryAllocator >::csArray const csArray< T, ElementHandler, MemoryAllocator > &    source [inline]
 

Copy constructor.

Definition at line 220 of file array.h.


Member Function Documentation

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::Capacity   const [inline]
 

Query vector capacity. Note that you should rarely need to do this.

Definition at line 242 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::DefaultCompare T const &    item1,
T const &    item2
[inline, static]
 

The default ArrayCompareFunction for InsertSorted().

Definition at line 434 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::InsertSorted().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::DefaultCompareKey T const &    item1,
void *    p
[inline, static]
 

The default ArrayCompareKeyFunction for FindKey().

Definition at line 442 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::FindSortedKey().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
bool csArray< T, ElementHandler, MemoryAllocator >::Delete T const &    item [inline]
 

Delete the given element from vector.

Definition at line 638 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::DeleteAll   [inline]
 

Clear entire vector.

Definition at line 528 of file array.h.

Referenced by csTreeNode::BSF(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::ShrinkBestFit(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::TransferTo().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
bool csArray< T, ElementHandler, MemoryAllocator >::DeleteIndex int    n [inline]
 

Delete element number 'n' from vector.

Definition at line 599 of file array.h.

Referenced by csTreeNode::BSF(), csHash< bool, utf32_char >::Delete(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Delete(), and csHash< bool, utf32_char >::DeleteAll().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::DeleteRange int    start,
int    end
[inline]
 

Delete a given range (inclusive).

This routine will clamp start and end to the size of the array.

Definition at line 619 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::Empty   [inline]
 

Remove all elements.

Similar to DeleteAll(), but does not release memory used by the array itself, thus making it more efficient for cases when the number of contained elements will fluctuate.

Definition at line 563 of file array.h.

Referenced by csHash< bool, utf32_char >::DeleteAll().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::Find T const &    which const [inline]
 

Find a element in array and return its index (or -1 if not found).

Definition at line 509 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Delete().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::FindKey void *    key,
ArrayCompareKeyFunction   comparekey
const [inline]
 

Find an element based on some key.

Definition at line 355 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::FindSortedKey void *    key,
ArrayCompareKeyFunction   comparekey = DefaultCompareKey,
int *    candidate = 0
const [inline]
 

Find an element based on some key, using a csArrayCompareKeyFunction.

The array must be sorted. Returns -1 if element does not exist.

Reimplemented in csStringArray.

Definition at line 454 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T const& csArray< T, ElementHandler, MemoryAllocator >::Get int    n const [inline]
 

Get an element (const).

Definition at line 312 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T& csArray< T, ElementHandler, MemoryAllocator >::Get int    n [inline]
 

Get an element (non-const).

Definition at line 305 of file array.h.

Referenced by csGrid::GetRootView(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::operator[]().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T& csArray< T, ElementHandler, MemoryAllocator >::GetExtend int    n [inline]
 

Get an item from the array.

If the number of elements in this array is too small the array will be automatically extended.

Definition at line 322 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
Iterator csArray< T, ElementHandler, MemoryAllocator >::GetIterator   const [inline]
 

Returns an Iterator which traverses the Array.

Definition at line 681 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::InitRegion int    start,
int    count
[inline, protected]
 

Initialize a region.

This is a dangerous function to use because it does not properly destruct the items in the array.

Definition at line 150 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
bool csArray< T, ElementHandler, MemoryAllocator >::Insert int    n,
T const &    item
[inline]
 

Insert element 'item' before element 'n'.

Definition at line 407 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::InsertSorted().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::InsertSorted const T &    item,
ArrayCompareFunction   compare = DefaultCompare,
int *    equal_index = 0
[inline]
 

Insert an element at a sorted position, using a csArrayCompareFunction.

Assumes array is already sorted.

Definition at line 481 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::Length   const [inline]
 

Return the number of elements in the Array.

Definition at line 236 of file array.h.

Referenced by csPluginPaths::AddOnce(), csTreeNode::BSF(), csHash< bool, utf32_char >::Delete(), csHash< bool, utf32_char >::DeleteAll(), csBlockAllocator< csKDTreeChild >::Dump(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Find(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::FindKey(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::FindSortedKey(), csHash< bool, utf32_char >::Get(), csHash< bool, utf32_char >::GetAll(), csHash< bool, utf32_char >::In(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::InsertSorted(), csTree< T >::PopulateWith(), csHash< bool, utf32_char >::Put(), csHash< bool, utf32_char >::PutFirst(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::SetCapacity(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::SetLength(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Sort(), and csBlockAllocator< csKDTreeChild >::~csBlockAllocator().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
csArray<T>& csArray< T, ElementHandler, MemoryAllocator >::operator= const csArray< T, ElementHandler, MemoryAllocator > &    other [inline]
 

Assignment operator.

Definition at line 229 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T const& csArray< T, ElementHandler, MemoryAllocator >::operator[] int    n const [inline]
 

Get a const reference.

Definition at line 337 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T& csArray< T, ElementHandler, MemoryAllocator >::operator[] int    n [inline]
 

Get an element (non-const).

Definition at line 331 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T csArray< T, ElementHandler, MemoryAllocator >::Pop   [inline]
 

Pop an element from tail end of array.

Reimplemented in csPDelArray< T >, csRefArray< T >, csStringArray, csPDelArray< cspPageData >, csPDelArray< csSkinSlice >, csPDelArray< csPlugin >, csPDelArray< csMousePointer >, csPDelArray< ArchiveEntry >, csPDelArray< csWSTexture >, csPDelArray< renderMeshListInfo >, csPDelArray< csPixmap >, csPDelArray< csLayoutConstraint >, csPDelArray< csPluginLoadRec >, csPDelArray< csRect >, csPDelArray< csGridRowEntry >, csPDelArray< csAccElement >, csPDelArray< csCommandLineOption >, csPDelArray< csPluginOption >, csRefArray< iImage >, csRefArray< csShaderVariable >, csRefArray< csEventCord >, csRefArray< iObjectModelListener >, csRefArray< iConfigFile >, and csRefArray< iObject >.

Definition at line 383 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
int csArray< T, ElementHandler, MemoryAllocator >::Push T const &    what [inline]
 

Push an element onto the tail end of the array. Returns index of element.

Definition at line 365 of file array.h.

Referenced by csAnimationTemplate::AddFrame(), csPluginPaths::AddOnce(), csTreeNode::BSF(), csBlockAllocator< csKDTreeChild >::csBlockAllocator(), csHash< bool, utf32_char >::GetAll(), csHash< bool, utf32_char >::Put(), csHash< bool, utf32_char >::PutFirst(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Section().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::Put int    n,
T const &    what
[inline]
 

Put an element at some position.

Definition at line 343 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
csArray<T> csArray< T, ElementHandler, MemoryAllocator >::Section int    low,
int    high
const [inline]
 

Get the portion of the array between low and high inclusive.

Definition at line 425 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::SetCapacity int    n [inline]
 

Set vector capacity to approximately 'n' elements.

Never sets the capacity to fewer than the current number of elements in the array. See Truncate() or SetLength() if you need to adjust the number of actual array elements.

Definition at line 574 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::SetLength int    n [inline]
 

Set vector length to n.

Reimplemented in csPDelArray< T >, csPDelArray< cspPageData >, csPDelArray< csSkinSlice >, csPDelArray< csPlugin >, csPDelArray< csMousePointer >, csPDelArray< ArchiveEntry >, csPDelArray< csWSTexture >, csPDelArray< renderMeshListInfo >, csPDelArray< csPixmap >, csPDelArray< csLayoutConstraint >, csPDelArray< csPluginLoadRec >, csPDelArray< csRect >, csPDelArray< csGridRowEntry >, csPDelArray< csAccElement >, csPDelArray< csCommandLineOption >, and csPDelArray< csPluginOption >.

Definition at line 290 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::SetLength int    n,
T const &    what
[inline]
 

Set the actual number of items in this array.

This can be used to shrink an array (works like Truncate() then in which case it will properly destroy all truncated objects) or to enlarge an array in which case it will properly set the new capacity and construct all new items based on the given item.

Reimplemented in csPDelArray< T >, csPDelArray< cspPageData >, csPDelArray< csSkinSlice >, csPDelArray< csPlugin >, csPDelArray< csMousePointer >, csPDelArray< ArchiveEntry >, csPDelArray< csWSTexture >, csPDelArray< renderMeshListInfo >, csPDelArray< csPixmap >, csPDelArray< csLayoutConstraint >, csPDelArray< csPluginLoadRec >, csPDelArray< csRect >, csPDelArray< csGridRowEntry >, csPDelArray< csAccElement >, csPDelArray< csCommandLineOption >, and csPDelArray< csPluginOption >.

Definition at line 274 of file array.h.

Referenced by csHash< bool, utf32_char >::csHash(), csHash< bool, utf32_char >::DeleteAll(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::GetExtend(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Put().

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::ShrinkBestFit   [inline]
 

Make the array just as big as it needs to be.

This is useful in cases where you know the array isn't going to be modified anymore in order to preserve memory.

Definition at line 585 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::Sort ArraySortCompareFunction *    compare [inline]
 

Sort array.

Reimplemented in csStringArray.

Definition at line 520 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T& csArray< T, ElementHandler, MemoryAllocator >::Top   [inline]
 

Return the top element but do not remove it.

Definition at line 400 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
T const& csArray< T, ElementHandler, MemoryAllocator >::Top   const [inline]
 

Return the top element but do not remove it.

Definition at line 393 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::TransferTo csArray< T, ElementHandler, MemoryAllocator > &    destination [inline]
 

Transfer the entire contents of one array to the other.

The end result will be that this array will be completely empty and the other array will have all items that originally were in this array. This operation is very efficient.

Definition at line 253 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>, class MemoryAllocator = csArrayMemoryAllocator<T>>
void csArray< T, ElementHandler, MemoryAllocator >::Truncate int    n [inline]
 

Truncate array to specified number of elements.

The new number of elements cannot exceed the current number of elements. Use SetLength() for a more general way to enlarge the array.

Definition at line 546 of file array.h.

Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Empty(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::SetLength().


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.2.18