Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4DimensionedTypeUtils.cc
이 파일의 문서화 페이지로 가기
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:
44  };
45 
46  // Get unit value from input string. Return value indicates if
47  // conversion was successful.
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 
const XML_Char * name
Definition: expat.h:151
G4bool GetUnitValue(const G4String &unit, G4double &value)
bool operator()(const G4UnitDefinition *value) const
std::vector< G4UnitsCategory * > G4UnitsTable
Definition: G4UnitsTable.hh:60
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
const G4String & GetSymbol() const
const XML_Char int const XML_Char * value
Definition: expat.h:331
const G4String & GetName() const
static G4UnitsTable & GetUnitsTable()
std::vector< G4UnitDefinition * > G4UnitsContainer
static void BuildUnitsTable()