CrystalSpace

Public API Reference

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

csArray 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(). More...

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


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. More...

 csArray (const csArray &source)
 Copy constructor. More...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

void Sort (ArraySortCompareFunction *compare)
 Sort array. More...

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

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

void DeleteAll ()
 Clear entire vector. More...

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

void Empty ()
 Remove all elements. More...

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

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

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

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

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

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


Static Public Methods

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

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


Protected Methods

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


Detailed Description

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

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 61 of file array.h.


Member Typedef Documentation

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

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

Definition at line 119 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::InsertSorted.

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

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

Definition at line 121 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::FindKey, and csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::FindSortedKey.


Constructor & Destructor Documentation

template<class T, class ElementHandler = csArrayElementHandler<T>>
csArray< T, ElementHandler >::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 127 of file array.h.

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

Copy constructor.

Definition at line 144 of file array.h.


Member Function Documentation

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

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

Definition at line 166 of file array.h.

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

The default ArrayCompareFunction for InsertSorted().

Definition at line 338 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::InsertSorted.

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

The default ArrayCompareKeyFunction for FindKey().

Definition at line 346 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::FindSortedKey.

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

Delete the given element from vector.

Definition at line 556 of file array.h.

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

Clear entire vector.

Definition at line 446 of file array.h.

Referenced by csTreeNode::BSF, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::ShrinkBestFit, and csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::TransferTo.

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

Delete element number 'n' from vector.

Definition at line 517 of file array.h.

Referenced by csTreeNode::BSF, csHash< K, T, ReverseKeyHandler >::Delete, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Delete, and csHash< K, T, ReverseKeyHandler >::DeleteAll.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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 537 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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 481 of file array.h.

Referenced by csHash< K, T, ReverseKeyHandler >::DeleteAll.

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

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

Definition at line 413 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Delete.

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

Find an element based on some key.

Definition at line 266 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
int csArray< T, ElementHandler >::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 358 of file array.h.

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

Get an element (const).

Definition at line 430 of file array.h.

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

Get an element (non-const).

Definition at line 229 of file array.h.

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

template<class T, class ElementHandler = csArrayElementHandler<T>>
T& csArray< T, ElementHandler >::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 239 of file array.h.

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

Returns an Iterator which traverses the Array.

Definition at line 591 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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 74 of file array.h.

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

Insert element 'item' before element 'n'.

Definition at line 311 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::InsertSorted.

template<class T, class ElementHandler = csArrayElementHandler<T>>
int csArray< T, ElementHandler >::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 385 of file array.h.

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

Return the number of elements in the Array.

Definition at line 160 of file array.h.

Referenced by csPluginPaths::AddOnce, csTreeNode::BSF, csHash< K, T, ReverseKeyHandler >::Delete, csHash< K, T, ReverseKeyHandler >::DeleteAll, csBlockAllocator< Element >::Dump, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Find, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::FindKey, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::FindSortedKey, csHash< K, T, ReverseKeyHandler >::Get, csHash< K, T, ReverseKeyHandler >::GetAll, csStaticLODFactoryMesh::GetLODCount, csStaticLODMesh::GetLODCount, csStaticLODFactoryMesh::GetMeshesForLOD, csStaticLODMesh::GetMeshesForLOD, csObjectWatcher::GetWatchedLightCount, csObjectWatcher::GetWatchedMovableCount, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::InsertSorted, csTree::PopulateWith, csHash< K, T, ReverseKeyHandler >::Put, csHash< K, T, ReverseKeyHandler >::PutFirst, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::SetCapacity, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::SetLength, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Sort, and csBlockAllocator< Element >::~csBlockAllocator.

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

Assignment operator.

Definition at line 153 of file array.h.

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

Get a const reference.

Definition at line 437 of file array.h.

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

Get an element (non-const).

Definition at line 248 of file array.h.

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

Pop an element from tail end of array.

Reimplemented in csPDelArray.

Definition at line 294 of file array.h.

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

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

Definition at line 276 of file array.h.

Referenced by csAnimationTemplate::AddFrame, csPluginPaths::AddOnce, csTreeNode::BSF, csBlockAllocator< Element >::csBlockAllocator, csHash< K, T, ReverseKeyHandler >::GetAll, csHash< K, T, ReverseKeyHandler >::Put, csHash< K, T, ReverseKeyHandler >::PutFirst, and csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Section.

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

Put an element at some position.

Definition at line 254 of file array.h.

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

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

Definition at line 329 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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 492 of file array.h.

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

Set vector length to n.

Reimplemented in csPDelArray.

Definition at line 214 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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.

Definition at line 198 of file array.h.

Referenced by csHash< K, T, ReverseKeyHandler >::csHash, csHash< K, T, ReverseKeyHandler >::DeleteAll, csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::GetExtend, csStaticLODFactoryMesh::GetMeshesForLOD, csStaticLODMesh::GetMeshesForLOD, and csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Put.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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 503 of file array.h.

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

Sort array.

Reimplemented in csStringArray.

Definition at line 424 of file array.h.

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

Return the top element but do not remove it.

Definition at line 304 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::TransferTo csArray< T, ElementHandler > &    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 177 of file array.h.

template<class T, class ElementHandler = csArrayElementHandler<T>>
void csArray< T, ElementHandler >::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 464 of file array.h.

Referenced by csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::Empty, and csArray< iLightingProcessData *, csRefArrayElementHandler< iLightingProcessData * > >::SetLength.


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