CDynamicArray< T > Class Template Reference

Inheritance diagram for CDynamicArray< T >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class T>
class CDynamicArray< T >

dynamic array, i.e. array that can be used like a list or an array. it grows and shrinks dynamically, while elements can be accessed via index performance tuned for simple types as float etc. for hi-level objects only store pointers

Definition at line 30 of file DynamicArray.h.


Public Member Functions

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

Static Public Attributes

static CParallel parallel
static CIO io
static CVersion version

Protected Attributes

INT resize_granularity
T * array
INT num_elements
INT last_element_idx

Constructor & Destructor Documentation

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

constructor

Parameters:
p_resize_granularity resize granularity

Definition at line 37 of file DynamicArray.h.

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

Definition at line 49 of file DynamicArray.h.


Member Function Documentation

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

set the resize granularity

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

Definition at line 56 of file DynamicArray.h.

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

get array size (including granularity buffer)

Returns:
total array size (including granularity buffer)

Definition at line 67 of file DynamicArray.h.

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

get number of elements

Returns:
index of last element

Definition at line 76 of file DynamicArray.h.

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

get array element at index

Parameters:
index index
Returns:
array element at index

Definition at line 87 of file DynamicArray.h.

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

set array element at index

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

Definition at line 98 of file DynamicArray.h.

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

insert array element at index

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

Definition at line 130 of file DynamicArray.h.

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 151 of file DynamicArray.h.

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

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

Parameters:
idx index
Returns:
if deleting was successful

Definition at line 162 of file DynamicArray.h.

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

resize the array

Parameters:
n new size
Returns:
if resizing was successful

Definition at line 186 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 217 of file DynamicArray.h.

template<class T>
void CDynamicArray< T >::set_array ( T *  p_array,
INT  p_num_elements,
INT  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 228 of file DynamicArray.h.

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

clear the array (with zeros)

Definition at line 237 of file DynamicArray.h.

template<class T>
T CDynamicArray< T >::operator[] ( INT  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 252 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 262 of file DynamicArray.h.


Member Data Documentation

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

shrink/grow step size

Definition at line 274 of file DynamicArray.h.

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

memory for dynamic array

Definition at line 277 of file DynamicArray.h.

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

the number of potentially used elements in array

Definition at line 280 of file DynamicArray.h.

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

the element in the array that has largest index

Definition at line 283 of file DynamicArray.h.

CParallel CSGObject::parallel [static, inherited]

Definition at line 105 of file SGObject.h.

CIO CSGObject::io [static, inherited]

Definition at line 106 of file SGObject.h.

CVersion CSGObject::version [static, inherited]

Definition at line 107 of file SGObject.h.


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

SHOGUN Machine Learning Toolbox - Documentation