CrystalSpace

Public API Reference

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

csArray Class Template Reference

A templated array class. More...

#include <array.h>

List of all members.

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 &other)
 Copy constructor just copies all data. More...

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

void DeleteAll ()
 Clear entire vector, releasing all memory. More...

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

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

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

 ~csArray ()
 Destroy the container. More...

int Length () const
 Query vector length. More...

int Capacity () const
 Query vector capacity. Note that you should rarely need to do this. 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...

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

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

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

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

int Find (T const &which) const
 Find a element in array and return its index (or -1 if not found). 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 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...

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


Detailed Description

template<class T>
class csArray< T >

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


Constructor & Destructor Documentation

template<class T>
csArray< T >::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 83 of file array.h.

template<class T>
csArray< T >::csArray const csArray< T > &    other [inline]
 

Copy constructor just copies all data.

Definition at line 95 of file array.h.

template<class T>
csArray< T >::~csArray   [inline]
 

Destroy the container.

Definition at line 198 of file array.h.


Member Function Documentation

template<class T>
int csArray< T >::Capacity   const [inline]
 

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

Definition at line 210 of file array.h.

template<class T>
bool csArray< T >::Delete T const &    item [inline]
 

Delete the given element from vector.

Definition at line 355 of file array.h.

template<class T>
void csArray< T >::DeleteAll   [inline]
 

Clear entire vector, releasing all memory.

Definition at line 136 of file array.h.

Referenced by csArray< csHashBucket >::ShrinkBestFit, csArray< csHashBucket >::TransferTo, and csArray< csHashBucket >::~csArray.

template<class T>
bool csArray< T >::DeleteIndex int    n [inline]
 

Delete element number 'n' from vector.

Definition at line 316 of file array.h.

Referenced by csArray< csHashBucket >::Delete.

template<class T>
void csArray< T >::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 336 of file array.h.

template<class T>
void csArray< T >::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 193 of file array.h.

template<class T>
int csArray< T >::Find T const &    which const [inline]
 

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

Definition at line 272 of file array.h.

Referenced by csArray< csHashBucket >::Delete.

template<class T>
T& csArray< T >::Get int    n [inline]
 

Get an element (non-const).

Definition at line 253 of file array.h.

template<class T>
T const& csArray< T >::Get int    n const [inline]
 

Get an element (const).

Definition at line 246 of file array.h.

Referenced by csArray< csHashBucket >::operator[].

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

Insert element 'item' before element 'n'.

Definition at line 364 of file array.h.

template<class T>
int csArray< T >::Length   const [inline]
 

Query vector length.

Definition at line 204 of file array.h.

Referenced by csArray< csHashBucket >::csArray, csBlockAllocator::Dump, csArray< csHashBucket >::Find, csArray< csHashBucket >::SetCapacity, csArray< csHashBucket >::SetLength, and csBlockAllocator::~csBlockAllocator.

template<class T>
T& csArray< T >::operator[] int    n [inline]
 

Get an element (non-const).

Definition at line 266 of file array.h.

template<class T>
T const& csArray< T >::operator[] int    n const [inline]
 

Get an element (const).

Definition at line 260 of file array.h.

template<class T>
T csArray< T >::Pop   [inline]
 

Pop an element from tail end of array.

Definition at line 299 of file array.h.

template<class T>
int csArray< T >::Push T const &    what [inline]
 

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

Definition at line 281 of file array.h.

Referenced by csArray< csHashBucket >::csArray, and csBlockAllocator::csBlockAllocator.

template<class T>
void csArray< T >::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 221 of file array.h.

template<class T>
void csArray< T >::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.

Definition at line 173 of file array.h.

template<class T>
void csArray< T >::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 232 of file array.h.

template<class T>
T const& csArray< T >::Top   const [inline]
 

Return the top element but do not remove it.

Definition at line 309 of file array.h.

template<class T>
void csArray< T >::TransferTo csArray< T > &    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 111 of file array.h.

template<class T>
void csArray< T >::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 154 of file array.h.

Referenced by csArray< csHashBucket >::Empty, and csArray< csHashBucket >::SetLength.


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