Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
global
src
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
21
G4String
TG4NameMap::fgUndefined
=
"Undefined"
;
22
23
//_____________________________________________________________________________
24
TG4NameMap::TG4NameMap
() :
fMap
(),
fInverseMap
(),
fSecond
(
fgUndefined
)
25
{
27
}
28
29
//_____________________________________________________________________________
30
TG4NameMap::~TG4NameMap
()
31
{
33
}
34
35
//
36
// public methods
37
//
38
39
//_____________________________________________________________________________
40
G4bool
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
//_____________________________________________________________________________
56
G4bool
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
//_____________________________________________________________________________
70
G4bool
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
//_____________________________________________________________________________
85
const
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
//_____________________________________________________________________________
97
const
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
//_____________________________________________________________________________
109
void
TG4NameMap::PrintAll
()
const
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
//_____________________________________________________________________________
139
void
TG4NameMap::Clear
()
140
{
142
143
fMap
.clear();
144
fInverseMap
.clear();
145
fSecond
=
fgUndefined
;
146
}
TG4Globals.h
Definition of the TG4Globals class and basic container types.
TG4NameMap.h
Definition of the TG4NameMap class.
TG4NameMap::fInverseMap
Map fInverseMap
inverse map container
Definition
TG4NameMap.h:69
TG4NameMap::Add
G4bool Add(const G4String &first, const G4String &second)
Definition
TG4NameMap.cxx:40
TG4NameMap::GetSecond
const G4String & GetSecond(const G4String &first) const
Definition
TG4NameMap.cxx:97
TG4NameMap::Clear
void Clear()
Definition
TG4NameMap.cxx:139
TG4NameMap::MapConstIterator
Map::const_iterator MapConstIterator
The constant iterator for the map of strings to strings.
Definition
TG4NameMap.h:40
TG4NameMap::fSecond
G4String fSecond
the current second
Definition
TG4NameMap.h:70
TG4NameMap::fgUndefined
static G4String fgUndefined
the value of undefined second
Definition
TG4NameMap.h:65
TG4NameMap::TG4NameMap
TG4NameMap()
Definition
TG4NameMap.cxx:24
TG4NameMap::fMap
Map fMap
map container
Definition
TG4NameMap.h:68
TG4NameMap::PrintAll
void PrintAll() const
Definition
TG4NameMap.cxx:109
TG4NameMap::~TG4NameMap
~TG4NameMap()
Definition
TG4NameMap.cxx:30
TG4NameMap::GetFirst
const G4String & GetFirst(const G4String &second) const
Definition
TG4NameMap.cxx:85
TG4NameMap::AddName
G4bool AddName(const G4String &name)
Definition
TG4NameMap.cxx:70
TG4NameMap::AddInverse
G4bool AddInverse(const G4String &first, const G4String &second)
Definition
TG4NameMap.cxx:56
Generated on
for Geant4 VMC by
1.17.0