NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StopReason< T > Class Template Reference

Template class for the stop reason of a stop type. More...

#include <StopReason.hpp>

Collaboration diagram for StopReason< T >:

Public Member Functions

 StopReason ()
 Constructor. More...
 
 ~StopReason ()
 Destructor. More...
 
get () const
 The stop reason. More...
 
void set (T s)
 Set the stop reason if it is listed in dictionnary. More...
 
void setStarted ()
 Reset the stop reason to the default STARTED state. More...
 
bool isStarted () const
 Check if it is in STARTED state. More...
 
std::string getStopReasonAsString () const
 Translate the stop reason into a string for display. More...
 
bool checkTerminate () const
 Check if the stop reason requires a termination. More...
 

Private Member Functions

std::map< T, std::string > & dict () const
 Dictionnary to translate a stop type into a string. More...
 
void testValidity () const
 Helper for constructor (check sanity) More...
 

Private Attributes

_stopReason
 The stop reason stored as a stop type. More...
 

Detailed Description

template<typename T>
class StopReason< T >

Template class for the stop reason of a stop type.

The possible stop types can be generic: IterStopType, EvalStopType, BaseStopType, or specific to an algorithm: MadsStopType, PhaseOneStopType, NMStopType ,....

The default stop type is STARTED (no stop). A stop reason different than STARTED indicates what is the cause of termination. Some stop reasons indicate a normal termination that don't need propagation and other must be propagated to stop an algorithm (see StopReason::checkTerminate()).

Definition at line 99 of file StopReason.hpp.

Constructor & Destructor Documentation

template<typename T>
StopReason< T >::StopReason ( )
inlineexplicit

Constructor.

Upon construction, the validity of the stop reason is verified (sanity check).
By default the stop reason is set to STARTED.

Definition at line 147 of file StopReason.hpp.

148  {
149  testValidity();
150 
151  _stopReason = T::STARTED;
152 
153  }
void testValidity() const
Helper for constructor (check sanity)
Definition: StopReason.hpp:114
T _stopReason
The stop reason stored as a stop type.
Definition: StopReason.hpp:104
template<typename T>
StopReason< T >::~StopReason ( )
inline

Destructor.

Definition at line 156 of file StopReason.hpp.

157  {}

Member Function Documentation

template<typename T>
bool StopReason< T >::checkTerminate ( ) const

Check if the stop reason requires a termination.

This is implemented for each stop type (template specialization of the function).
Except for EvalStopType, a stop reason different than STARTED indicates that an algorithm or a sub-algorithm must terminate.

Returns
true if a termination is required, false otherwise.
template<typename T>
std::map<T,std::string>& StopReason< T >::dict ( ) const
private

Dictionnary to translate a stop type into a string.

We have template specializations of this function for each stop type. This function is called to display the stop reason.

template<typename T>
T StopReason< T >::get ( ) const
inline

The stop reason.

Definition at line 160 of file StopReason.hpp.

161  {
162  return _stopReason;
163  }
T _stopReason
The stop reason stored as a stop type.
Definition: StopReason.hpp:104
template<typename T>
std::string StopReason< T >::getStopReasonAsString ( ) const
inline

Translate the stop reason into a string for display.

Definition at line 189 of file StopReason.hpp.

190  {
191  typename std::map<T,std::string>::iterator it = dict().find( _stopReason );
192  return it->second;
193  }
T _stopReason
The stop reason stored as a stop type.
Definition: StopReason.hpp:104
std::map< T, std::string > & dict() const
Dictionnary to translate a stop type into a string.
template<typename T>
bool StopReason< T >::isStarted ( ) const
inline

Check if it is in STARTED state.

Definition at line 183 of file StopReason.hpp.

184  {
185  return ( _stopReason == T::STARTED );
186  }
T _stopReason
The stop reason stored as a stop type.
Definition: StopReason.hpp:104
template<typename T>
void StopReason< T >::set ( s)
inline

Set the stop reason if it is listed in dictionnary.

Definition at line 166 of file StopReason.hpp.

167  {
168  typename std::map<T,std::string>::iterator it = dict().find(s);
169 
170  if ( it==dict().end() )
171  throw Exception(__FILE__,__LINE__,"Stop reason not found.");
172 
173  _stopReason = s;
174  }
Exception utility.
T _stopReason
The stop reason stored as a stop type.
Definition: StopReason.hpp:104
std::map< T, std::string > & dict() const
Dictionnary to translate a stop type into a string.
template<typename T>
void StopReason< T >::setStarted ( )
inline

Reset the stop reason to the default STARTED state.

Definition at line 177 of file StopReason.hpp.

178  {
179  _stopReason = T::STARTED;
180  }
T _stopReason
The stop reason stored as a stop type.
Definition: StopReason.hpp:104
template<typename T>
void StopReason< T >::testValidity ( ) const
inlineprivate

Helper for constructor (check sanity)

Definition at line 114 of file StopReason.hpp.

115  {
116  if ( ! std::is_enum<T>::value )
117  throw Exception(__FILE__,__LINE__,"The templated stop reason is not an enum.");
118 
119  if ( dict().size() == 0 )
120  throw Exception(__FILE__,__LINE__,"Dictionary not filled.");
121 
122 
123  if ( (int) T::STARTED != 0 )
124  throw Exception(__FILE__,__LINE__,"First StopType in enum must be STARTED.");
125 
126  if ( (int) T::LAST != dict().size() )
127  throw Exception(__FILE__,__LINE__,"Not enough elements in enum dictionary.");
128 
129 
130  for (int i = (int) T::STARTED; i < (int ) T::LAST; i++)
131  {
132  typename std::map<T,std::string>::iterator it = dict().find( (T) i );
133 
134  if ( it== dict().end() )
135  throw Exception(__FILE__,__LINE__,"All enum elements must be in dictionary.");
136 
137  }
138 
139  }
Exception utility.
std::map< T, std::string > & dict() const
Dictionnary to translate a stop type into a string.

Member Data Documentation

template<typename T>
T StopReason< T >::_stopReason
private

The stop reason stored as a stop type.

Definition at line 104 of file StopReason.hpp.


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