thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
LoopGuard.h
1// -*- C++ -*-
2//
3// LoopGuard.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_LoopGuard_H
10#define ThePEG_LoopGuard_H
11// This is the declaration of the LoopGuard class.
12
13namespace ThePEG {
14
26template <typename ExceptionT = Exception,
27 typename MessageT = const char *>
28class LoopGuard {
29
30public:
31
37 LoopGuard(const MessageT & mess, long maxc = 1000000 )
38 : count(0), maxCount(maxc), message(mess) {}
39
45 {
46 if ( ++count > maxCount ) throw ExceptionT(message);
47 }
48
49private:
50
54 long count;
55
60
65 const MessageT & message;
66
67private:
68
73
78
79};
80
94template <typename ExceptionT>
95class LoopGuard<ExceptionT,void> {
96
97public:
98
104 LoopGuard(long maxc = 1000000 )
105 : count(0), maxCount(maxc) {}
106
112 {
113 if ( ++count > maxCount ) throw ExceptionT();
114 }
115
116private:
117
121 long count;
122
127
128private:
129
134
139
140};
141
142}
143
144#endif /* ThePEG_LoopGuard_H */
LoopGuard(long maxc=1000000)
Create a loop guard object which will throw an exception of type ExceptionT, constructed with 'mess' ...
Definition: LoopGuard.h:104
long count
The number of counts so far.
Definition: LoopGuard.h:121
LoopGuard(const LoopGuard &)
Copy constructor is private and not implemented.
long maxCount
The maximum number of counts allowed.
Definition: LoopGuard.h:126
void operator()()
Increase the iteration count and throw an ExceptionT if the maximum number of iterations is exceeded.
Definition: LoopGuard.h:111
LoopGuard()
Default constructor is private and not implemented.
A LoopGuard object can be used to throw an exception if a loop is iterated too many times.
Definition: LoopGuard.h:28
LoopGuard()
Default constructor is private and not implemented.
long maxCount
The maximum number of counts allowed.
Definition: LoopGuard.h:59
LoopGuard(const LoopGuard &)
Copy constructor is private and not implemented.
void operator()()
Increase the iteration count and throw an ExceptionT if the maximum number of iterations is exceeded.
Definition: LoopGuard.h:44
long count
The number of counts so far.
Definition: LoopGuard.h:54
const MessageT & message
The message with which the thrown ExceptionT object will be initialized.
Definition: LoopGuard.h:65
LoopGuard(const MessageT &mess, long maxc=1000000)
Create a loop guard object which will throw an exception of type ExceptionT, constructed with 'mess' ...
Definition: LoopGuard.h:37
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28