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 SG_REF'd/deleted.
Definition at line 28 of file DynamicArrayPtr.h.
Public Member Functions | |
CDynamicArrayPtr (int32_t p_resize_granularity=128) | |
virtual | ~CDynamicArrayPtr () |
int32_t | set_granularity (int32_t g) |
int32_t | get_array_size (void) |
int32_t | get_num_elements (void) const |
CSGObject * | get_element (int32_t index) const |
CSGObject * | get_element_safe (int32_t index) const |
bool | set_element (CSGObject *element, int32_t index) |
bool | insert_element (CSGObject *element, int32_t index) |
bool | append_element (CSGObject *element) |
void | push_back (CSGObject *element) |
void | pop_back (void) |
CSGObject * | back (void) |
int32_t | find_element (CSGObject *element) |
bool | delete_element (int32_t idx) |
bool | resize_array (int32_t n) |
CSGObject ** | get_array (void) |
void | set_array (CSGObject **p_array, int32_t p_num_elements, int32_t array_size) |
void | clear_array (void) |
CSGObject * | operator[] (int32_t index) const |
CDynamicArrayPtr & | operator= (CDynamicArrayPtr &orig) |
virtual const char * | get_name () const |
CDynamicArrayPtr | ( | int32_t | p_resize_granularity = 128 |
) |
constructor
p_resize_granularity | resize granularity |
Definition at line 37 of file DynamicArrayPtr.h.
virtual ~CDynamicArrayPtr | ( | ) | [virtual] |
Definition at line 51 of file DynamicArrayPtr.h.
bool append_element | ( | CSGObject * | element | ) |
append array element to the end of array
element | element to append |
Definition at line 118 of file DynamicArrayPtr.h.
CSGObject* back | ( | void | ) |
STD::VECTOR compatible. Return array element at the end of array.
Definition at line 140 of file DynamicArrayPtr.h.
void clear_array | ( | void | ) |
clear the array (with zeros)
Definition at line 191 of file DynamicArrayPtr.h.
bool delete_element | ( | int32_t | idx | ) |
delete array element at idx (does not call delete[] or the like)
idx | index |
Definition at line 158 of file DynamicArrayPtr.h.
int32_t find_element | ( | CSGObject * | element | ) |
find first occurence of array element and return its index or -1 if not available
element | element to search for |
Definition at line 149 of file DynamicArrayPtr.h.
CSGObject** get_array | ( | void | ) |
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 !
Definition at line 176 of file DynamicArrayPtr.h.
int32_t get_array_size | ( | void | ) |
get array size (including granularity buffer)
Definition at line 65 of file DynamicArrayPtr.h.
CSGObject* get_element | ( | int32_t | index | ) | const |
get array element at index
(does NOT do bounds checking)
index | index |
Definition at line 82 of file DynamicArrayPtr.h.
CSGObject* get_element_safe | ( | int32_t | index | ) | const |
get array element at index
(does bounds checking)
index | index |
Definition at line 92 of file DynamicArrayPtr.h.
virtual const char* get_name | ( | void | ) | const [virtual] |
int32_t get_num_elements | ( | void | ) | const |
bool insert_element | ( | CSGObject * | element, | |
int32_t | index | |||
) |
insert array element at index
element | element to insert | |
index | index |
Definition at line 110 of file DynamicArrayPtr.h.
CDynamicArrayPtr& operator= | ( | CDynamicArrayPtr & | orig | ) |
operator overload for array assignment
orig | original array |
Definition at line 211 of file DynamicArrayPtr.h.
CSGObject* 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
index | index |
Definition at line 203 of file DynamicArrayPtr.h.
void pop_back | ( | void | ) |
STD::VECTOR compatible. Delete array element at the end of array.
Definition at line 132 of file DynamicArrayPtr.h.
void push_back | ( | CSGObject * | element | ) |
STD::VECTOR compatible. Append array element to the end of array.
element | element to append |
Definition at line 126 of file DynamicArrayPtr.h.
bool resize_array | ( | int32_t | n | ) |
resize the array
n | new size |
Definition at line 166 of file DynamicArrayPtr.h.
void set_array | ( | CSGObject ** | p_array, | |
int32_t | p_num_elements, | |||
int32_t | array_size | |||
) |
set the array pointer and free previously allocated memory
p_array | new array | |
p_num_elements | last element index + 1 | |
array_size | number of elements in array |
Definition at line 185 of file DynamicArrayPtr.h.
bool set_element | ( | CSGObject * | element, | |
int32_t | index | |||
) |
set array element at index
element | element to set | |
index | index |
Definition at line 101 of file DynamicArrayPtr.h.
int32_t set_granularity | ( | int32_t | g | ) |
set the resize granularity
g | new granularity |
Definition at line 58 of file DynamicArrayPtr.h.