Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4DimensionedType.hh
이 파일의 문서화 페이지로 가기
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: G4DimensionedType.hh 66376 2012-12-18 09:42:59Z gcosmo $
27 //
28 // Generic dimensioned type.
29 //
30 // Jane Tinslay, September 2006
31 //
32 #ifndef G4DIMENSIONEDTYPE_HH
33 #define G4DIMENSIONEDTYPE_HH
34 
35 #include "globals.hh"
37 #include "G4String.hh"
38 #include "G4UnitsTable.hh"
39 #include <ostream>
40 
41 namespace G4DimensionedTypeUtils
42 {
43  G4bool GetUnitValue(const G4String& unit, G4double& value);
44 }
45 
46 // Default error handling done through G4ConversionFatalError
47 template <typename T, typename ConversionErrorPolicy = G4ConversionFatalError>
48 class G4DimensionedType : public ConversionErrorPolicy {
49 
50 public:
51 
52  // Constructors
54  G4DimensionedType(const T& value, const G4String& unit);
55 
56  // Destructor
57  virtual ~G4DimensionedType();
58 
59  // Accessors
60 
61  // Raw, undimensioned value
62  T RawValue() const;
63 
64  // Unit string
65  G4String Unit() const;
66 
67  // Dimensioned value - rawValue*converted unit
68  T DimensionedValue() const;
69 
70  // Operators
71  T operator()() const;
72  bool operator == (const G4DimensionedType<T>& rhs) const;
73  bool operator != (const G4DimensionedType<T>& rhs) const;
74  bool operator < (const G4DimensionedType<T>& rhs) const;
75  bool operator > (const G4DimensionedType<T>& rhs) const;
76 
77 private:
78 
79  // Data members
80  T fValue;
83 
84 };
85 
86 template <typename T, typename ConversionErrorPolicy>
88  :fValue(0)
89  ,fUnit("Undefined")
90  ,fDimensionedValue(0)
91 {}
92 
93 template <typename T, typename ConversionErrorPolicy>
95  :fValue(value)
96  ,fUnit(unit)
97 {
98  G4double unitValue(0);
99 
100  // Convert unit string to unit value
101  if (!G4DimensionedTypeUtils::GetUnitValue(unit, unitValue)) ConversionErrorPolicy::ReportError(unit, "Invalid unit");
102 
103  fDimensionedValue = value*unitValue;
104 }
105 
106 template <typename T, typename ConversionErrorPolicy>
108 
109 template <typename T, typename ConversionErrorPolicy>
110 T
112 {
113  return fValue;
114 }
115 
116 template <typename T, typename ConversionErrorPolicy>
117 G4String
119 {
120  return fUnit;
121 }
122 
123 template <typename T, typename ConversionErrorPolicy>
124 T
126 {
127  return fDimensionedValue;
128 }
129 
130 template <typename T, typename ConversionErrorPolicy>
131 T
133 {
134  return fDimensionedValue;
135 }
136 
137 template <typename T, typename ConversionErrorPolicy>
138 bool
140 {
141  return fDimensionedValue == rhs.fDimensionedValue;
142 }
143 
144 template <typename T, typename ConversionErrorPolicy>
145 bool
147 {
148  return fDimensionedValue != rhs.fDimensionedValue;
149 }
150 
151 template <typename T, typename ConversionErrorPolicy>
152 bool
154 {
155  return fDimensionedValue < rhs.fDimensionedValue;
156 }
157 
158 template <typename T, typename ConversionErrorPolicy>
159 bool
161 {
162  return fDimensionedValue > rhs.fDimensionedValue;
163 }
164 
165 template <typename M>
166 std::ostream& operator << (std::ostream& os, const G4DimensionedType<M>& obj) {
167  os << obj.RawValue()<<" "<<obj.Unit();
168  return os;
169 }
170 
171 #endif
bool operator<(const G4DimensionedType< T > &rhs) const
G4bool GetUnitValue(const G4String &unit, G4double &value)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4String Unit() const
bool operator==(const G4DimensionedType< T > &rhs) const
bool operator!=(const G4DimensionedType< T > &rhs) const
bool operator>(const G4DimensionedType< T > &rhs) const