thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
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
13
namespace
ThePEG
{
14
26
template
<
typename
ExceptionT = Exception,
27
typename
MessageT =
const
char
*>
28
class
LoopGuard
{
29
30
public
:
31
37
LoopGuard
(
const
MessageT & mess,
long
maxc = 1000000 )
38
:
count
(0),
maxCount
(maxc),
message
(mess) {}
39
44
void
operator()
()
45
{
46
if
( ++
count
>
maxCount
)
throw
ExceptionT(
message
);
47
}
48
49
private
:
50
54
long
count
;
55
59
long
maxCount
;
60
65
const
MessageT &
message
;
66
67
private
:
68
72
LoopGuard
();
73
77
LoopGuard
(
const
LoopGuard
&);
78
79
};
80
94
template
<
typename
ExceptionT>
95
class
LoopGuard
<ExceptionT,void> {
96
97
public
:
98
104
LoopGuard
(
long
maxc = 1000000 )
105
:
count
(0),
maxCount
(maxc) {}
106
111
void
operator()
()
112
{
113
if
( ++
count
>
maxCount
)
throw
ExceptionT();
114
}
115
116
private
:
117
121
long
count
;
122
126
long
maxCount
;
127
128
private
:
129
133
LoopGuard
();
134
138
LoopGuard
(
const
LoopGuard
&);
139
140
};
141
142
}
143
144
#endif
/* ThePEG_LoopGuard_H */
ThePEG::LoopGuard< ExceptionT, void >::LoopGuard
LoopGuard(long maxc=1000000)
Create a loop guard object which will throw an exception of type ExceptionT, constructed with 'mess' ...
Definition:
LoopGuard.h:104
ThePEG::LoopGuard< ExceptionT, void >::count
long count
The number of counts so far.
Definition:
LoopGuard.h:121
ThePEG::LoopGuard< ExceptionT, void >::LoopGuard
LoopGuard(const LoopGuard &)
Copy constructor is private and not implemented.
ThePEG::LoopGuard< ExceptionT, void >::maxCount
long maxCount
The maximum number of counts allowed.
Definition:
LoopGuard.h:126
ThePEG::LoopGuard< ExceptionT, void >::operator()
void operator()()
Increase the iteration count and throw an ExceptionT if the maximum number of iterations is exceeded.
Definition:
LoopGuard.h:111
ThePEG::LoopGuard< ExceptionT, void >::LoopGuard
LoopGuard()
Default constructor is private and not implemented.
ThePEG::LoopGuard
A LoopGuard object can be used to throw an exception if a loop is iterated too many times.
Definition:
LoopGuard.h:28
ThePEG::LoopGuard::LoopGuard
LoopGuard()
Default constructor is private and not implemented.
ThePEG::LoopGuard::maxCount
long maxCount
The maximum number of counts allowed.
Definition:
LoopGuard.h:59
ThePEG::LoopGuard::LoopGuard
LoopGuard(const LoopGuard &)
Copy constructor is private and not implemented.
ThePEG::LoopGuard::operator()
void operator()()
Increase the iteration count and throw an ExceptionT if the maximum number of iterations is exceeded.
Definition:
LoopGuard.h:44
ThePEG::LoopGuard::count
long count
The number of counts so far.
Definition:
LoopGuard.h:54
ThePEG::LoopGuard::message
const MessageT & message
The message with which the thrown ExceptionT object will be initialized.
Definition:
LoopGuard.h:65
ThePEG::LoopGuard::LoopGuard
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
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6