Assimp  v4.1. (December 2018)
irr::core::array< T > Class Template Reference

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

Public Member Functions

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

Detailed Description

template<class T>
class irr::core::array< T >

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

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

Constructor & Destructor Documentation

◆ array() [1/3]

template<class T >
irr::core::array< T >::array ( )
inline

◆ array() [2/3]

template<class T >
irr::core::array< T >::array ( u32  start_count)
inline

Constructs a array and allocates an initial chunk of memory.

Parameters
start_countAmount of elements to allocate.

◆ array() [3/3]

template<class T >
irr::core::array< T >::array ( const array< T > &  other)
inline

Copy constructor.

◆ ~array()

template<class T >
irr::core::array< T >::~array ( )
inline

Destructor.

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

Member Function Documentation

◆ allocated_size()

template<class T >
u32 irr::core::array< T >::allocated_size ( ) const
inline

Returns amount memory allocated.

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

◆ binary_search() [1/2]

template<class T >
s32 irr::core::array< T >::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.

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

◆ binary_search() [2/2]

template<class T >
s32 irr::core::array< T >::binary_search ( const T &  element,
s32  left,
s32  right 
)
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.

Parameters
elementElement to search for.
leftFirst left index
rightLast right index.
Returns
Returns position of the searched element if it was found, otherwise -1 is returned.

◆ clear()

template<class T >
void irr::core::array< T >::clear ( )
inline

Clears the array and deletes all allocated memory.

◆ const_pointer()

template<class T >
const T* irr::core::array< T >::const_pointer ( ) const
inline

Returns a const pointer to the array.

Returns
Pointer to the array.

◆ empty()

template<class T >
bool irr::core::array< T >::empty ( ) const
inline

Returns true if array is empty.

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

◆ erase() [1/2]

template<class T >
void irr::core::array< T >::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
indexIndex of element to be erased.

◆ erase() [2/2]

template<class T >
void irr::core::array< T >::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
indexIndex of the first element to be erased.
countAmount of elements to be erased.

◆ getLast() [1/2]

template<class T >
T& irr::core::array< T >::getLast ( )
inline

Gets last frame.

◆ getLast() [2/2]

template<class T >
const T& irr::core::array< T >::getLast ( ) const
inline

Gets last frame.

◆ insert()

template<class T >
void irr::core::array< T >::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
elementElement to be inserted
indexWhere position to insert the new element.

◆ linear_reverse_search()

template<class T >
s32 irr::core::array< T >::linear_reverse_search ( T &  element)
inline

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

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

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

◆ linear_search()

template<class T >
s32 irr::core::array< T >::linear_search ( T &  element)
inline

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

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

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

◆ operator=()

template<class T >
void irr::core::array< T >::operator= ( const array< T > &  other)
inline

Assignement operator.

◆ operator[]() [1/2]

template<class T >
T& irr::core::array< T >::operator[] ( u32  index)
inline

Direct access operator.

◆ operator[]() [2/2]

template<class T >
const T& irr::core::array< T >::operator[] ( u32  index) const
inline

Direct access operator.

◆ pointer()

template<class T >
T* irr::core::array< T >::pointer ( )
inline

Returns a pointer to the array.

Returns
Pointer to the array.

◆ push_back()

template<class T >
void irr::core::array< T >::push_back ( const T &  element)
inline

Adds an element at back of array.

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

Parameters
elementElement to add at the back of the array.

◆ push_front()

template<class T >
void irr::core::array< T >::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
elementElement to add at the back of the array.

◆ reallocate()

template<class T >
void irr::core::array< T >::reallocate ( u32  new_size)
inline

Reallocates the array, make it bigger or smaller.

Parameters
new_sizeNew size of array.

◆ set_free_when_destroyed()

template<class T >
void irr::core::array< T >::set_free_when_destroyed ( bool  f)
inline

Sets if the array should delete the memory it used.

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

◆ set_pointer()

template<class T >
void irr::core::array< T >::set_pointer ( T *  newPointer,
u32  size 
)
inline

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

Parameters
newPointerPointer to new array of elements.
sizeSize of the new array.

◆ set_sorted()

template<class T >
void irr::core::array< T >::set_sorted ( bool  _is_sorted)
inline

Sets if the array is sorted.

◆ set_used()

template<class T >
void irr::core::array< T >::set_used ( u32  usedNow)
inline

Sets the size of the array.

Parameters
usedNowAmount of elements now used.

◆ size()

template<class T >
u32 irr::core::array< T >::size ( ) const
inline

Returns size of used array.

Returns
Size of elements in the array.

◆ sort()

template<class T >
void irr::core::array< T >::sort ( )
inline

Sorts the array using heapsort.

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


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