![]() |
Public API Reference |
![]() |
A templated array class. More...
#include <csutil/array.h>
Classes | |
class | ConstIterator |
Iterator for the csArray class. More... | |
class | Iterator |
Iterator for the csArray class. More... | |
class | ReverseConstIterator |
Reverse iterator for the csArray class. More... | |
class | ReverseIterator |
Reverse iterator for the csArray class. More... | |
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 (size_t in_capacity=0, const CapacityHandler &ch=CapacityHandler()) | |
Initialize object to have initial capacity of in_capacity elements. | |
csArray (size_t in_capacity, const MemoryAllocator &alloc, const CapacityHandler &ch) | |
Initialize object to have initial capacity of in_capacity elements and with specific memory allocator and capacity handler initializations. | |
csArray (const csArray &source) | |
Copy constructor. | |
bool | Delete (T const &item) |
Delete the given element from the array. | |
void | DeleteAll () |
Clear the entire array, releasing all allocated memory. | |
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. | |
bool | 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 this 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 & | Get (size_t n) |
Get an element (non-const). | |
T const & | Get (size_t n) const |
Get an element (const). | |
const MemoryAllocator & | GetAllocator () const |
Return a reference to the allocator of this array. | |
T & | GetExtend (size_t n) |
Get an item from the array. | |
T & | GetExtend (size_t n, T const &what) |
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 () |
Return an Iterator which traverses the array. | |
ConstIterator | GetIterator () const |
Return an Iterator which traverses the array. | |
ReverseIterator | GetReverseIterator () |
Return an ReverseIterator which traverses the array in reverse direction. | |
ReverseConstIterator | GetReverseIterator () const |
Return 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 whether the array is empty or not. | |
void | Merge (const csArray &origin) |
Push the elements of an array onto the tail end of the array. | |
void | MergeSmart (const csArray &origin) |
Push the elements of an array onto the tail end of the array if its elements aren't already present. | |
csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | operator= (const csArray &other) |
Assignment operator. | |
bool | operator== (const csArray &other) const |
Check if this array has the exact same contents as other. | |
T & | operator[] (size_t n) |
Get an element (non-const). | |
T const & | operator[] (size_t n) const |
Get a const reference. | |
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 or reset a copy of the element what at the position with index n . | |
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, T const &what) |
Set the actual number of items in this array. | |
void | SetSize (size_t n) |
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. | |
template<typename Pred > | |
void | Sort (Pred &pred) |
Sort array using a binary predicate. | |
template<typename Pred > | |
void | SortStable (Pred &pred) |
Sort array using a binary predicate and a stable sorting algorithm. | |
T const & | Top () const |
Return the top element but do not remove it. (const) | |
T & | Top () |
Return the top element but do not remove it. (non-const) | |
void | TransferTo (csArray &destination) |
Transfer the entire contents of one array to the other. | |
void | Truncate (size_t n) |
Truncate the array to the specified number of elements. | |
~csArray () | |
Destroy array and all contained elements. | |
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. | |
void | SetCapacityVeryUnsafe (size_t n) |
Set the internal array capacity. | |
void | SetDataVeryUnsafe (T *data) |
Set the internal pointer to the data. | |
void | SetSizeVeryUnsafe (size_t n) |
Set the internal array size. |
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.
csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::csArray | ( | size_t | in_capacity = 0 , |
const CapacityHandler & | ch = CapacityHandler() |
||
) | [inline] |
Initialize object to have initial capacity of in_capacity
elements.
The storage increase depends on the specified capacity handler. The default capacity handler accepts a threshold parameter by which the storage is increased each time the upper bound is exceeded.
csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::csArray | ( | size_t | in_capacity, |
const MemoryAllocator & | alloc, | ||
const CapacityHandler & | ch | ||
) | [inline] |
csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::csArray | ( | const csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | source | ) | [inline] |
static int csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::DefaultCompare | ( | T const & | r1, |
T const & | r2 | ||
) | [inline, static] |
Compare two objects of the same type.
r1 | Reference to first object. |
r2 | Reference to second object. |
bool csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::DeleteIndex | ( | size_t | n | ) | [inline] |
Delete an element from the array.
bool csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::DeleteIndexFast | ( | size_t | n | ) | [inline] |
Delete an element from the array in constant-time, regardless of the array's size.
bool csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::DeleteRange | ( | size_t | start, |
size_t | end | ||
) | [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::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.
size_t csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Find | ( | T const & | which | ) | const [inline] |
Find an element in this array.
size_t csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::FindKey | ( | csArrayCmp< T, K > | comparekey | ) | const [inline] |
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.
size_t csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::FindSortedKey | ( | csArrayCmp< T, K > | comparekey, |
size_t * | candidate = 0 |
||
) | const [inline] |
const MemoryAllocator& csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetAllocator | ( | ) | const [inline] |
T& csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetExtend | ( | size_t | n, |
T const & | what | ||
) | [inline] |
size_t csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetIndex | ( | const T * | which | ) | const [inline] |
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.
Iterator csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetIterator | ( | ) | [inline] |
ConstIterator csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetIterator | ( | ) | const [inline] |
ReverseIterator csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetReverseIterator | ( | ) | [inline] |
Return an ReverseIterator which traverses the array in reverse direction.
ReverseConstIterator csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::GetReverseIterator | ( | ) | const [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::InitRegion | ( | size_t | start, |
size_t | count | ||
) | [inline, protected] |
size_t csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::InsertSorted | ( | const T & | item, |
int(*)(T const &, T const &) | compare = DefaultCompare , |
||
size_t * | equal_index = 0 |
||
) | [inline] |
Insert an element at a sorted position, using an element comparison function.
item | The item to insert. |
compare | [optional] Pointer to a function to compare two elements. |
equal_index | [optional] Returns the index of an element equal to the one to be inserted, if one is found. csArrayItemNotFound otherwise. |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Merge | ( | const csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | origin | ) | [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::MergeSmart | ( | const csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | origin | ) | [inline] |
csArray<T,ElementHandler,MemoryAllocator,CapacityHandler>& csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::operator= | ( | const csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | other | ) | [inline] |
bool csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::operator== | ( | const csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | other | ) | const [inline] |
T& csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::operator[] | ( | size_t | n | ) | [inline] |
T const& csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::operator[] | ( | size_t | n | ) | const [inline] |
T csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Pop | ( | ) | [inline] |
Pop an element from tail end of array.
Reimplemented in CS::Utility::StringArray< Allocator, CapacityHandler >, CS::Utility::StringArray< CS::Memory::AllocatorMalloc, csArrayCapacityDefault >, csPDelArray< T, MemoryAllocator, CapacityHandler >, csPDelArray< Target >, csPDelArray< renderMeshListInfo >, csPDelArray< csPluginLoadRec >, csPDelArray< csPixmap >, csPDelArray< Layer >, csPDelArray< ArchiveEntry, CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow< 256 > >, csPDelArray< csCommandLineOption >, csPDelArray< csPluginOption, CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow< 16 > >, csRefArray< T, Allocator, CapacityHandler >, csRefArray< iImage >, csRefArray< csShaderVariable >, csRefArray< iEventHandler >, csRefArray< CS::Animation::iSkeletonAnimNodeFactory >, csRefArray< iSndSysStreamCallback >, csRefArray< View2RenderView >, csRefArray< iObjectNameChangeListener >, csRefArray< iConfigListener >, csRefArray< iTextureHandle >, csRefArray< iObjectModelListener >, csRefArray< RViewPortal2RenderView >, csRefArray< SuperFrustum >, csRefArray< csVisibilityObjectWrapper >, csRefArray< Thread >, and csRefArray< iConfigFile >.
csArray<T> csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Section | ( | size_t | low, |
size_t | high | ||
) | const [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetCapacity | ( | size_t | n | ) | [inline] |
Set vector capacity to approximately n
elements.
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetCapacityVeryUnsafe | ( | size_t | n | ) | [inline, protected] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetDataVeryUnsafe | ( | T * | data | ) | [inline, protected] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetMinimalCapacity | ( | size_t | n | ) | [inline] |
Set vector capacity to at least n
elements.
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetSize | ( | size_t | n, |
T const & | what | ||
) | [inline] |
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.
n | New array length. |
what | Object used as template to construct each newly added object using the object's copy constructor when the array size is increased by this method. |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetSize | ( | size_t | n | ) | [inline] |
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.
n | New array length. |
Reimplemented in csPDelArray< T, MemoryAllocator, CapacityHandler >, csPDelArray< Target >, csPDelArray< renderMeshListInfo >, csPDelArray< csPluginLoadRec >, csPDelArray< csPixmap >, csPDelArray< Layer >, csPDelArray< ArchiveEntry, CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow< 256 > >, csPDelArray< csCommandLineOption >, and csPDelArray< csPluginOption, CS::Container::ArrayAllocDefault, csArrayCapacityFixedGrow< 16 > >.
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SetSizeVeryUnsafe | ( | size_t | n | ) | [inline, protected] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::ShrinkBestFit | ( | ) | [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Sort | ( | int(*)(T const &, T const &) | compare = DefaultCompare | ) | [inline] |
Sort array using a comparison function.
Reimplemented in CS::Utility::StringArray< Allocator, CapacityHandler >, and CS::Utility::StringArray< CS::Memory::AllocatorMalloc, csArrayCapacityDefault >.
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Sort | ( | Pred & | pred | ) | [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::SortStable | ( | Pred & | pred | ) | [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::TransferTo | ( | csArray< T, ElementHandler, MemoryAllocator, CapacityHandler > & | destination | ) | [inline] |
void csArray< T, ElementHandler, MemoryAllocator, CapacityHandler >::Truncate | ( | size_t | n | ) | [inline] |
Truncate the array to the specified number of elements.
The new number of elements cannot exceed the current number of elements.