4 // See the class description in the header file.
7 #include "TG4Globals.h"
9 #include "g4std/iomanip"
12 typedef G4std::map<G4String, G4int, G4std::less<G4String> >
13 :: iterator IntMapIterator;
15 TG4IntMap::TG4IntMap(){
19 TG4IntMap::TG4IntMap(const TG4IntMap& right) {
21 TG4Globals::Exception("TG4IntMap is protected from copying.");
24 TG4IntMap::~TG4IntMap() {
30 TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
32 // check assignement to self
33 if (this == &right) return *this;
35 TG4Globals::Exception("TG4IntMap is protected from assigning.");
42 G4bool TG4IntMap::IsDefined(const G4String& first)
44 // Returns true if the first is already in the map.
47 IntMapIterator i = fMap.find(first);
56 G4bool TG4IntMap::Add(const G4String& first, G4int second)
58 // Adds pair (name, int number) to the map.
61 if (!IsDefined(first)) {
63 // only in case it is not yet here
70 G4int TG4IntMap::GetSecond(const G4String& name)
72 // Gets second name associated with given name.
75 IntMapIterator i = fMap.find(name);
76 if (i == fMap.end()) {
77 G4String text = "G4IntMap::GetSecond: ";
78 text = text + name + " is not defined.";
79 TG4Globals::Warning(text);
87 void TG4IntMap::PrintAll()
93 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
95 for (IntMapIterator i=fMap.begin(); i != fMap.end(); i++) {
96 const G4String& first = (*i).first;
97 G4int second = (*i).second;
98 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
99 << first << " " << second << G4endl;
105 void TG4IntMap::Clear()
110 if (fMap.size()>0) fMap.clear();