Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4NameMap.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4NameMap.h"
16#include "TG4Globals.h"
17
18#include "globals.hh"
19#include "iomanip"
20
21G4String TG4NameMap::fgUndefined = "Undefined";
22
23//_____________________________________________________________________________
24TG4NameMap::TG4NameMap() : fMap(), fInverseMap(), fSecond(fgUndefined)
25{
27}
28
29//_____________________________________________________________________________
34
35//
36// public methods
37//
38
39//_____________________________________________________________________________
40G4bool TG4NameMap::Add(const G4String& first, const G4String& second)
41{
44
45 if (GetSecond(first) == fgUndefined) {
46 // insert into map
47 // only in case it is not yet here
48 fMap[first] = second;
49 fInverseMap[second] = first;
50 return true;
51 }
52 return false;
53}
54
55//_____________________________________________________________________________
56G4bool TG4NameMap::AddInverse(const G4String& first, const G4String& second)
57{
59
60 if (GetFirst(second) == fgUndefined) {
61 // insert into map
62 // only in case it is not yet here
63 fInverseMap[second] = first;
64 return true;
65 }
66 return false;
67}
68
69//_____________________________________________________________________________
70G4bool TG4NameMap::AddName(const G4String& name)
71{
73
74 if (GetSecond(name) == fgUndefined) {
75 // insert into map
76 // only in case it is not yet here
77 fMap[name] = fSecond;
78 fInverseMap[fSecond] = name;
79 return true;
80 }
81 return false;
82}
83
84//_____________________________________________________________________________
85const G4String& TG4NameMap::GetFirst(const G4String& second) const
86{
88
89 MapConstIterator i = fInverseMap.find(second);
90 if (i == fInverseMap.end())
91 return fgUndefined;
92 else
93 return (*i).second;
94}
95
96//_____________________________________________________________________________
97const G4String& TG4NameMap::GetSecond(const G4String& first) const
98{
100
101 MapConstIterator i = fMap.find(first);
102 if (i == fMap.end())
103 return fgUndefined;
104 else
105 return (*i).second;
106}
107
108//_____________________________________________________________________________
110{
112
113 if (fMap.size()) {
114 G4cout << "Dump of map - " << fMap.size() << " entries:" << G4endl;
115 G4int counter = 0;
116 for (MapConstIterator i = fMap.begin(); i != fMap.end(); i++) {
117 const G4String& first = (*i).first;
118 const G4String& second = (*i).second;
119 G4cout << "Map element " << std::setw(3) << counter++ << " " << first
120 << " " << second << G4endl;
121 }
122 }
123
124 if (fInverseMap.size()) {
125 G4cout << "Dump of inverse map - " << fInverseMap.size()
126 << " entries:" << G4endl;
127 G4int counter = 0;
128 for (MapConstIterator i = fInverseMap.begin(); i != fInverseMap.end();
129 i++) {
130 const G4String& first = (*i).first;
131 const G4String& second = (*i).second;
132 G4cout << "Map element " << std::setw(3) << counter++ << " " << first
133 << " " << second << G4endl;
134 }
135 }
136}
137
138//_____________________________________________________________________________
140{
142
143 fMap.clear();
144 fInverseMap.clear();
146}
Definition of the TG4Globals class and basic container types.
Definition of the TG4NameMap class.
Map fInverseMap
inverse map container
Definition TG4NameMap.h:69
G4bool Add(const G4String &first, const G4String &second)
const G4String & GetSecond(const G4String &first) const
Map::const_iterator MapConstIterator
The constant iterator for the map of strings to strings.
Definition TG4NameMap.h:40
G4String fSecond
the current second
Definition TG4NameMap.h:70
static G4String fgUndefined
the value of undefined second
Definition TG4NameMap.h:65
Map fMap
map container
Definition TG4NameMap.h:68
void PrintAll() const
const G4String & GetFirst(const G4String &second) const
G4bool AddName(const G4String &name)
G4bool AddInverse(const G4String &first, const G4String &second)