Simpatico
v1.10
|
An automatically growable PArray.
An GPArray is a PArray that grows as needed as objects are appended. Like any PArray, it holds pointers to objects, rather than objects. The associated objects are not destroyed when a PArray is deallocated or destroyed.
#include <GPArray.h>
Public Member Functions | |
GPArray () | |
Constructor. More... | |
GPArray (const GPArray< Data > &other) | |
Copy constructor, copy pointers. More... | |
GPArray< Data > & | operator= (const GPArray< Data > &other) |
Assignment, element by element. More... | |
virtual | ~GPArray () |
Destructor. More... | |
void | append (Data &data) |
Append an element to the end of the sequence. More... | |
void | reserve (int capacity) |
Reserve memory for specified number of elements. More... | |
void | deallocate () |
Deallocate (delete) underlying array of pointers. More... | |
void | clear () |
Reset to empty state. More... | |
bool | isAllocated () const |
Is this GPArray allocated? More... | |
![]() | |
virtual | ~PArray () |
Destructor. More... | |
int | capacity () const |
Return allocated size. More... | |
int | size () const |
Return logical size. More... | |
void | begin (PArrayIterator< Data > &iterator) const |
Set a PArrayIterator to the beginning of this PArray. More... | |
void | begin (ConstPArrayIterator< Data > &iterator) const |
Set a ConstPArrayIterator to the beginning of this PArray. More... | |
Data & | operator[] (int i) const |
Mimic C array subscripting. More... | |
Additional Inherited Members | |
![]() | |
PArray () | |
Constructor (protected to prevent instantiation). More... | |
![]() | |
Data ** | ptrs_ |
PArray of of pointers to Data objects. More... | |
int | capacity_ |
Allocated size of ptrs_ array. More... | |
int | size_ |
Logical size (number of elements with initialized data). More... | |
|
inline |
Util::GPArray< Data >::GPArray | ( | const GPArray< Data > & | other | ) |
Copy constructor, copy pointers.
Allocates new Data* array and copies pointers to Data objects.
other | the GPArray to be copied. |
Allocates a new Data* array and copies all pointer values.
other | the GPArray to be copied. |
Definition at line 125 of file GPArray.h.
References Util::PArray< Data >::capacity_, Util::PArray< Data >::ptrs_, and Util::PArray< Data >::size_.
|
virtual |
Destructor.
Deletes array of pointers, if allocated previously. Does not delete the associated Data objects.
Definition at line 176 of file GPArray.h.
References Util::PArray< Data >::capacity_, Util::Memory::deallocate(), Util::GPArray< Data >::isAllocated(), Util::PArray< Data >::ptrs_, and Util::PArray< Data >::size_.
GPArray< Data > & Util::GPArray< Data >::operator= | ( | const GPArray< Data > & | other | ) |
Assignment, element by element.
Preconditions:
other | the rhs GPArray |
Definition at line 160 of file GPArray.h.
References Util::GPArray< Data >::append(), Util::GPArray< Data >::clear(), and Util::PArray< Data >::size_.
void Util::GPArray< Data >::append | ( | Data & | data | ) |
Append an element to the end of the sequence.
Resizes array if space is inadequate.
data | Data object to be appended |
Definition at line 235 of file GPArray.h.
References Util::PArray< Data >::capacity_, Util::GPArray< Data >::isAllocated(), Util::PArray< Data >::ptrs_, and Util::PArray< Data >::size_.
Referenced by Util::GPArray< Data >::operator=().
void Util::GPArray< Data >::reserve | ( | int | capacity | ) |
Reserve memory for specified number of elements.
Resizes and copies array if requested capacity is less than the current capacity. Does nothing if requested capacity is greater than current capacity.
capacity | number of elements for which to reserve space. |
Definition at line 189 of file GPArray.h.
References Util::PArray< Data >::capacity(), Util::PArray< Data >::capacity_, Util::PArray< Data >::ptrs_, Util::PArray< Data >::size_, and UTIL_THROW.
void Util::GPArray< Data >::deallocate | ( | ) |
Deallocate (delete) underlying array of pointers.
Definition at line 221 of file GPArray.h.
References Util::PArray< Data >::capacity_, Util::GPArray< Data >::isAllocated(), Util::PArray< Data >::ptrs_, and Util::PArray< Data >::size_.
|
inline |
Reset to empty state.
Definition at line 268 of file GPArray.h.
References Util::PArray< Data >::size_.
Referenced by Util::GPArray< Data >::operator=().
|
inline |
Is this GPArray allocated?
Definition at line 275 of file GPArray.h.
References Util::PArray< Data >::ptrs_.
Referenced by Util::GPArray< Data >::append(), Util::GPArray< Data >::deallocate(), and Util::GPArray< Data >::~GPArray().