|
|
|||
File indexing completed on 2026-08-06 09:38:32
0001 // -*- C++ -*- 0002 // 0003 // HoldFlag.h is a part of ThePEG - Toolkit for HEP Event Generation 0004 // Copyright (C) 1999-2019 Leif Lonnblad 0005 // 0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details. 0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 0008 // 0009 #ifndef ThePEG_HoldFlag_H 0010 #define ThePEG_HoldFlag_H 0011 // This is the declaration of the HoldFlag class. 0012 0013 namespace ThePEG { 0014 0015 template <typename T = bool> 0016 /** 0017 * <code>HoldFlag</code> objects are used to temporarily change the value 0018 * of an object, restoring the original value when the 0019 * <code>HoldFlag</code> object is destructed. 0020 * 0021 * @see Level 0022 */ 0023 class HoldFlag { 0024 0025 public: 0026 0027 /** 0028 * Constructor setting a temporary value for the given object. 0029 * @param newFlag the object which value is temporarily changed. 0030 * @param holdFlag the temporary value for the newFlag object. 0031 */ 0032 HoldFlag(T & newFlag, const T & holdFlag) 0033 : theFlag(newFlag), oldFlag(holdFlag) { std::swap(theFlag, oldFlag); } 0034 0035 /** 0036 * Constructor setting the a temporary value for the given object. 0037 * @param newFlag the object which value is temporarily changed. 0038 * @param holdFlag the temporary value for the newFlag object. 0039 * @param finalFlag the newFlag object will be given the value 0040 * finalFlag when the HoldFlag object is destroyed. 0041 */ 0042 HoldFlag(T & newFlag, const T & holdFlag, const T & finalFlag) 0043 : theFlag(newFlag), oldFlag(holdFlag) 0044 { 0045 std::swap(theFlag, oldFlag); 0046 oldFlag = finalFlag; 0047 } 0048 0049 /** 0050 * Destructor. Restores the corresponding object to its original 0051 * value. 0052 */ 0053 ~HoldFlag() { std::swap(theFlag, oldFlag); } 0054 0055 private: 0056 0057 /** 0058 * The object to be changed. 0059 */ 0060 T & theFlag; 0061 0062 /** 0063 * The value which will be restored when this is destroyed. 0064 */ 0065 T oldFlag; 0066 0067 /** 0068 * Default constructor is private and not implemented. 0069 */ 0070 HoldFlag(); 0071 0072 /** 0073 * Copy constructor is private and not implemented. 0074 */ 0075 HoldFlag(const HoldFlag &); 0076 0077 /** 0078 * Assignment is private and not implemented. 0079 */ 0080 HoldFlag & operator=(const HoldFlag &) = delete; 0081 0082 }; 0083 0084 /** 0085 * Specialization of HoldFlag for boolean variables. 0086 */ 0087 template <> 0088 class HoldFlag<bool> { 0089 0090 public: 0091 0092 /** 0093 * Constructor setting the a temporary value for the bool variable. 0094 * @param newFlag the boolean variable which value is temporarily changed. 0095 * @param holdFlag the temporary value for the newFlag variable. 0096 */ 0097 HoldFlag(bool & newFlag, bool holdFlag = true) 0098 : theFlag(newFlag), oldFlag(newFlag) { theFlag = holdFlag; } 0099 0100 /** 0101 * Constructor setting the a temporary value for the bool variable. 0102 * @param newFlag the boolean variable which value is temporarily changed. 0103 * @param holdFlag the temporary value for the newFlag variable. 0104 * @param finalFlag the newFlag variable will be given the value 0105 * finalFlag when the HoldFlag object is destroyed. 0106 */ 0107 HoldFlag(bool & newFlag, bool holdFlag, bool finalFlag) 0108 : theFlag(newFlag), oldFlag(finalFlag) { theFlag = holdFlag; } 0109 0110 /** 0111 * Destructor. Restores the corresponding variable to its original 0112 * value. 0113 */ 0114 ~HoldFlag() { theFlag = oldFlag; } 0115 0116 private: 0117 0118 /** 0119 * The variable to be changed. 0120 */ 0121 bool & theFlag; 0122 0123 /** 0124 * The value which will be restored when this is destroyed. 0125 */ 0126 bool oldFlag; 0127 0128 /** 0129 * Default constructor is private and not implemented. 0130 */ 0131 HoldFlag(); 0132 0133 /** 0134 * Copy constructor is private and not implemented. 0135 */ 0136 HoldFlag(const HoldFlag &); 0137 0138 /** 0139 * Assignment is private and not implemented. 0140 */ 0141 HoldFlag & operator=(const HoldFlag &) = delete; 0142 0143 }; 0144 0145 } 0146 0147 #endif /* ThePEG_HoldFlag_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|