Safe arrays of arbitrary types.Class Array provides safe arrays of arbitrary type. Array elements are accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by. More...
#include <array.h>
Public Member Functions | |
Access / modification | |
T & | operator[] (int n) |
reference n 'th element. More... | |
const T & | operator[] (int n) const |
reference n 'th element. More... | |
T * | get_ptr () |
void | append (int n) |
append n uninitialized elements. More... | |
void | append (int n, const T *p_array) |
append n elements from p_array . More... | |
void | append (const Array< T > &p_array) |
append all elements from p_array . More... | |
void | insert (int i, int n) |
void | insert (int i, int n, const T *p_array) |
insert n elements from p_array before i 'th element. More... | |
void | insert (int i, const Array< T > &p_array) |
insert all elements from p_array before i 'th element. More... | |
void | remove (int n=0, int m=1) |
void | clear () |
remove all elements. More... | |
int | size () const |
return the number of elements. More... | |
void | reSize (int newsize) |
reset the number of elements. More... | |
Construction / destruction | |
Array< T > & | operator= (const Array< T > &rhs) |
assignment operator. More... | |
Array (int n=0) | |
default constructor. More... | |
Array (const Array< T > &old) | |
copy constructor More... | |
~Array () | |
destructor More... | |
bool | isConsistent () const |
consistency check More... | |
Protected Attributes | |
Data | |
int | num |
the length of array data More... | |
T * | data |
the array of elements More... | |
Safe arrays of arbitrary types.
Class Array provides safe arrays of arbitrary type. Array elements are accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by.
-DNDEBUG
).Moreover, Arrays may easily be extended by inserting or appending elements to the Array or shrunken by removing elements. Method reSize(int n) resets the Array's length to n
, thereby appending elements or truncating the Array to the required size.
An Array is implemented in a C++-compliant way with respect to how memory is managed: Only operators new and delete are used for allocating memory. This involves some overhead for all methods effecting the length of an Array, i.e., all methods insert(), append(), remove() and reSize(). This involves allocating a new C++ array of the new size and copying all elements with the template parameters operator=().
For this reason, it is not convenient to use class Array if its elements are Data Objects. In this case use class DataArray instead.
|
explicit |
void append | ( | int | n | ) |
append n
uninitialized elements.
Definition at line 100 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::reSize().
void append | ( | int | n, |
const T * | p_array | ||
) |
void append | ( | const Array< T > & | p_array | ) |
T* get_ptr | ( | ) |
void insert | ( | int | i, |
int | n | ||
) |
insert n
uninitialized elements before i
'th element.
You must not! use realloc, memcpy or memmove, because some data element points inside itself, and therefore you always need to copy all elements by hand.
Definition at line 120 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::append(), and Array< soplex::UnitVectorBase >::insert().
void insert | ( | int | i, |
int | n, | ||
const T * | p_array | ||
) |
void insert | ( | int | i, |
const Array< T > & | p_array | ||
) |
bool isConsistent | ( | ) | const |
consistency check
Definition at line 358 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::Array(), and Array< soplex::UnitVectorBase >::operator=().
void remove | ( | int | n = 0 , |
int | m = 1 |
||
) |
void reSize | ( | int | newsize | ) |
reset the number of elements.
Definition at line 264 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::operator=().
int size | ( | ) | const |
return the number of elements.
Definition at line 258 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::insert(), Array< soplex::UnitVectorBase >::operator=(), and Array< soplex::UnitVectorBase >::remove().
|
protected |
the array of elements
Definition at line 70 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::Array(), Array< soplex::UnitVectorBase >::get_ptr(), Array< soplex::UnitVectorBase >::insert(), and Array< soplex::UnitVectorBase >::operator=().
|
protected |
the length of array data
Definition at line 69 of file array.h.
Referenced by Array< soplex::UnitVectorBase >::Array(), Array< soplex::UnitVectorBase >::clear(), Array< soplex::UnitVectorBase >::insert(), Array< soplex::UnitVectorBase >::operator=(), Array< soplex::UnitVectorBase >::remove(), Array< soplex::UnitVectorBase >::size(), and Array< soplex::UnitVectorBase >::~Array().