PSCF v1.1
Public Member Functions | List of all members
Util::Setable< T > Class Template Reference

Template for a value that can be set or declared null (i.e., unknown). More...

#include <Setable.h>

Public Member Functions

 Setable ()
 Default constructor. More...
 
 Setable (const Setable< T > &other)
 Copy constructor. More...
 
 Setable (const T &value)
 Construct from T value (explicit). More...
 
Setable< T > & operator= (const Setable< T > &other)
 Assignment from another Setable<T> object. More...
 
Setable< T > & operator= (const T &value)
 Assignment from T value. More...
 
void set (const T &value)
 Set the value and mark as set. More...
 
void unset ()
 Unset the value (mark as unknown). More...
 
bool isSet () const
 Is this object set (is the value known)? More...
 
const T & value () const
 Return value (if set). More...
 
bool isValid (MPI::Intracomm &communicator) const
 Test consistency of states on different processors. More...
 

Detailed Description

template<class T>
class Util::Setable< T >

Template for a value that can be set or declared null (i.e., unknown).

Type T must be copy-constructable and have an assignment (=) operator.

Convention for MPI programs: In parallel MPI programs in which a value for a variable is calculated by a reduce operation and is set only on a master processor, a default value should be set on all other processors whenever the true value is set on the master. This indicates on all processors that the value is known, though it may only be available on the master processor. Similarly, when a value is unset, the unset() function should be called on all processors. This convention allows the isSet() function to be used on all processors to query whether the value is known, which may be then be used to decide when to initiate a recomputation that may require computation on all processors. This convention is imposed by the isValid() function, which requires that isSet have the same value on all processors within a communicator (i.e., all true or all false).

Definition at line 38 of file Setable.h.

Constructor & Destructor Documentation

◆ Setable() [1/3]

template<class T >
Util::Setable< T >::Setable ( )
inline

Default constructor.

Definition at line 46 of file Setable.h.

◆ Setable() [2/3]

template<class T >
Util::Setable< T >::Setable ( const Setable< T > &  other)
inline

Copy constructor.

Parameters
otherSetable object being copied.

Definition at line 56 of file Setable.h.

◆ Setable() [3/3]

template<class T >
Util::Setable< T >::Setable ( const T &  value)
inlineexplicit

Construct from T value (explicit).

Parameters
valuevalue of wrapped object

Definition at line 66 of file Setable.h.

Member Function Documentation

◆ operator=() [1/2]

template<class T >
Setable< T > & Util::Setable< T >::operator= ( const Setable< T > &  other)
inline

Assignment from another Setable<T> object.

Parameters
otherobject on RHS of assignment

Definition at line 76 of file Setable.h.

◆ operator=() [2/2]

template<class T >
Setable< T > & Util::Setable< T >::operator= ( const T &  value)
inline

Assignment from T value.

Equivalent to set(value). Sets the value and marks it as set.

Parameters
valueT value on RHS of assignment
Returns
this object

Definition at line 95 of file Setable.h.

References Util::Setable< T >::value().

◆ set()

template<class T >
void Util::Setable< T >::set ( const T &  value)
inline

Set the value and mark as set.

Parameters
valuevalue to be assigned.

Definition at line 107 of file Setable.h.

References Util::Setable< T >::value().

◆ unset()

template<class T >
void Util::Setable< T >::unset ( )
inline

Unset the value (mark as unknown).

Definition at line 116 of file Setable.h.

◆ isSet()

template<class T >
bool Util::Setable< T >::isSet ( ) const
inline

Is this object set (is the value known)?

Returns
true if set (known), false if null (unknown).

Definition at line 124 of file Setable.h.

◆ value()

template<class T >
const T & Util::Setable< T >::value ( ) const
inline

Return value (if set).

Throws an Exception if value is not set.

Definition at line 132 of file Setable.h.

References UTIL_THROW.

Referenced by Util::Setable< T >::operator=(), and Util::Setable< T >::set().

◆ isValid()

template<typename T >
bool Util::Setable< T >::isValid ( MPI::Intracomm &  communicator) const

Test consistency of states on different processors.

If valid, return true, else throws an Exception. The state is valid if the value of isSet is the same on all processors.

Definition at line 163 of file Setable.h.

References UTIL_THROW.


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