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 //_____________________________________________________________________________
16 TG4IntMap::TG4IntMap(){
20 //_____________________________________________________________________________
21 TG4IntMap::TG4IntMap(const TG4IntMap& right) {
23 TG4Globals::Exception("TG4IntMap is protected from copying.");
26 //_____________________________________________________________________________
27 TG4IntMap::~TG4IntMap() {
33 //_____________________________________________________________________________
34 TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
36 // check assignement to self
37 if (this == &right) return *this;
39 TG4Globals::Exception("TG4IntMap is protected from assigning.");
46 //_____________________________________________________________________________
47 G4bool TG4IntMap::IsDefined(const G4String& first)
49 // Returns true if the first is already in the map.
52 IntMapIterator i = fMap.find(first);
61 //_____________________________________________________________________________
62 G4bool TG4IntMap::Add(const G4String& first, G4int second)
64 // Adds pair (name, int number) to the map.
67 if (!IsDefined(first)) {
69 // only in case it is not yet here
76 //_____________________________________________________________________________
77 G4int TG4IntMap::GetSecond(const G4String& name)
79 // Gets second name associated with given name.
82 IntMapIterator i = fMap.find(name);
83 if (i == fMap.end()) {
84 G4String text = " TG4IntMap::GetSecond: ";
85 text = text + name + " is not defined.";
86 TG4Globals::Warning(text);
94 //_____________________________________________________________________________
95 void TG4IntMap::PrintAll()
101 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
103 for (IntMapIterator i=fMap.begin(); i != fMap.end(); i++) {
104 const G4String& first = (*i).first;
105 G4int second = (*i).second;
106 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
107 << first << " " << second << G4endl;
112 //_____________________________________________________________________________
113 void TG4IntMap::Clear()
118 if (fMap.size()>0) fMap.clear();