CDynamicArray< T > Class Template Reference

Inheritance diagram for CDynamicArray< T >:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 CDynamicArray (int32_t p_resize_granularity=128)
 ~CDynamicArray ()
int32_t set_granularity (int32_t g)
int32_t get_array_size ()
int32_t get_num_elements () const
get_element (int32_t index) const
bool set_element (T element, int32_t index)
bool insert_element (T element, int32_t index)
bool append_element (T element)
bool delete_element (int32_t idx)
bool resize_array (int32_t n)
T * get_array ()
void set_array (T *p_array, int32_t p_num_elements, int32_t array_size)
void clear_array ()
operator[] (int32_t index) const
CDynamicArray< T > & operator= (CDynamicArray< T > &orig)

Protected Attributes

int32_t resize_granularity
T * array
int32_t num_elements
int32_t last_element_idx


Detailed Description

template<class T>
class CDynamicArray< T >

Template Dynamic array class that creates an array that can be used like a list or an array.

It grows and shrinks dynamically, while elements can be accessed via index. It is performance tuned for simple types like float etc. and for hi-level objects only stores pointers, which are not automagically deleted.

Definition at line 32 of file DynamicArray.h.


Constructor & Destructor Documentation

template<class T>
CDynamicArray< T >::CDynamicArray ( int32_t  p_resize_granularity = 128  ) 

constructor

Parameters:
p_resize_granularity resize granularity

Definition at line 39 of file DynamicArray.h.

template<class T>
CDynamicArray< T >::~CDynamicArray (  ) 

Definition at line 51 of file DynamicArray.h.


Member Function Documentation

template<class T>
bool CDynamicArray< T >::append_element ( element  ) 

append array element to the end of array

Parameters:
element element to append
Returns:
if setting was successful

Definition at line 153 of file DynamicArray.h.

template<class T>
void CDynamicArray< T >::clear_array (  ) 

clear the array (with zeros)

Definition at line 239 of file DynamicArray.h.

template<class T>
bool CDynamicArray< T >::delete_element ( int32_t  idx  ) 

delete array element at idx (does not call delete[] or the like)

Parameters:
idx index
Returns:
if deleting was successful

Definition at line 164 of file DynamicArray.h.

template<class T>
T* CDynamicArray< T >::get_array (  ) 

get the array call get_array just before messing with it DO NOT call any [],resize/delete functions after get_array(), the pointer may become invalid !

Returns:
the array

Definition at line 219 of file DynamicArray.h.

template<class T>
int32_t CDynamicArray< T >::get_array_size (  ) 

get array size (including granularity buffer)

Returns:
total array size (including granularity buffer)

Definition at line 69 of file DynamicArray.h.

template<class T>
T CDynamicArray< T >::get_element ( int32_t  index  )  const

get array element at index

Parameters:
index index
Returns:
array element at index

Definition at line 89 of file DynamicArray.h.

template<class T>
int32_t CDynamicArray< T >::get_num_elements (  )  const

get number of elements

Returns:
index of last element

Definition at line 78 of file DynamicArray.h.

template<class T>
bool CDynamicArray< T >::insert_element ( element,
int32_t  index 
)

insert array element at index

Parameters:
element element to insert
index index
Returns:
if setting was successful

Definition at line 132 of file DynamicArray.h.

template<class T>
CDynamicArray<T>& CDynamicArray< T >::operator= ( CDynamicArray< T > &  orig  ) 

operator overload for array assignment

Parameters:
orig original array
Returns:
new array

Definition at line 264 of file DynamicArray.h.

template<class T>
T CDynamicArray< T >::operator[] ( int32_t  index  )  const

operator overload for array read only access use set_element() for write access (will also make the array dynamically grow)

DOES NOT DO ANY BOUNDS CHECKING

Parameters:
index index
Returns:
element at index

Definition at line 254 of file DynamicArray.h.

template<class T>
bool CDynamicArray< T >::resize_array ( int32_t  n  ) 

resize the array

Parameters:
n new size
Returns:
if resizing was successful

Definition at line 188 of file DynamicArray.h.

template<class T>
void CDynamicArray< T >::set_array ( T *  p_array,
int32_t  p_num_elements,
int32_t  array_size 
)

set the array pointer and free previously allocated memory

Parameters:
p_array new array
p_num_elements last element index + 1
array_size number of elements in array

Definition at line 230 of file DynamicArray.h.

template<class T>
bool CDynamicArray< T >::set_element ( element,
int32_t  index 
)

set array element at index

Parameters:
element element to set
index index
Returns:
if setting was successful

Definition at line 100 of file DynamicArray.h.

template<class T>
int32_t CDynamicArray< T >::set_granularity ( int32_t  g  ) 

set the resize granularity

Parameters:
g new granularity
Returns:
what has been set (minimum is 128)

Definition at line 58 of file DynamicArray.h.


Member Data Documentation

template<class T>
T* CDynamicArray< T >::array [protected]

memory for dynamic array

Definition at line 279 of file DynamicArray.h.

template<class T>
int32_t CDynamicArray< T >::last_element_idx [protected]

the element in the array that has largest index

Definition at line 285 of file DynamicArray.h.

template<class T>
int32_t CDynamicArray< T >::num_elements [protected]

the number of potentially used elements in array

Definition at line 282 of file DynamicArray.h.

template<class T>
int32_t CDynamicArray< T >::resize_granularity [protected]

shrink/grow step size

Definition at line 276 of file DynamicArray.h.


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

SHOGUN Machine Learning Toolbox - Documentation