thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::LoopGuard< ExceptionT, MessageT > Class Template Reference

A LoopGuard object can be used to throw an exception if a loop is iterated too many times. More...

#include <LoopGuard.h>

Public Member Functions

 LoopGuard (const MessageT &mess, long maxc=1000000)
 Create a loop guard object which will throw an exception of type ExceptionT, constructed with 'mess' as argument, if the maximum number of iterations is exceeded.
 
void operator() ()
 Increase the iteration count and throw an ExceptionT if the maximum number of iterations is exceeded.
 

Private Member Functions

 LoopGuard ()
 Default constructor is private and not implemented.
 
 LoopGuard (const LoopGuard &)
 Copy constructor is private and not implemented.
 

Private Attributes

long count
 The number of counts so far.
 
long maxCount
 The maximum number of counts allowed.
 
const MessageT & message
 The message with which the thrown ExceptionT object will be initialized.
 

Detailed Description

template<typename ExceptionT = Exception, typename MessageT = const char *>
class ThePEG::LoopGuard< ExceptionT, MessageT >

A LoopGuard object can be used to throw an exception if a loop is iterated too many times.

It is used by constructing an object before the loop giving the maximum number of iterations allowed and a message to be used as argument to the constructor of the exception to be thrown. Inside the loop the parenthesis is called without argument, which will increment and check an internal counter.

See also
Level

Definition at line 28 of file LoopGuard.h.

Constructor & Destructor Documentation

◆ LoopGuard()

template<typename ExceptionT = Exception, typename MessageT = const char *>
ThePEG::LoopGuard< ExceptionT, MessageT >::LoopGuard ( const MessageT &  mess,
long  maxc = 1000000 
)
inline

Create a loop guard object which will throw an exception of type ExceptionT, constructed with 'mess' as argument, if the maximum number of iterations is exceeded.

Definition at line 37 of file LoopGuard.h.

Member Function Documentation

◆ operator()()

template<typename ExceptionT = Exception, typename MessageT = const char *>
void ThePEG::LoopGuard< ExceptionT, MessageT >::operator() ( )
inline

Increase the iteration count and throw an ExceptionT if the maximum number of iterations is exceeded.

Definition at line 44 of file LoopGuard.h.

References ThePEG::LoopGuard< ExceptionT, MessageT >::count, ThePEG::LoopGuard< ExceptionT, MessageT >::maxCount, and ThePEG::LoopGuard< ExceptionT, MessageT >::message.

Member Data Documentation

◆ count

template<typename ExceptionT = Exception, typename MessageT = const char *>
long ThePEG::LoopGuard< ExceptionT, MessageT >::count
private

The number of counts so far.

Definition at line 54 of file LoopGuard.h.

Referenced by ThePEG::LoopGuard< ExceptionT, MessageT >::operator()(), and ThePEG::LoopGuard< ExceptionT, void >::operator()().

◆ maxCount

template<typename ExceptionT = Exception, typename MessageT = const char *>
long ThePEG::LoopGuard< ExceptionT, MessageT >::maxCount
private

The maximum number of counts allowed.

Definition at line 59 of file LoopGuard.h.

Referenced by ThePEG::LoopGuard< ExceptionT, MessageT >::operator()(), and ThePEG::LoopGuard< ExceptionT, void >::operator()().

◆ message

template<typename ExceptionT = Exception, typename MessageT = const char *>
const MessageT& ThePEG::LoopGuard< ExceptionT, MessageT >::message
private

The message with which the thrown ExceptionT object will be initialized.

Definition at line 65 of file LoopGuard.h.

Referenced by ThePEG::LoopGuard< ExceptionT, MessageT >::operator()().


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