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)
80 // Gets second name associated with given name.
83 MapIterator i = fMap.find(name);
84 if (i == fMap.end()) {
85 G4String text = " TG4IntMap::GetSecond: ";
86 text = text + name + " is not defined.";
87 TG4Globals::Warning(text);
95 //_____________________________________________________________________________
96 void TG4IntMap::PrintAll() const
102 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
104 for (MapConstIterator i=fMap.begin(); i != fMap.end(); i++) {
105 const G4String& first = (*i).first;
106 G4int second = (*i).second;
107 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
108 << first << " " << second << G4endl;
113 //_____________________________________________________________________________
114 void TG4IntMap::Clear()
119 if (fMap.size()>0) fMap.clear();