File indexing completed on 2025-01-18 09:57:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 using namespace G4Accumulables;
0036
0037
0038 template <typename T>
0039 G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
0040 : G4VAccumulable(name),
0041 fValue(initValue),
0042 fInitValue(initValue),
0043 fMergeMode(mergeMode),
0044 fMergeFunction(GetMergeFunction<T>(mergeMode))
0045 {}
0046
0047
0048 template <typename T>
0049 G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
0050 : G4VAccumulable(),
0051 fValue(initValue),
0052 fInitValue(initValue),
0053 fMergeMode(mergeMode),
0054 fMergeFunction(GetMergeFunction<T>(mergeMode))
0055 {}
0056
0057
0058 template <typename T>
0059 G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
0060 : G4VAccumulable(rhs),
0061 fValue(rhs.fValue),
0062 fInitValue(rhs.fInitValue),
0063 fMergeMode(rhs.fMergeMode),
0064 fMergeFunction(rhs.fMergeFunction)
0065 {}
0066
0067
0068 template <typename T>
0069 G4Accumulable<T>::G4Accumulable(G4Accumulable&& rhs) noexcept
0070 : G4VAccumulable(rhs),
0071 fValue(std::move(rhs.fValue)),
0072 fInitValue(std::move(rhs.fInitValue)),
0073 fMergeMode(rhs.fMergeMode),
0074 fMergeFunction(rhs.fMergeFunction)
0075 {}
0076
0077
0078 template <typename T>
0079 G4Accumulable<T>&
0080 G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
0081 {
0082
0083 if (this == &rhs) return *this;
0084
0085
0086 G4VAccumulable::operator=(rhs);
0087
0088
0089 fValue = rhs.fValue;
0090 fInitValue = rhs.fInitValue;
0091 fMergeMode = rhs.fMergeMode;
0092 fMergeFunction = rhs.fMergeFunction;
0093
0094 return *this;
0095 }
0096
0097
0098 template <typename T>
0099 G4Accumulable<T>& G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs) noexcept
0100 {
0101
0102 if (this == &rhs) return *this;
0103
0104
0105 G4VAccumulable::operator=(rhs);
0106
0107
0108 fValue = std::move(rhs.fValue);
0109 fInitValue = std::move(rhs.fInitValue);
0110 fMergeMode = rhs.fMergeMode;
0111 fMergeFunction = rhs.fMergeFunction;
0112
0113 return *this;
0114 }
0115
0116
0117 template <typename T>
0118 G4Accumulable<T>&
0119 G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
0120 {
0121
0122 fValue += rhs.fValue;
0123 return *this;
0124 }
0125
0126
0127 template <typename T>
0128 G4Accumulable<T>&
0129 G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
0130 {
0131
0132 fValue *= rhs.fValue;
0133 return *this;
0134 }
0135
0136
0137 template <typename T>
0138 G4Accumulable<T>&
0139 G4Accumulable<T>::operator=(const T& value)
0140 {
0141
0142 fValue = value;
0143 return *this;
0144 }
0145
0146
0147 template <typename T>
0148 G4Accumulable<T>&
0149 G4Accumulable<T>::operator+=(const T& value)
0150 {
0151
0152 fValue += value;
0153 return *this;
0154 }
0155
0156
0157 template <typename T>
0158 G4Accumulable<T>&
0159 G4Accumulable<T>::operator*=(const T& value)
0160 {
0161
0162 fValue *= value;
0163 return *this;
0164 }
0165
0166
0167 template <typename T>
0168 G4Accumulable<T>
0169 G4Accumulable<T>::operator++(int)
0170 {
0171
0172 G4Accumulable<T> temp = *this;
0173 fValue++;
0174 return temp;
0175 }
0176
0177
0178 template <typename T>
0179 G4Accumulable<T>&
0180 G4Accumulable<T>::operator++()
0181 {
0182
0183 fValue++;
0184 return *this;
0185 }
0186
0187
0188 template <typename T>
0189 void G4Accumulable<T>::Merge(const G4VAccumulable& other)
0190 {
0191
0192
0193 fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
0194
0195 }
0196
0197
0198 template <typename T>
0199 void G4Accumulable<T>::Reset()
0200 {
0201 fValue = fInitValue;
0202 }
0203
0204
0205 template <typename T>
0206 T G4Accumulable<T>::GetValue() const
0207 {
0208 return fValue;
0209 }