thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
HoldFlag.h
1 // -*- C++ -*-
2 //
3 // HoldFlag.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_HoldFlag_H
10 #define ThePEG_HoldFlag_H
11 // This is the declaration of the HoldFlag class.
12 
13 namespace ThePEG {
14 
15 template <typename T = bool>
23 class HoldFlag {
24 
25 public:
26 
32  HoldFlag(T & newFlag, const T & holdFlag)
33  : theFlag(newFlag), oldFlag(holdFlag) { std::swap(theFlag, oldFlag); }
34 
42  HoldFlag(T & newFlag, const T & holdFlag, const T & finalFlag)
43  : theFlag(newFlag), oldFlag(holdFlag)
44  {
45  std::swap(theFlag, oldFlag);
46  oldFlag = finalFlag;
47  }
48 
53  ~HoldFlag() { std::swap(theFlag, oldFlag); }
54 
55 private:
56 
60  T & theFlag;
61 
66 
70  HoldFlag();
71 
75  HoldFlag(const HoldFlag &);
76 
80  HoldFlag & operator=(const HoldFlag &) = delete;
81 
82 };
83 
87 template <>
88 class HoldFlag<bool> {
89 
90 public:
91 
97  HoldFlag(bool & newFlag, bool holdFlag = true)
98  : theFlag(newFlag), oldFlag(newFlag) { theFlag = holdFlag; }
99 
107  HoldFlag(bool & newFlag, bool holdFlag, bool finalFlag)
108  : theFlag(newFlag), oldFlag(finalFlag) { theFlag = holdFlag; }
109 
115 
116 private:
117 
121  bool & theFlag;
122 
126  bool oldFlag;
127 
131  HoldFlag();
132 
136  HoldFlag(const HoldFlag &);
137 
141  HoldFlag & operator=(const HoldFlag &) = delete;
142 
143 };
144 
145 }
146 
147 #endif /* ThePEG_HoldFlag_H */
HoldFlag(T &newFlag, const T &holdFlag)
Constructor setting a temporary value for the given object.
Definition: HoldFlag.h:32
T oldFlag
The value which will be restored when this is destroyed.
Definition: HoldFlag.h:65
HoldFlag()
Default constructor is private and not implemented.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
HoldFlag(bool &newFlag, bool holdFlag=true)
Constructor setting the a temporary value for the bool variable.
Definition: HoldFlag.h:97
~HoldFlag()
Destructor.
Definition: HoldFlag.h:53
HoldFlag(bool &newFlag, bool holdFlag, bool finalFlag)
Constructor setting the a temporary value for the bool variable.
Definition: HoldFlag.h:107
bool oldFlag
The value which will be restored when this is destroyed.
Definition: HoldFlag.h:126
bool & theFlag
The variable to be changed.
Definition: HoldFlag.h:121
HoldFlag(T &newFlag, const T &holdFlag, const T &finalFlag)
Constructor setting the a temporary value for the given object.
Definition: HoldFlag.h:42
HoldFlag objects are used to temporarily change the value of an object, restoring the original value ...
Definition: HoldFlag.h:23
T & theFlag
The object to be changed.
Definition: HoldFlag.h:60
HoldFlag & operator=(const HoldFlag &)=delete
Assignment is private and not implemented.
~HoldFlag()
Destructor.
Definition: HoldFlag.h:114