PSCF v1.1
Public Member Functions | Protected Attributes | List of all members
Util::SSet< Data, Capacity > Class Template Reference

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...
 

Detailed Description

template<typename Data, int Capacity>
class Util::SSet< Data, Capacity >

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.

Definition at line 43 of file SSet.h.

Constructor & Destructor Documentation

◆ SSet() [1/2]

template<typename Data , int Capacity>
Util::SSet< Data, Capacity >::SSet
inline

Default constructor.

Definition at line 177 of file SSet.h.

◆ SSet() [2/2]

template<typename Data , int Capacity>
Util::SSet< Data, Capacity >::SSet ( SSet< Data, Capacity > const &  other)

Copy constructor.

Copies all pointers.

Parameters
otherthe SSet to be copied.

Definition at line 185 of file SSet.h.

References Util::SSet< Data, Capacity >::ptrs_, and Util::SSet< Data, Capacity >::size_.

◆ ~SSet()

template<typename Data , int Capacity>
Util::SSet< Data, Capacity >::~SSet

Destructor.

Definition at line 240 of file SSet.h.

Member Function Documentation

◆ operator=()

template<typename Data , int Capacity>
SSet< Data, Capacity > & Util::SSet< Data, Capacity >::operator= ( SSet< Data, Capacity > const &  other)

Assignment, element by element.

Parameters
otherthe rhs SSet

Definition at line 209 of file SSet.h.

References Util::SSet< Data, Capacity >::size_, and UTIL_THROW.

◆ append()

template<typename Data , int Capacity>
void Util::SSet< Data, Capacity >::append ( Data &  data)
inline

Add an object to the set.

Appends a pointer to the object to the end of the sequence.

Parameters
dataData to add to end of array.

Definition at line 309 of file SSet.h.

References UTIL_THROW.

◆ remove()

template<typename Data , int Capacity>
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.

Exceptions
Exceptionif object data is not in the Set.
Parameters
dataobject to be removed.

Definition at line 334 of file SSet.h.

References UTIL_THROW.

◆ clear()

template<typename Data , int Capacity>
void Util::SSet< Data, Capacity >::clear
inline

Set logical size to zero and nullify all elements.

Definition at line 322 of file SSet.h.

◆ capacity()

template<typename Data , int Capacity>
int Util::SSet< Data, Capacity >::capacity
inline

Return physical capacity of array.

Definition at line 247 of file SSet.h.

◆ size()

template<typename Data , int Capacity>
int Util::SSet< Data, Capacity >::size
inline

◆ isElement()

template<typename Data , int Capacity>
bool Util::SSet< Data, Capacity >::isElement ( Data const &  data) const

Is an object an element of the set?

Parameters
dataobject of interest.

Definition at line 366 of file SSet.h.

◆ index()

template<typename Data , int Capacity>
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.

Parameters
dataobject of interest.
Returns
current index of pointer to element within this SSet.

Definition at line 387 of file SSet.h.

◆ begin() [1/2]

template<typename Data , int Capacity>
void Util::SSet< Data, Capacity >::begin ( PArrayIterator< Data > &  iterator)
inline

Set a PArrayIterator to the beginning of this Array.

Parameters
iteratorPArrayIterator, initialized on output.

Definition at line 263 of file SSet.h.

References Util::PArrayIterator< Data >::setCurrent(), and Util::PArrayIterator< Data >::setEnd().

◆ begin() [2/2]

template<typename Data , int Capacity>
void Util::SSet< Data, Capacity >::begin ( ConstPArrayIterator< Data > &  iterator) const
inline

Set a ConstPArrayIterator to the beginning of this Array.

Parameters
iteratorConstPArrayIterator, initialized on output.

Definition at line 274 of file SSet.h.

References Util::ConstPArrayIterator< Data >::setCurrent(), and Util::ConstPArrayIterator< Data >::setEnd().

◆ operator[]() [1/2]

template<typename Data , int Capacity>
Data & Util::SSet< Data, Capacity >::operator[] ( int  i)
inline

Mimic C array subscripting.

Parameters
iarray index
Returns
reference to element i

Definition at line 285 of file SSet.h.

◆ operator[]() [2/2]

template<typename Data , int Capacity>
Data const & Util::SSet< Data, Capacity >::operator[] ( int  i) const
inline

Mimic C array subscripting.

Parameters
iarray index
Returns
const reference to element i

Definition at line 296 of file SSet.h.

Member Data Documentation

◆ ptrs_

template<typename Data , int Capacity>
Data* Util::SSet< Data, Capacity >::ptrs_[Capacity]
protected

Array of pointers to Data objects.

Definition at line 164 of file SSet.h.

Referenced by Util::SSet< Data, Capacity >::SSet().

◆ size_

template<typename Data , int Capacity>
int Util::SSet< Data, Capacity >::size_
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().


The documentation for this class was generated from the following file: