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

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.

#include <SSet.h>

Public Member Functions

 SSet ()
 Default constructor. More...
 
 SSet (const SSet< Data, Capacity > &other)
 Copy constructor. More...
 
SSet< Data, Capacity > & operator= (const SSet< Data, Capacity > &other)
 Assignment, element by element. More...
 
 ~SSet ()
 Destructor. More...
 
void append (Data &data)
 Add an object to the set. More...
 
void remove (const Data &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 (const Data &data) const
 Is an object an element of the set? More...
 
int index (const Data &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...
 
const Data & 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...
 

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 177 of file SSet.h.

template<typename Data , int Capacity>
Util::SSet< Data, Capacity >::SSet ( const SSet< Data, Capacity > &  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_.

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

Destructor.

Definition at line 240 of file SSet.h.

Member Function Documentation

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

Assignment, element by element.

Parameters
otherthe rhs SSet

Definition at line 209 of file SSet.h.

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

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 307 of file SSet.h.

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

template<typename Data , int Capacity>
void Util::SSet< Data, Capacity >::remove ( const Data &  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 332 of file SSet.h.

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

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

Set logical size to zero and nullify all elements.

Definition at line 320 of file SSet.h.

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

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

Return physical capacity of array.

Definition at line 247 of file SSet.h.

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

Return logical size of this array.

Definition at line 254 of file SSet.h.

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

Referenced by McMd::LinkPotentialImpl< Interaction >::atomEnergy().

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

Is an object an element of the set?

Parameters
dataobject of interest.

Definition at line 364 of file SSet.h.

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

template<typename Data , int Capacity>
int Util::SSet< Data, Capacity >::index ( const Data &  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 385 of file SSet.h.

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

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::SSet< Data, Capacity >::ptrs_, Util::PArrayIterator< Data >::setCurrent(), Util::PArrayIterator< Data >::setEnd(), and Util::SSet< Data, Capacity >::size_.

Referenced by McMd::LinkMaster::begin().

template<typename Data , int Capacity>
void Util::SSet< Data, Capacity >::begin ( ConstPArrayIterator< Data > &  iterator) const
inline
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 283 of file SSet.h.

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

template<typename Data , int Capacity>
const Data & 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 294 of file SSet.h.

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

Member Data Documentation

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

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