Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DimensionedType.hh
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//
27// Generic dimensioned type.
28//
29// Jane Tinslay, September 2006
30//
31#ifndef G4DIMENSIONEDTYPE_HH
32#define G4DIMENSIONEDTYPE_HH
33
34#include "globals.hh"
36#include "G4String.hh"
37#include "G4UnitsTable.hh"
38#include <ostream>
39
41{
42 G4bool GetUnitValue(const G4String& unit, G4double& value);
43}
44
45// Default error handling done through G4ConversionFatalError
46template <typename T, typename ConversionErrorPolicy = G4ConversionFatalError>
47class G4DimensionedType : public ConversionErrorPolicy {
48
49public:
50
51 // Constructors
53 G4DimensionedType(const T& value, const G4String& unit);
54
55 // Destructor
57
58 // Accessors
59
60 // Raw, undimensioned value
61 T RawValue() const;
62
63 // Unit string
64 G4String Unit() const;
65
66 // Dimensioned value - rawValue*converted unit
67 T DimensionedValue() const;
68
69 // Operators
70 T operator()() const;
71 bool operator == (const G4DimensionedType<T>& rhs) 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
76private:
77
78 // Data members
79 T fValue;
80 G4String fUnit;
81 T fDimensionedValue;
82
83};
84
85template <typename T, typename ConversionErrorPolicy>
87 :fValue(0)
88 ,fUnit("Undefined")
89 ,fDimensionedValue(0)
90{}
91
92template <typename T, typename ConversionErrorPolicy>
94 :fValue(value)
95 ,fUnit(unit)
96{
97 G4double unitValue(0);
98
99 // Convert unit string to unit value
100 if (!G4DimensionedTypeUtils::GetUnitValue(unit, unitValue)) ConversionErrorPolicy::ReportError(unit, "Invalid unit");
101
102 fDimensionedValue = value*unitValue;
103}
104
105template <typename T, typename ConversionErrorPolicy>
107
108template <typename T, typename ConversionErrorPolicy>
109T
111{
112 return fValue;
113}
114
115template <typename T, typename ConversionErrorPolicy>
118{
119 return fUnit;
120}
121
122template <typename T, typename ConversionErrorPolicy>
123T
125{
126 return fDimensionedValue;
127}
128
129template <typename T, typename ConversionErrorPolicy>
130T
132{
133 return fDimensionedValue;
134}
135
136template <typename T, typename ConversionErrorPolicy>
137bool
139{
140 return fDimensionedValue == rhs.fDimensionedValue;
141}
142
143template <typename T, typename ConversionErrorPolicy>
144bool
146{
147 return fDimensionedValue != rhs.fDimensionedValue;
148}
149
150template <typename T, typename ConversionErrorPolicy>
151bool
153{
154 return fDimensionedValue < rhs.fDimensionedValue;
155}
156
157template <typename T, typename ConversionErrorPolicy>
158bool
160{
161 return fDimensionedValue > rhs.fDimensionedValue;
162}
163
164template <typename M>
165std::ostream& operator << (std::ostream& os, const G4DimensionedType<M>& obj) {
166 os << obj.RawValue()<<" "<<obj.Unit();
167 return os;
168}
169
170#endif
std::ostream & operator<<(std::ostream &os, const G4DimensionedType< M > &obj)
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
bool operator>(const G4DimensionedType< T > &rhs) const
virtual ~G4DimensionedType()
bool operator==(const G4DimensionedType< T > &rhs) const
bool operator!=(const G4DimensionedType< T > &rhs) const
bool operator<(const G4DimensionedType< T > &rhs) const
G4String Unit() const
G4bool GetUnitValue(const G4String &unit, G4double &value)