4 // Author: I. Hrivnacova
8 // See the class description in the header file.
10 #include "TG4IntMap.h"
11 #include "TG4Globals.h"
13 #include "g4std/iomanip"
16 //_____________________________________________________________________________
17 TG4IntMap::TG4IntMap(){
21 //_____________________________________________________________________________
22 TG4IntMap::TG4IntMap(const TG4IntMap& right) {
24 TG4Globals::Exception("TG4IntMap is protected from copying.");
27 //_____________________________________________________________________________
28 TG4IntMap::~TG4IntMap() {
34 //_____________________________________________________________________________
35 TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
37 // check assignement to self
38 if (this == &right) return *this;
40 TG4Globals::Exception("TG4IntMap is protected from assigning.");
47 //_____________________________________________________________________________
48 G4bool TG4IntMap::IsDefined(const G4String& first)
50 // Returns true if the first is already in the map.
53 MapIterator i = fMap.find(first);
62 //_____________________________________________________________________________
63 G4bool TG4IntMap::Add(const G4String& first, G4int second)
65 // Adds pair (name, int number) to the map.
68 if (!IsDefined(first)) {
70 // only in case it is not yet here
77 //_____________________________________________________________________________
78 G4int TG4IntMap::GetSecond(const G4String& name, G4bool warn)
80 // Gets second name associated with given name.
83 MapIterator i = fMap.find(name);
84 if (i == fMap.end()) {
86 G4String text = " TG4IntMap::GetSecond: ";
87 text = text + name + " is not defined.";
88 TG4Globals::Warning(text);
97 //_____________________________________________________________________________
98 void TG4IntMap::PrintAll() const
104 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
106 for (MapConstIterator i=fMap.begin(); i != fMap.end(); i++) {
107 const G4String& first = (*i).first;
108 G4int second = (*i).second;
109 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
110 << first << " " << second << G4endl;
115 //_____________________________________________________________________________
116 void TG4IntMap::Clear()
121 if (fMap.size()>0) fMap.clear();