Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

irr::core::array< T, TAlloc > Class Template Reference

Self reallocating template array (like stl vector) with additional features. More...

#include <irrArray.h>

List of all members.

Public Member Functions

u32 allocated_size () const
 Get amount of memory allocated.
 array (const array< T > &other)
 Copy constructor.
 array (u32 start_count)
 Constructs an array and allocates an initial chunk of memory.
 array ()
 Default constructor for empty array.
s32 binary_search (const T &element, s32 left, s32 right) const
 Performs a binary search for an element, returns -1 if not found.
s32 binary_search (const T &element) const
 Performs a binary search for an element if possible, returns -1 if not found.
s32 binary_search (const T &element)
 Performs a binary search for an element, returns -1 if not found.
s32 binary_search_multi (const T &element, s32 &last)
void clear ()
 Clears the array and deletes all allocated memory.
const T * const_pointer () const
 Gets a const pointer to the array.
bool empty () const
 Check if array is empty.
void erase (u32 index, s32 count)
 Erases some elements from the array.
void erase (u32 index)
 Erases an element from the array.
const T & getLast () const
 Gets last element.
T & getLast ()
 Gets last element.
void insert (const T &element, u32 index=0)
 Insert item into array at specified position.
s32 linear_reverse_search (const T &element) const
 Finds an element in linear time, which is very slow.
s32 linear_search (const T &element) const
 Finds an element in linear time, which is very slow.
bool operator!= (const array< T > &other) const
 Inequality operator.
void operator= (const array< T > &other)
 Assignment operator.
bool operator== (const array< T > &other) const
 Equality operator.
const T & operator[] (u32 index) const
 Direct const access operator.
T & operator[] (u32 index)
 Direct access operator.
T * pointer ()
 Gets a pointer to the array.
void push_back (const T &element)
 Adds an element at back of array.
void push_front (const T &element)
 Adds an element at the front of the array.
void reallocate (u32 new_size)
 Reallocates the array, make it bigger or smaller.
void set_free_when_destroyed (bool f)
 Sets if the array should delete the memory it uses upon destruction.
void set_pointer (T *newPointer, u32 size)
 Sets pointer to new array, using this as new workspace.
void set_sorted (bool _is_sorted)
 Sets if the array is sorted.
void set_used (u32 usedNow)
 Sets the size of the array and allocates new elements if necessary.
void setAllocStrategy (eAllocStrategy newStrategy=ALLOC_STRATEGY_DOUBLE)
 set a new allocation strategy
u32 size () const
 Get number of occupied elements of the array.
void sort ()
 Sorts the array using heapsort.
 ~array ()
 Destructor.


Detailed Description

template<class T, typename TAlloc = irrAllocator<T>>
class irr::core::array< T, TAlloc >

Self reallocating template array (like stl vector) with additional features.

Some features are: Heap sorting, binary search methods, easier debugging.

Definition at line 21 of file irrArray.h.


Constructor & Destructor Documentation

template<class T, typename TAlloc = irrAllocator<T>>
irr::core::array< T, TAlloc >::array (  )  [inline]

Default constructor for empty array.

Definition at line 27 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
irr::core::array< T, TAlloc >::array ( u32  start_count  )  [inline]

Constructs an array and allocates an initial chunk of memory.

Parameters:
start_count Amount of elements to pre-allocate.

Definition at line 35 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
irr::core::array< T, TAlloc >::array ( const array< T > &  other  )  [inline]

Copy constructor.

Definition at line 44 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
irr::core::array< T, TAlloc >::~array (  )  [inline]

Destructor.

Frees allocated memory, if set_free_when_destroyed was not set to false by the user before.

Definition at line 55 of file irrArray.h.


Member Function Documentation

template<class T, typename TAlloc = irrAllocator<T>>
u32 irr::core::array< T, TAlloc >::allocated_size (  )  const [inline]

Get amount of memory allocated.

Returns:
Amount of memory allocated. The amount of bytes allocated would be allocated_size() * sizeof(ElementTypeUsed);

Definition at line 352 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
s32 irr::core::array< T, TAlloc >::binary_search ( const T &  element,
s32  left,
s32  right 
) const [inline]

Performs a binary search for an element, returns -1 if not found.

Parameters:
element,: Element to search for.
left First left index
right Last right index.
Returns:
Position of the searched element if it was found, otherwise -1 is returned.

Definition at line 414 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
s32 irr::core::array< T, TAlloc >::binary_search ( const T &  element  )  const [inline]

Performs a binary search for an element if possible, returns -1 if not found.

This method is for const arrays and so cannot call sort(), if the array is not sorted then linear_search will be used instead. Potentially very slow!

Parameters:
element Element to search for.
Returns:
Position of the searched element if it was found, otherwise -1 is returned.

Definition at line 399 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
s32 irr::core::array< T, TAlloc >::binary_search ( const T &  element  )  [inline]

Performs a binary search for an element, returns -1 if not found.

The array will be sorted before the binary search if it is not already sorted. Caution is advised! Be careful not to call this on unsorted const arrays, or the slower method will be used.

Parameters:
element Element to search for.
Returns:
Position of the searched element if it was found, otherwise -1 is returned.

Definition at line 386 of file irrArray.h.

Referenced by irr::core::array< irr::scene::IMeshBuffer * >::binary_search(), and irr::core::array< irr::scene::IMeshBuffer * >::binary_search_multi().

template<class T, typename TAlloc = irrAllocator<T>>
s32 irr::core::array< T, TAlloc >::binary_search_multi ( const T &  element,
s32 last 
) [inline]

Performs a binary search for an element, returns -1 if not found. it is used for searching a multiset The array will be sorted before the binary search if it is not already sorted.

Parameters:
element Element to search for.
&last return lastIndex of equal elements
Returns:
Position of the first searched element if it was found, otherwise -1 is returned.

Definition at line 452 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::clear (  )  [inline]

Clears the array and deletes all allocated memory.

Definition at line 190 of file irrArray.h.

Referenced by irr::scene::quake3::getAsStringList(), and irr::scene::quake3::getTextures().

template<class T, typename TAlloc = irrAllocator<T>>
const T* irr::core::array< T, TAlloc >::const_pointer (  )  const [inline]

Gets a const pointer to the array.

Returns:
Pointer to the array.

Definition at line 335 of file irrArray.h.

Referenced by irr::scene::CMeshBuffer< T >::getVertices().

template<class T, typename TAlloc = irrAllocator<T>>
bool irr::core::array< T, TAlloc >::empty (  )  const [inline]

Check if array is empty.

Returns:
True if the array is empty false if not.

Definition at line 360 of file irrArray.h.

Referenced by irr::scene::CMeshBuffer< T >::recalculateBoundingBox().

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::erase ( u32  index,
s32  count 
) [inline]

Erases some elements from the array.

May be slow, because all elements following after the erased element have to be copied.

Parameters:
index,: Index of the first element to be erased.
count,: Amount of elements to be erased.

Definition at line 533 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::erase ( u32  index  )  [inline]

Erases an element from the array.

May be slow, because all elements following after the erased element have to be copied.

Parameters:
index,: Index of element to be erased.

Definition at line 512 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
const T& irr::core::array< T, TAlloc >::getLast (  )  const [inline]

Gets last element.

Definition at line 317 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
T& irr::core::array< T, TAlloc >::getLast (  )  [inline]

Gets last element.

Definition at line 308 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::insert ( const T &  element,
u32  index = 0 
) [inline]

Insert item into array at specified position.

Please use this only if you know what you are doing (possible performance loss). The preferred method of adding elements should be push_back().

Parameters:
element,: Element to be inserted
index,: Where position to insert the new element.

Definition at line 167 of file irrArray.h.

Referenced by irr::core::array< irr::scene::IMeshBuffer * >::push_front().

template<class T, typename TAlloc = irrAllocator<T>>
s32 irr::core::array< T, TAlloc >::linear_reverse_search ( const T &  element  )  const [inline]

Finds an element in linear time, which is very slow.

Use binary_search for faster finding. Only works if ==operator is implemented.

Parameters:
element,: Element to search for.
Returns:
Position of the searched element if it was found, otherwise -1 is returned.

Definition at line 498 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
s32 irr::core::array< T, TAlloc >::linear_search ( const T &  element  )  const [inline]

Finds an element in linear time, which is very slow.

Use binary_search for faster finding. Only works if ==operator is implemented.

Parameters:
element Element to search for.
Returns:
Position of the searched element if it was found, otherwise -1 is returned.

Definition at line 482 of file irrArray.h.

Referenced by irr::core::array< irr::scene::IMeshBuffer * >::binary_search().

template<class T, typename TAlloc = irrAllocator<T>>
bool irr::core::array< T, TAlloc >::operator!= ( const array< T > &  other  )  const [inline]

Inequality operator.

Definition at line 283 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::operator= ( const array< T > &  other  )  [inline]

Assignment operator.

Definition at line 242 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
bool irr::core::array< T, TAlloc >::operator== ( const array< T > &  other  )  const [inline]

Equality operator.

Definition at line 271 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
const T& irr::core::array< T, TAlloc >::operator[] ( u32  index  )  const [inline]

Direct const access operator.

Definition at line 299 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
T& irr::core::array< T, TAlloc >::operator[] ( u32  index  )  [inline]

Direct access operator.

Definition at line 290 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
T* irr::core::array< T, TAlloc >::pointer (  )  [inline]

Gets a pointer to the array.

Returns:
Pointer to the array.

Definition at line 327 of file irrArray.h.

Referenced by irr::scene::CMeshBuffer< T >::getVertices().

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::push_back ( const T &  element  )  [inline]

Adds an element at back of array.

If the array is too small to add this new element it is made bigger.

Parameters:
element,: Element to add at the back of the array.

Definition at line 108 of file irrArray.h.

Referenced by irr::scene::CMeshBuffer< T >::append(), irr::scene::quake3::getAsStringList(), and irr::scene::quake3::getTextures().

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::push_front ( const T &  element  )  [inline]

Adds an element at the front of the array.

If the array is to small to add this new element, the array is made bigger. Please note that this is slow, because the whole array needs to be copied for this.

Parameters:
element Element to add at the back of the array.

Definition at line 155 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::reallocate ( u32  new_size  )  [inline]

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::set_free_when_destroyed ( bool  f  )  [inline]

Sets if the array should delete the memory it uses upon destruction.

Parameters:
f If true, the array frees the allocated memory in its destructor, otherwise not. The default is true.

Definition at line 222 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::set_pointer ( T *  newPointer,
u32  size 
) [inline]

Sets pointer to new array, using this as new workspace.

Parameters:
newPointer,: Pointer to new array of elements.
size,: Size of the new array.

Definition at line 206 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::set_sorted ( bool  _is_sorted  )  [inline]

Sets if the array is sorted.

Definition at line 557 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::set_used ( u32  usedNow  )  [inline]

Sets the size of the array and allocates new elements if necessary.

Please note: This is only secure when using it with simple types, because no default constructor will be called for the added elements.

Parameters:
usedNow Amount of elements now used.

Definition at line 232 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::setAllocStrategy ( eAllocStrategy  newStrategy = ALLOC_STRATEGY_DOUBLE  )  [inline]

set a new allocation strategy

if the maximum size of the array is unknown, you can define how big the allocation should happen.

Parameters:
newStrategy New strategy to apply to this array.

Definition at line 100 of file irrArray.h.

template<class T, typename TAlloc = irrAllocator<T>>
u32 irr::core::array< T, TAlloc >::size (  )  const [inline]

Get number of occupied elements of the array.

Returns:
Size of elements in the array which are actually occupied.

Definition at line 343 of file irrArray.h.

Referenced by irr::scene::quake3::getAsStringList(), irr::scene::quake3::getTextures(), irr::scene::CMeshBuffer< T >::getVertexCount(), and irr::scene::CMeshBuffer< T >::recalculateBoundingBox().

template<class T, typename TAlloc = irrAllocator<T>>
void irr::core::array< T, TAlloc >::sort (  )  [inline]

Sorts the array using heapsort.

There is no additional memory waste and the algorithm performs O(n*log n) in worst case.

Definition at line 369 of file irrArray.h.

Referenced by irr::core::array< irr::scene::IMeshBuffer * >::binary_search(), and irr::core::array< irr::scene::IMeshBuffer * >::binary_search_multi().


The documentation for this class was generated from the following file:

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2009 by Nikolaus Gebhardt. Generated on Sun Jan 10 09:24:09 2010 by Doxygen (1.5.6)