thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
13namespace ThePEG {
14
15template <typename T = bool>
23class HoldFlag {
24
25public:
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 {
46 oldFlag = finalFlag;
47 }
48
54
55private:
56
61
66
71
76
80 HoldFlag & operator=(const HoldFlag &) = delete;
81
82};
83
87template <>
88class HoldFlag<bool> {
89
90public:
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
116private:
117
121 bool & theFlag;
122
127
132
137
141 HoldFlag & operator=(const HoldFlag &) = delete;
142
143};
144
145}
146
147#endif /* ThePEG_HoldFlag_H */
HoldFlag(bool &newFlag, bool holdFlag, bool finalFlag)
Constructor setting the a temporary value for the bool variable.
Definition: HoldFlag.h:107
bool & theFlag
The variable to be changed.
Definition: HoldFlag.h:121
HoldFlag(const HoldFlag &)
Copy constructor is private and not implemented.
HoldFlag(bool &newFlag, bool holdFlag=true)
Constructor setting the a temporary value for the bool variable.
Definition: HoldFlag.h:97
HoldFlag()
Default constructor is private and not implemented.
bool oldFlag
The value which will be restored when this is destroyed.
Definition: HoldFlag.h:126
~HoldFlag()
Destructor.
Definition: HoldFlag.h:114
HoldFlag & operator=(const HoldFlag &)=delete
Assignment is private and not implemented.
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.
T oldFlag
The value which will be restored when this is destroyed.
Definition: HoldFlag.h:65
~HoldFlag()
Destructor.
Definition: HoldFlag.h:53
HoldFlag(const HoldFlag &)
Copy constructor is private and not implemented.
HoldFlag()
Default constructor is private and not implemented.
HoldFlag(T &newFlag, const T &holdFlag)
Constructor setting a temporary value for the given object.
Definition: HoldFlag.h:32
HoldFlag(T &newFlag, const T &holdFlag, const T &finalFlag)
Constructor setting the a temporary value for the given object.
Definition: HoldFlag.h:42
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
void swap(ThePEG::Pointer::RCPtr< T > &t1, ThePEG::Pointer::RCPtr< T > &t2)
Specialization of std::swap to avoid unnecessary (in/de)crements of the reference count.
Definition: RCPtr.h:1154