Geant4
11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DimensionedTypeUtils.cc
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
// John Allison 1st October 2012
27
28
// Utility moved from G4DimensionedType.hh.
29
30
#include "
G4DimensionedType.hh
"
31
32
namespace
G4DimensionedTypeUtils
33
{
34
// Helper class
35
class
HasName
{
36
public
:
37
HasName
(
const
G4String
& name): fName(name) {};
38
bool
operator()
(
const
G4UnitDefinition
* value)
const
39
{
40
return
((value->
GetName
() == fName) || (value->
GetSymbol
() == fName));
41
}
42
private
:
43
G4String
fName;
44
};
45
46
// Get unit value from input string. Return value indicates if
47
// conversion was successful.
48
G4bool
GetUnitValue
(
const
G4String
& unit,
G4double
& value)
49
{
50
// Get units table
51
G4UnitsTable
& unitTable =
G4UnitDefinition::GetUnitsTable
();
52
if
(unitTable.empty())
G4UnitDefinition::BuildUnitsTable
();
53
54
// Iterate over unit lists, searching for unit match
55
auto
iterTable = unitTable.begin();
56
57
HasName
myUnit(unit);
58
G4bool
gotUnit(
false
);
59
60
while
(!gotUnit && (iterTable != unitTable.end())) {
61
G4UnitsContainer
unitContainer = (*iterTable)->GetUnitsList();
62
63
auto
iterUnits =
64
std::find_if(unitContainer.begin(), unitContainer.end(), myUnit);
65
66
if
(iterUnits != unitContainer.end()) {
67
value = (*iterUnits)->GetValue();
68
gotUnit =
true
;
69
}
70
71
iterTable++;
72
}
73
74
return
gotUnit;
75
}
76
}
77
G4DimensionedType.hh
G4double
double G4double
Definition
G4Types.hh:83
G4bool
bool G4bool
Definition
G4Types.hh:86
G4UnitsContainer
std::vector< G4UnitDefinition * > G4UnitsContainer
Definition
G4UnitsTable.hh:127
G4UnitsTable
std::vector< G4UnitsCategory * > G4UnitsTable
Definition
G4UnitsTable.hh:68
G4DimensionedTypeUtils::HasName
Definition
G4DimensionedTypeUtils.cc:35
G4DimensionedTypeUtils::HasName::operator()
bool operator()(const G4UnitDefinition *value) const
Definition
G4DimensionedTypeUtils.cc:38
G4DimensionedTypeUtils::HasName::HasName
HasName(const G4String &name)
Definition
G4DimensionedTypeUtils.cc:37
G4String
Definition
G4String.hh:62
G4UnitDefinition
Definition
G4UnitsTable.hh:75
G4UnitDefinition::BuildUnitsTable
static void BuildUnitsTable()
Definition
G4UnitsTable.cc:246
G4UnitDefinition::GetName
const G4String & GetName() const
G4UnitDefinition::GetUnitsTable
static G4UnitsTable & GetUnitsTable()
Definition
G4UnitsTable.cc:143
G4UnitDefinition::GetSymbol
const G4String & GetSymbol() const
G4DimensionedTypeUtils
Definition
G4DimensionedType.hh:41
G4DimensionedTypeUtils::GetUnitValue
G4bool GetUnitValue(const G4String &unit, G4double &value)
Definition
G4DimensionedTypeUtils.cc:48
geant4-v11.2.2
source
graphics_reps
src
G4DimensionedTypeUtils.cc
Generated by
1.12.0