|
SHOGUN
v2.0.0
|
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 31 of file DynArray.h.
Public Member Functions | |
| DynArray (int32_t p_resize_granularity=128, bool tracable=true) | |
| DynArray (T *p_array, int32_t p_array_size, bool p_free_array, bool p_copy_array, bool tracable=true) | |
| DynArray (const T *p_array, int32_t p_array_size, bool tracable=true) | |
| virtual | ~DynArray () |
| int32_t | set_granularity (int32_t g) |
| int32_t | get_array_size () const |
| int32_t | get_num_elements () const |
| T | get_element (int32_t index) const |
| T | get_last_element () const |
| T * | get_element_ptr (int32_t index) |
| T | get_element_safe (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) |
| void | push_back (T element) |
| void | pop_back () |
| T | back () const |
| int32_t | find_element (T element) const |
| bool | delete_element (int32_t idx) |
| bool | resize_array (int32_t n) |
| T * | get_array () const |
| void | set_array (T *p_array, int32_t p_num_elements, int32_t p_array_size, bool p_free_array, bool p_copy_array) |
| void | set_array (const T *p_array, int32_t p_num_elements, int32_t p_array_size) |
| void | clear_array () |
| void | reset () |
| void | shuffle () |
| void | set_const (const T &const_element) |
| T | operator[] (int32_t index) const |
| DynArray< T > & | operator= (DynArray< T > &orig) |
| virtual const char * | get_name () const |
Protected Attributes | |
| int32_t | resize_granularity |
| T * | array |
| int32_t | num_elements |
| int32_t | last_element_idx |
| bool | use_sg_mallocs |
| bool | free_array |
Friends | |
| class | CDynamicArray |
| class | CDynamicObjectArray |
| class | CCommUlongStringKernel |
| DynArray | ( | int32_t | p_resize_granularity = 128, |
| bool | tracable = true |
||
| ) |
constructor
| p_resize_granularity | resize granularity |
| tracable |
Definition at line 43 of file DynArray.h.
| DynArray | ( | T * | p_array, |
| int32_t | p_array_size, | ||
| bool | p_free_array, | ||
| bool | p_copy_array, | ||
| bool | tracable = true |
||
| ) |
constructor
| p_array | another array |
| p_array_size | array's size |
| p_free_array | if array must be freed |
| p_copy_array | if array must be copied |
| tracable |
Definition at line 66 of file DynArray.h.
| DynArray | ( | const T * | p_array, |
| int32_t | p_array_size, | ||
| bool | tracable = true |
||
| ) |
constructor
| p_array | another array |
| p_array_size | array's size |
| tracable |
Definition at line 82 of file DynArray.h.
|
virtual |
destructor
Definition at line 93 of file DynArray.h.
| bool append_element | ( | T | element | ) |
append array element to the end of array
| element | element to append |
Definition at line 243 of file DynArray.h.
| T back | ( | ) | const |
STD VECTOR compatible. Return array element at the end of array.
Definition at line 273 of file DynArray.h.
| void clear_array | ( | ) |
clear the array (with zeros)
Definition at line 435 of file DynArray.h.
| bool delete_element | ( | int32_t | idx | ) |
delete array element at idx (does not call SG_FREE() or the like)
| idx | index |
Definition at line 308 of file DynArray.h.
| int32_t find_element | ( | T | element | ) | const |
find first occurence of array element and return its index or -1 if not available
| element | element to search for |
Definition at line 285 of file DynArray.h.
| T* get_array | ( | ) | const |
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 376 of file DynArray.h.
| int32_t get_array_size | ( | ) | const |
get array size (including granularity buffer)
Definition at line 120 of file DynArray.h.
| T get_element | ( | int32_t | index | ) | const |
get array element at index
(does NOT do bounds checking)
| index | index |
Definition at line 141 of file DynArray.h.
| T* get_element_ptr | ( | int32_t | index | ) |
get array element at index as pointer
(does NOT do bounds checking)
| index | index |
Definition at line 162 of file DynArray.h.
| T get_element_safe | ( | int32_t | index | ) | const |
get array element at index
(does bounds checking)
| index | index |
Definition at line 174 of file DynArray.h.
| T get_last_element | ( | ) | const |
gets last array element
Definition at line 150 of file DynArray.h.
|
virtual |
Definition at line 505 of file DynArray.h.
| int32_t get_num_elements | ( | ) | const |
| bool insert_element | ( | T | element, |
| int32_t | index | ||
| ) |
insert array element at index
| element | element to insert |
| index | index |
Definition at line 222 of file DynArray.h.
operator overload for array assignment. Left array is resized if needed.
| orig | original array |
Definition at line 482 of file DynArray.h.
| 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
| index | index |
Definition at line 471 of file DynArray.h.
| void pop_back | ( | ) |
STD VECTOR compatible. Delete array element at the end of array.
Definition at line 262 of file DynArray.h.
| void push_back | ( | T | element | ) |
STD VECTOR compatible. Append array element to the end of array.
| element | element to append |
Definition at line 253 of file DynArray.h.
| void reset | ( | ) |
resets the array (as if it was just created), keeps granularity
Definition at line 442 of file DynArray.h.
| bool resize_array | ( | int32_t | n | ) |
resize the array
| n | new size |
Definition at line 333 of file DynArray.h.
| void set_array | ( | T * | p_array, |
| int32_t | p_num_elements, | ||
| int32_t | p_array_size, | ||
| bool | p_free_array, | ||
| bool | p_copy_array | ||
| ) |
set the array pointer and free previously allocated memory
| p_array | new array |
| p_num_elements | last element index + 1 |
| p_array_size | number of elements in array |
| p_free_array | if array must be freed |
| p_copy_array | if array must be copied |
Definition at line 389 of file DynArray.h.
| void set_array | ( | const T * | p_array, |
| int32_t | p_num_elements, | ||
| int32_t | p_array_size | ||
| ) |
set the array pointer and free previously allocated memory
| p_array | new array |
| p_num_elements | last element index + 1 |
| p_array_size | number of elements in array |
Definition at line 417 of file DynArray.h.
| void set_const | ( | const T & | const_element | ) |
set array with a constant
Definition at line 456 of file DynArray.h.
| bool set_element | ( | T | element, |
| int32_t | index | ||
| ) |
set array element at index
| element | element to set |
| index | index |
Definition at line 190 of file DynArray.h.
| int32_t set_granularity | ( | int32_t | g | ) |
set the resize granularity
| g | new granularity |
Definition at line 109 of file DynArray.h.
| void shuffle | ( | ) |
randomizes the array
Definition at line 449 of file DynArray.h.
|
friend |
Definition at line 35 of file DynArray.h.
|
friend |
Definition at line 33 of file DynArray.h.
|
friend |
Definition at line 34 of file DynArray.h.
|
protected |
memory for dynamic array
Definition at line 512 of file DynArray.h.
|
protected |
if array must be freed
Definition at line 524 of file DynArray.h.
|
protected |
the element in the array that has largest index
Definition at line 518 of file DynArray.h.
|
protected |
the number of potentially used elements in array
Definition at line 515 of file DynArray.h.
|
protected |
shrink/grow step size
Definition at line 509 of file DynArray.h.
|
protected |
whether SG_MALLOC or just malloc etc shall be used
Definition at line 521 of file DynArray.h.