Safe arrays of arbitrary types. 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 () |
const T * | get_const_ptr () const |
get a const C pointer to the data. More... | |
void | append (const T &t) |
append 1 elements with value t . More... | |
void | append (int n) |
append n uninitialized elements. More... | |
void | append (int n, const T &t) |
append n elements with value t . More... | |
void | append (int n, const T t[]) |
append n elements from t . More... | |
void | append (const Array< T > &t) |
append all elements from p_array . More... | |
void | insert (int i, int n) |
insert n uninitialized elements before i 'th element. More... | |
void | insert (int i, int n, const T &t) |
insert n elements with value t before i 'the element. More... | |
void | insert (int i, int n, const T t[]) |
insert n elements from p_array before i 'th element. More... | |
void | insert (int i, const Array< T > &t) |
insert all elements from p_array before i 'th element. More... | |
void | remove (int n=0, int m=1) |
remove m elements starting at n . More... | |
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 & | operator= (const Array &&rhs) |
Array (int n=0) | |
default constructor. More... | |
Array (const Array &old) | |
copy constructor More... | |
~Array () | |
destructor More... | |
void | push_back (const T &val) |
void | push_back (T &&val) |
bool | isConsistent () const |
Consistency check. More... | |
Protected Attributes | |
Data | |
std::vector< T > | data |
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 |
default constructor.
The constructor allocates an Array of n
uninitialized elements.
Definition at line 239 of file array.h.
References Array< T >::data.
void append | ( | const Array< T > & | t | ) |
append all elements from p_array
.
Definition at line 137 of file array.h.
References Array< T >::data.
void append | ( | const T & | t | ) |
append 1 elements with value t
.
Definition at line 116 of file array.h.
References Array< T >::data.
Referenced by Array< T >::append().
void append | ( | int | n | ) |
append n
uninitialized elements.
Definition at line 121 of file array.h.
References Array< T >::append().
void append | ( | int | n, |
const T & | t | ||
) |
append n
elements with value t
.
Definition at line 127 of file array.h.
References Array< T >::data.
void append | ( | int | n, |
const T | t[] | ||
) |
void clear | ( | ) |
const T * get_const_ptr | ( | ) | const |
get a const C pointer to the data.
Definition at line 110 of file array.h.
References Array< T >::data.
T * get_ptr | ( | ) |
This function serves for using a Vector in an C-style function. It returns a pointer to the first value of the array.
Definition at line 105 of file array.h.
References Array< T >::data.
void insert | ( | int | i, |
const Array< T > & | t | ||
) |
insert all elements from p_array
before i
'th element.
Definition at line 170 of file array.h.
References Array< T >::data, and Array< T >::size().
void insert | ( | int | i, |
int | n | ||
) |
insert n
uninitialized elements before i
'th element.
Definition at line 143 of file array.h.
References Array< T >::data.
void insert | ( | int | i, |
int | n, | ||
const T & | t | ||
) |
insert n
elements with value t
before i
'the element.
Definition at line 152 of file array.h.
References Array< T >::data.
void insert | ( | int | i, |
int | n, | ||
const T | t[] | ||
) |
insert n
elements from p_array
before i
'th element.
Definition at line 161 of file array.h.
References Array< T >::data.
Definition at line 229 of file array.h.
References Array< T >::data.
assignment operator.
Definition at line 217 of file array.h.
References Array< T >::data, Array< T >::reSize(), and Array< T >::size().
T & operator[] | ( | int | n | ) |
const T & operator[] | ( | int | n | ) | const |
void push_back | ( | const T & | val | ) |
Definition at line 256 of file array.h.
References Array< T >::data.
void push_back | ( | T && | val | ) |
Definition at line 261 of file array.h.
References Array< T >::data.
void remove | ( | int | n = 0 , |
int | m = 1 |
||
) |
remove m
elements starting at n
.
Definition at line 179 of file array.h.
References Array< T >::data, and Array< T >::size().
void reSize | ( | int | newsize | ) |
reset the number of elements.
Definition at line 206 of file array.h.
References Array< T >::data.
Referenced by Array< T >::operator=().
int size | ( | ) | const |
return the number of elements.
Definition at line 200 of file array.h.
References Array< T >::data.
Referenced by Array< T >::insert(), Array< T >::operator=(), DataHashTable< HashItem, Info >::reMax(), and Array< T >::remove().
|
protected |
Definition at line 81 of file array.h.
Referenced by Array< T >::append(), Array< T >::Array(), Array< T >::clear(), Array< T >::get_const_ptr(), Array< T >::get_ptr(), Array< T >::insert(), Array< T >::operator=(), Array< T >::operator[](), Array< T >::push_back(), Array< T >::remove(), Array< T >::reSize(), and Array< T >::size().