csArray< T, ElementHandler, MemoryAllocator > Class Template Reference
[Containers]
A templated array class.
More...
#include <csutil/array.h>
Public Member Functions | |
size_t | Capacity () const |
Query vector capacity. Note that you should rarely need to do this. | |
size_t | Contains (T const &which) const |
An alias for Find() which may be considered more idiomatic by some. | |
csArray (const csArray &source) | |
Copy constructor. | |
csArray (size_t in_capacity=0, size_t in_threshold=0) | |
Initialize object to have initial capacity of in_capacity elements, and to increase storage by in_threshold each time the upper bound is exceeded. | |
bool | Delete (T const &item) |
Delete the given element from the array. | |
void | DeleteAll () |
Clear entire array, releasing all allocated memory. | |
bool | DeleteFast (T const &item) |
Delete the given element from the array. | |
bool | DeleteIndex (size_t n) |
Delete an element from the array. | |
bool | DeleteIndexFast (size_t n) |
Delete an element from the array in constant-time, regardless of the array's size. | |
void | DeleteRange (size_t start, size_t end) |
Delete a given range (inclusive). | |
void | Empty () |
Remove all elements. | |
size_t | Find (T const &which) const |
Find an element in array. | |
template<class K> | |
size_t | FindKey (csArrayCmp< T, K > comparekey) const |
Find an element based upon some arbitrary key, which may be embedded within an element, or otherwise derived from it. | |
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. | |
T const & | Get (size_t n) const |
Get an element (const). | |
T & | Get (size_t n) |
Get an element (non-const). | |
T & | GetExtend (size_t n) |
Get an item from the array. | |
size_t | GetIndex (const T *which) const |
Given a pointer to an element in the array this function will return the index. | |
Iterator | GetIterator () const |
Returns an Iterator which traverses the array. | |
size_t | GetSize () const |
Return the number of elements in the array. | |
bool | Insert (size_t n, T const &item) |
Insert element item before element n . | |
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. | |
bool | IsEmpty () const |
Return true if the array is empty. | |
size_t | Length () const |
Return the number of elements in the array. | |
csArray< T, ElementHandler > & | operator= (const csArray &other) |
Assignment operator. | |
bool | operator== (const csArray &other) const |
Check if this array has the exact same contents as other. | |
T const & | operator[] (size_t n) const |
Get a const reference. | |
T & | operator[] (size_t n) |
Get an element (non-const). | |
T | Pop () |
Pop an element from tail end of array. | |
size_t | Push (T const &what) |
Push a copy of an element onto the tail end of the array. | |
size_t | PushSmart (T const &what) |
Push a element onto the tail end of the array if not already present. | |
void | Put (size_t n, T const &what) |
Insert a copy of element at the indicated position. | |
csArray< T > | Section (size_t low, size_t high) const |
Get the portion of the array between low and high inclusive. | |
void | SetCapacity (size_t n) |
Set vector capacity to approximately n elements. | |
void | SetMinimalCapacity (size_t n) |
Set vector capacity to at least n elements. | |
void | SetSize (size_t n) |
Set the actual number of items in this array. | |
void | SetSize (size_t n, T const &what) |
Set the actual number of items in this array. | |
void | ShrinkBestFit () |
Make the array just as big as it needs to be. | |
void | Sort (int(*compare)(T const &, T const &)=DefaultCompare) |
Sort array using a comparison function. | |
T & | Top () |
Return the top element but do not remove it. (non-const). | |
T const & | Top () const |
Return the top element but do not remove it. (const). | |
void | TransferTo (csArray &destination) |
Transfer the entire contents of one array to the other. | |
void | Truncate (size_t n) |
Truncate array to specified number of elements. | |
~csArray () | |
Destroy array and all contained elements. | |
void | SetLength (size_t n) |
void | SetLength (size_t n, T const &what) |
Set the actual number of items in this array. | |
Static Public Member Functions | |
static 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. | |
Classes | |
class | Iterator |
Iterator for the Array<> class. More... |
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 iFoo*, then you should consider csRefArray<>, which is more idiomatic than csArray<csRef<iFoo> >.
Definition at line 299 of file array.h.
Constructor & Destructor Documentation
|
Initialize object to have initial capacity of
|
|
Destroy array and all contained elements.
|
|
Copy constructor.
|
Member Function Documentation
|
Query vector capacity. Note that you should rarely need to do this.
Definition at line 483 of file array.h. Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::SetMinimalCapacity(). |
|
An alias for Find() which may be considered more idiomatic by some.
|
|
Compare two objects of the same type.
|
|
Delete the given element from the array.
Definition at line 1005 of file array.h. Referenced by csObjectModel::RemoveListener(). |
|
Clear entire array, releasing all allocated memory.
Definition at line 822 of file array.h. Referenced by csTreeNode::BSF(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::ShrinkBestFit(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::TransferTo(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::~csArray(). |
|
Delete the given element from the array.
|
|
Delete an element from the array. return True if the indicated item index was valid, else false.
Definition at line 935 of file array.h. Referenced by csTreeNode::BSF(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Delete(), scfStringArray::DeleteIndex(), and csTreeNode::RemoveChild(). |
|
Delete an element from the array in constant-time, regardless of the array's size. return True if the indicated item index was valid, else false.
Definition at line 960 of file array.h. Referenced by csHash< csHandlerID, csRef< iEventHandler > >::Delete(), csHash< csHandlerID, csRef< iEventHandler > >::DeleteAll(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::DeleteFast(). |
|
Delete a given range (inclusive).
|
|
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 865 of file array.h. Referenced by scfStringArray::Empty(). |
|
Find an element in array.
Definition at line 785 of file array.h. Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Contains(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Delete(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::DeleteFast(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::PushSmart(), and csTreeNode::RemoveChild(). |
|
Find an element based upon some arbitrary key, which may be embedded within an element, or otherwise derived from it. The incoming key functor defines the relationship between the key and the array's element type.
|
|
Find an element based on some key, using a comparison function.
Definition at line 723 of file array.h. Referenced by csBlockAllocator< csBSPTree >::FindBlock(). |
|
Get an element (const).
|
|
Get an element (non-const).
Definition at line 567 of file array.h. Referenced by scfStringArray::Get(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::operator==(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::operator[](), and csTreeNode::~csTreeNode(). |
|
Get an item from the array. If the number of elements in this array is too small the array will be automatically extended, and the newly added objects will be created using their default (no-argument) constructor. |
|
Given a pointer to an element in the array this function will return the index. Note that this function does not 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.
|
|
Return the number of elements in the array.
Definition at line 468 of file array.h. Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::IsEmpty(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Length(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::operator==(). |
|
Initialize a region. This is a dangerous function to use because it does not properly destruct the items in the array. |
|
Insert element
Definition at line 691 of file array.h. Referenced by scfStringArray::Insert(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::InsertSorted(). |
|
Insert an element at a sorted position, using an element comparison function.
|
|
Return true if the array is empty.
Definition at line 875 of file array.h. Referenced by scfStringArray::IsEmpty(). |
|
|
Assignment operator.
|
|
Check if this array has the exact same contents as other.
|
|
Get a const reference.
|
|
Get an element (non-const).
|
|
|
Push a copy of an element onto the tail end of the array.
Definition at line 633 of file array.h. Referenced by csTreeNode::AddChild(), csObjectModel::AddListener(), csTreeNode::BSF(), csTreeNode::csTreeNode(), csHash< csHandlerID, csRef< iEventHandler > >::GetAll(), scfStringArray::Push(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::PushSmart(), csHash< csHandlerID, csRef< iEventHandler > >::Put(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Section(). |
|
Push a element onto the tail end of the array if not already present.
|
|
Insert a copy of element at the indicated position.
|
|
Get the portion of the array between
|
|
Set vector capacity to approximately
|
|
Set the actual number of items in this array.
Reimplemented in csPDelArray< T >, csPDelArray< csPlugin >, csPDelArray< ArchiveEntry >, csPDelArray< renderMeshListInfo >, csPDelArray< csPixmap >, csPDelArray< csPluginLoadRec >, and csPDelArray< csPluginOption >. Definition at line 562 of file array.h. Referenced by csHash< csHandlerID, csRef< iEventHandler > >::DeleteAll(). |
|
Set vector capacity to at least
|
|
Set the actual number of items in this array. This can be used to shrink an array (like Truncate()) or to enlarge an array, in which case it will properly construct all new items using their default (zero-argument) constructor.
|
|
Set the actual number of items in this array. This can be used to shrink an array (like Truncate()) or to enlarge an array, in which case it will properly construct all new items based on the given item.
Definition at line 521 of file array.h. Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::GetExtend(), csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Put(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::SetLength(). |
|
Make the array just as big as it needs to be. This is useful in cases where you know the array is not going to be modified anymore in order to preserve memory. |
|
Sort array using a comparison function.
Reimplemented in csStringArray. |
|
Return the top element but do not remove it. (non-const).
|
|
Return the top element but do not remove it. (const).
|
|
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.
Definition at line 849 of file array.h. Referenced by csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::Empty(), and csArray< csShaderVariable *, csRefArrayElementHandler< csShaderVariable * > >::SetSize(). |
The documentation for this class was generated from the following file:
- csutil/array.h
Generated for Crystal Space by doxygen 1.4.6