Geant4 10.7.0
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
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
52 if (unitTable.size() == 0) G4UnitDefinition::BuildUnitsTable();
53
54 // Iterate over unit lists, searching for unit match
55 G4UnitsTable::const_iterator 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 G4UnitsContainer::const_iterator 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
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:68
bool operator()(const G4UnitDefinition *value) const
static void BuildUnitsTable()
const G4String & GetName() const
static G4UnitsTable & GetUnitsTable()
const G4String & GetSymbol() const
G4bool GetUnitValue(const G4String &unit, G4double &value)