Template class for the stop reason of a stop type.
More...
#include <StopReason.hpp>
|
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...
|
|
template<typename T>
class StopReason< T >
Template class for the stop reason of a stop type.
The possible stop types can be generic: IterStopType, EvalGlobalStopType, EvalMainThreadStopType, 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 do not need propagation and others must be propagated to stop an algorithm (see StopReason::checkTerminate()).
Definition at line 195 of file StopReason.hpp.
◆ StopReason()
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 246 of file StopReason.hpp.
◆ ~StopReason()
◆ checkTerminate()
Check if the stop reason requires a termination.
This is implemented for each stop type (template specialization of the function).
Except for EvalMainThreadStopType, 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.
◆ dict()
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.
◆ get()
◆ getStopReasonAsString()
template<typename T >
std::string StopReason< T >::getStopReasonAsString |
( |
| ) |
const |
|
inline |
Translate the stop reason into a string for display.
Definition at line 287 of file StopReason.hpp.
289 typename std::map<T,std::string>::iterator it =
dict().find(
_stopReason );
◆ isStarted()
◆ set()
Set the stop reason if it is listed in dictionnary.
Definition at line 264 of file StopReason.hpp.
266 typename std::map<T,std::string>::iterator it =
dict().find(s);
268 if ( it==
dict().end() )
269 throw Exception(__FILE__,__LINE__,
"Stop reason not found.");
◆ setStarted()
Reset the stop reason to the default STARTED state.
Definition at line 275 of file StopReason.hpp.
◆ testValidity()
Helper for constructor (check sanity)
Definition at line 210 of file StopReason.hpp.
212 if ( ! std::is_enum<T>::value )
213 throw Exception(__FILE__,__LINE__,
"The templated stop reason is not an enum.");
215 if (
dict().size() == 0 )
216 throw Exception(__FILE__,__LINE__,
"Dictionary not filled.");
219 if ( (
int) T::STARTED != 0 )
220 throw Exception(__FILE__,__LINE__,
"First StopType in enum must be STARTED.");
222 if ( (
int) T::LAST !=
dict().size() )
224 std::string s =
"Not enough elements in enum dictionary (";
225 s += std::to_string(
dict().size()) +
"), expecting " + std::to_string((
int)T::LAST);
229 for (
int i = (
int) T::STARTED; i < (int ) T::LAST; i++)
231 typename std::map<T,std::string>::iterator it =
dict().find( (T) i );
233 if ( it==
dict().end() )
234 throw Exception(__FILE__,__LINE__,
"All enum elements must be in dictionary.");
◆ _stopReason
The stop reason stored as a stop type.
Definition at line 200 of file StopReason.hpp.
The documentation for this class was generated from the following file: