PSCF v1.1
|
Statically allocated array of pointers to an unordered set. More...
#include <SSet.h>
Public Member Functions | |
SSet () | |
Default constructor. More... | |
SSet (SSet< Data, Capacity > const &other) | |
Copy constructor. More... | |
SSet< Data, Capacity > & | operator= (SSet< Data, Capacity > const &other) |
Assignment, element by element. More... | |
~SSet () | |
Destructor. More... | |
void | append (Data &data) |
Add an object to the set. More... | |
void | remove (Data const &data) |
Remove an object from the set. More... | |
void | clear () |
Set logical size to zero and nullify all elements. More... | |
int | capacity () const |
Return physical capacity of array. More... | |
int | size () const |
Return logical size of this array. More... | |
bool | isElement (Data const &data) const |
Is an object an element of the set? More... | |
int | index (Data const &data) const |
Return the current index of an object within the set, if any. More... | |
void | begin (PArrayIterator< Data > &iterator) |
Set a PArrayIterator to the beginning of this Array. More... | |
void | begin (ConstPArrayIterator< Data > &iterator) const |
Set a ConstPArrayIterator to the beginning of this Array. More... | |
Data & | operator[] (int i) |
Mimic C array subscripting. More... | |
Data const & | operator[] (int i) const |
Mimic C array subscripting. More... | |
Protected Attributes | |
Data * | ptrs_ [Capacity] |
Array of pointers to Data objects. More... | |
int | size_ |
Logical size of array (number of elements in array). More... | |
Statically allocated array of pointers to an unordered set.
An SSet is a statically allocated array that holds pointers to a set of objects. It implements the same interface as PArray and FPArray, plus additional remove() and index() methods. As for any pointer array container, the [] operator returns an associated object by reference .
An SSet holds a set of pointers in a contiguous array. The size is the number of pointers now in the container, and the Capacity is the maximum number it can hold. The class is implemented as a wrapper for a statically allocated C array of Capacity elements.
The append method adds a pointer to the end of the sequence. The remove method removes an object from the set, or throws an exception if the object is not found in the set. As for an ArraySet, the remove method repacks the sequence of pointers by moving the last element to the position of the element that is being removed. Removal of an element thus generally changes the order in which the remaining elements are stored.
|
inline |
Util::SSet< Data, Capacity >::SSet | ( | SSet< Data, Capacity > const & | other | ) |
Copy constructor.
Copies all pointers.
other | the SSet to be copied. |
Definition at line 185 of file SSet.h.
References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.
Util::SSet< Data, Capacity >::~SSet |
SSet< Data, Capacity > & Util::SSet< Data, Capacity >::operator= | ( | SSet< Data, Capacity > const & | other | ) |
Assignment, element by element.
other | the rhs SSet |
Definition at line 209 of file SSet.h.
References Util::SSet< Data, Capacity >::size_, and UTIL_THROW.
|
inline |
Add an object to the set.
Appends a pointer to the object to the end of the sequence.
data | Data to add to end of array. |
Definition at line 309 of file SSet.h.
References UTIL_THROW.
void Util::SSet< Data, Capacity >::remove | ( | Data const & | data | ) |
Remove an object from the set.
Removal of an object generally changes the storage order of the remaining objects.
Exception | if object data is not in the Set. |
data | object to be removed. |
Definition at line 334 of file SSet.h.
References UTIL_THROW.
|
inline |
|
inline |
|
inline |
Return logical size of this array.
Definition at line 254 of file SSet.h.
Referenced by pscfpp.file.File::__eq__(), pscfpp.text.Record::__init__(), pscfpp.file.File::__init__(), pscfpp.file.File::__repr__(), and pscfpp.text.Record::__str__().
bool Util::SSet< Data, Capacity >::isElement | ( | Data const & | data | ) | const |
int Util::SSet< Data, Capacity >::index | ( | Data const & | data | ) | const |
Return the current index of an object within the set, if any.
Return the current index of an element within the set, or return -1 if the element is not in the set.
This method returns the current index of the pointer to object data within this SSet, in the range 0 < index < size() - 1. The method returns -1 if data is the object is not in the set.
Throws an exception if data is not in the associated array.
data | object of interest. |
|
inline |
Set a PArrayIterator to the beginning of this Array.
iterator | PArrayIterator, initialized on output. |
Definition at line 263 of file SSet.h.
References Util::PArrayIterator< Data >::setCurrent(), and Util::PArrayIterator< Data >::setEnd().
|
inline |
Set a ConstPArrayIterator to the beginning of this Array.
iterator | ConstPArrayIterator, initialized on output. |
Definition at line 274 of file SSet.h.
References Util::ConstPArrayIterator< Data >::setCurrent(), and Util::ConstPArrayIterator< Data >::setEnd().
|
inline |
|
inline |
|
protected |
Array of pointers to Data objects.
Definition at line 164 of file SSet.h.
Referenced by Util::SSet< Data, Capacity >::SSet().
|
protected |
Logical size of array (number of elements in array).
Definition at line 167 of file SSet.h.
Referenced by Util::SSet< Data, Capacity >::operator=(), and Util::SSet< Data, Capacity >::SSet().