csArray< T, ElementHandler, MemoryAllocator > Class Template Reference
A templated array class. More...
#include <csutil/array.h>
Public Member Functions | |
csArray (size_t icapacity=0, size_t 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 () | |
Destructor. | |
csArray (const csArray &source) | |
Copy constructor. | |
csArray< T, ElementHandler > & | operator= (const csArray &other) |
Assignment operator. | |
size_t | Length () const |
Return the number of elements in the Array. | |
size_t | 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 (size_t n, T const &what) |
Set the actual number of items in this array. | |
void | SetLength (size_t n) |
Set array length to n. | |
T & | Get (size_t n) |
Get an element (non-const). | |
T const & | Get (size_t n) const |
Get an element (const). | |
T & | GetExtend (size_t n) |
Get an item from the array. | |
T & | operator[] (size_t n) |
Get an element (non-const). | |
T const & | operator[] (size_t n) const |
Get a const reference. | |
void | Put (size_t n, T const &what) |
Put an element at some position. | |
template<class K> | |
size_t | FindKey (csArrayCmp< T, K > comparekey) const |
Find an element based on some key. | |
size_t | Push (T const &what) |
Push an element onto the tail end of the array. Returns index of element. | |
size_t | PushSmart (T const &what) |
Push a element onto the tail end of the array if not already present. | |
T | 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 (size_t n, T const &item) |
Insert element 'item' before element 'n'. | |
csArray< T > | Section (size_t low, size_t high) const |
Get the portion of the array between low and high inclusive. | |
template<class K> | |
size_t | FindSortedKey (csArrayCmp< T, K > comparekey, size_t *candidate=0) const |
Find an element based on some key, using a comparison function. | |
size_t | InsertSorted (const T &item, int(*compare)(T const &, T const &)=DefaultCompare, size_t *equal_index=0) |
Insert an element at a sorted position, using an element comparison function. | |
size_t | Find (T const &which) const |
Find a element in array and return its index (or csArrayItemNotFound if not found). | |
size_t | GetIndex (const T *which) const |
Given a pointer to an element in the array this function will return the index. | |
void | Sort (int(*compare)(T const &, T const &)=DefaultCompare) |
Sort array. | |
void | DeleteAll () |
Clear entire vector. | |
void | Truncate (size_t n) |
Truncate array to specified number of elements. | |
void | Empty () |
Remove all elements. | |
void | SetCapacity (size_t n) |
Set vector capacity to approximately 'n' elements. | |
void | ShrinkBestFit () |
Make the array just as big as it needs to be. | |
bool | DeleteIndex (size_t n) |
Delete element number 'n' from vector. | |
bool | DeleteIndexFast (size_t n) |
Delete element number 'n' from vector. | |
void | DeleteRange (size_t start, size_t end) |
Delete a given range (inclusive). | |
bool | Delete (T const &item) |
Delete the given element from vector. | |
bool | DeleteFast (T const &item) |
Delete the given element from vector. | |
Iterator | GetIterator () const |
Returns an Iterator which traverses the Array. | |
Static Public Member Functions | |
int | DefaultCompare (T const &r1, T const &r2) |
Compare two objects of the same type. | |
Protected Member Functions | |
void | InitRegion (size_t start, size_t 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 321 of file array.h.
Constructor & Destructor Documentation
|
Initialize object to have initial capacity of 'icapacity' elements, and to increase storage by 'ithreshold' each time the upper bound is exceeded.
|
|
Destructor.
|
|
Copy constructor.
|
Member Function Documentation
|
Query vector capacity. Note that you should rarely need to do this.
|
|
Compare two objects of the same type.
|
|
Delete the given element from vector.
Definition at line 937 of file array.h. Referenced by csFIFO< csRef< iJob > >::Delete(), and csObjectModel::RemoveListener(). |
|
Clear entire vector.
Definition at line 798 of file array.h. Referenced by csTreeNode::BSF(), csFrameDataHolder< csRenderMeshPtr >::Clear(), csFIFO< csRef< iJob > >::DeleteAll(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::TransferTo(). |
|
Delete the given element from vector. This is a special version of Delete() that doesn't preserve the order of the elements that remain. This is a lot faster for big arrays though. |
|
Delete element number 'n' from vector.
Definition at line 874 of file array.h. Referenced by csTreeNode::BSF(), csBlockAllocator< csBSPTree >::Compact(), and csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::DeleteElement(). |
|
Delete element number 'n' from vector. This is a special version of DeleteIndex() that doesn't preserve the order of the elements that remain. This is a lot faster for big arrays though. Definition at line 896 of file array.h. Referenced by csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::Delete(), and csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::DeleteAll(). |
|
Delete a given range (inclusive). This routine will clamp start and end to the size of the array. |
|
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 835 of file array.h. Referenced by csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::DeleteAll(), and csFIFO< csRef< iJob > >::PopTop(). |
|
Find a element in array and return its index (or csArrayItemNotFound if not found).
|
|
Find an element based on some key.
|
|
Find an element based on some key, using a comparison function. The array must be sorted. Returns csArrayItemNotFound if element does not exist. |
|
Get an element (const).
|
|
Get an element (non-const).
Definition at line 557 of file array.h. Referenced by csAnimationTemplate::GetFrame(), and csArray< T, ElementHandler, MemoryAllocator >::Iterator::Next(). |
|
Get an item from the array. If the number of elements in this array is too small the array will be automatically extended. |
|
Given a pointer to an element in the array this function will return the index. Note that this function doesn't check if the returned index is actually valid. The caller of this function is responsible for testing if the returned index is within the bounds of the array. |
|
Returns an Iterator which traverses the Array.
|
|
Initialize a region. This is a dangerous function to use because it does not properly destruct the items in the array. |
|
Insert element 'item' before element 'n'.
|
|
Insert an element at a sorted position, using an element comparison function. Assumes array is already sorted. |
|
|
Assignment operator.
|
|
Get a const reference.
|
|
Get an element (non-const).
|
|
|
Push an element onto the tail end of the array. Returns index of element.
Definition at line 615 of file array.h. Referenced by csAnimationTemplate::AddFrame(), csObjectModel::AddListener(), csPluginPaths::AddOnce(), csTreeNode::BSF(), csBlockAllocator< csBSPTree >::csBlockAllocator(), csTreeNode::csTreeNode(), csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::GetAll(), csFIFO< csRef< iJob > >::PopTop(), csFIFO< csRef< iJob > >::Push(), csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::Put(), csHash< KeyInfo, csStrKey, csConstCharHashKeyHandler >::PutUnique(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Section(). |
|
Push a element onto the tail end of the array if not already present. Returns index of newly pushed element or index of already present element. |
|
Put an element at some position.
Definition at line 594 of file array.h. Referenced by csPrintfFormatter< Twriter, Treader >::Format(). |
|
Get the portion of the array between low and high inclusive.
|
|
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. |
|
|
|
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 857 of file array.h. Referenced by csFrameDataHolder< csRenderMeshPtr >::GetUnusedData(). |
|
Sort array.
|
|
Return the top element but do not remove it.
|
|
Return the top element but do not remove it.
|
|
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. |
|
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. |
The documentation for this class was generated from the following file:
- csutil/array.h
Generated for Crystal Space by doxygen 1.3.9.1