4 // See the class description in the header file.
6 #include "TG4NameMap.h"
7 #include "TG4Globals.h"
9 #include "g4std/iomanip"
12 G4String TG4NameMap::fgUndefined = "Undefined";
14 typedef G4std::map<G4String, G4String, G4std::less<G4String> >
15 :: iterator MapIterator;
17 TG4NameMap::TG4NameMap()
18 : fSecond(fgUndefined) {
22 TG4NameMap::TG4NameMap(const TG4NameMap& right) {
24 TG4Globals::Exception("TG4NameMap is protected from copying.");
27 TG4NameMap::~TG4NameMap() {
33 TG4NameMap& TG4NameMap::operator=(const TG4NameMap& right)
35 // check assignement to self
36 if (this == &right) return *this;
38 TG4Globals::Exception("TG4NameMap is protected from assigning.");
45 G4bool TG4NameMap::Add(const G4String& first, const G4String& second)
47 // Adds names pair to the map.
48 // fSecond is not used in this add method.
51 if (GetSecond(first) == fgUndefined) {
53 // only in case it is not yet here
61 G4bool TG4NameMap::AddName(const G4String& name)
63 // Adds name to the map.
66 if (GetSecond(name) == fgUndefined) {
68 // only in case it is not yet here
76 const G4String& TG4NameMap::GetSecond(const G4String& name)
78 // Gets second name associated with given name.
81 MapIterator i = fMap.find(name);
89 void TG4NameMap::PrintAll()
95 G4cout << "Dump of TG4NameMap - " << fMap.size() << " entries:" << G4endl;
97 for (MapIterator i=fMap.begin(); i != fMap.end(); i++) {
98 const G4String& first = (*i).first;
99 const G4String& second = (*i).second;
100 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
101 << first << " " << second << G4endl;
107 void TG4NameMap::Clear()
113 for (MapIterator i=fMap.begin(); i != fMap.end(); i++) {
118 fSecond = "Undefined";