Geant4  10.02.p01
G4Parameter.icc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id$
27 
28 //
29 // public functions
30 //
31 
32 //_____________________________________________________________________________
33 template <typename T>
34 G4Parameter<T>::G4Parameter(const G4String& name, T initValue, G4MergeMode mergeMode)
35  : G4VParameter(name, mergeMode),
36  fValue(initValue),
37  fInitValue(initValue)
38 {}
39 
40 //_____________________________________________________________________________
41 template <typename T>
42 G4Parameter<T>::G4Parameter(const G4Parameter& rhs)
43  : G4VParameter(rhs),
44  fValue(rhs.fValue),
45  fInitValue(rhs.fInitValue)
46 {}
47 
48 //_____________________________________________________________________________
49 template <typename T>
50 G4Parameter<T>::~G4Parameter()
51 {}
52 
53 //_____________________________________________________________________________
54 template <typename T>
55 G4Parameter<T>&
56 G4Parameter<T>::operator=(const G4Parameter<T>& rhs)
57 {
58  // check assignment to self
59  if (this == &rhs) return *this;
60 
61  // base class assignment
62  G4VParameter::operator=(rhs);
63 
64  // this class data assignment
65  fValue = rhs.fValue;
66  fInitValue = rhs.fInitValue;
67 
68  return *this;
69 }
70 
71 //_____________________________________________________________________________
72 template <typename T>
73 G4Parameter<T>&
74 G4Parameter<T>::operator+=(const G4Parameter<T>& rhs)
75 {
76  // only update the value from rhs
77  fValue += rhs.fValue;
78  return *this;
79 }
80 
81 //_____________________________________________________________________________
82 template <typename T>
83 G4Parameter<T>&
84 G4Parameter<T>::operator*=(const G4Parameter<T>& rhs)
85 {
86  // only update the value from rhs
87  fValue *= rhs.fValue;
88  return *this;
89 }
90 
91 //_____________________________________________________________________________
92 template <typename T>
93 G4Parameter<T>&
94 G4Parameter<T>::operator=(const T& value)
95 {
96  // only update the value
97  fValue = value;
98  return *this;
99 }
100 
101 //_____________________________________________________________________________
102 template <typename T>
103 G4Parameter<T>&
104 G4Parameter<T>::operator+=(const T& value)
105 {
106  // only update the value
107  fValue += value;
108  return *this;
109 }
110 
111 //_____________________________________________________________________________
112 template <typename T>
113 G4Parameter<T>&
114 G4Parameter<T>::operator*=(const T& value)
115 {
116  // only update the value from rhs
117  fValue *= value;
118  return *this;
119 }
120 
121 //_____________________________________________________________________________
122 template <typename T>
123 void G4Parameter<T>::Merge(const G4VParameter& other)
124 {
125  if ( fMergeMode == G4MergeMode::kAddition ) {
126  fValue += static_cast<const G4Parameter<T>&>(other).fValue;
127  }
128  else if ( fMergeMode == G4MergeMode::kMultiplication ) {
129  fValue *= static_cast<const G4Parameter<T>&>(other).fValue;
130  }
131  // no operation is performed if User merge mode
132 }
133 
134 //_____________________________________________________________________________
135 template <typename T>
136 void G4Parameter<T>::Reset()
137 {
138  fValue = fInitValue;
139 }
140 
141 //_____________________________________________________________________________
142 template <typename T>
143 T G4Parameter<T>::GetValue() const
144 {
145  return fValue;
146 }