]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4IntMap.cxx
corrected warning text only
[u/mrichter/AliRoot.git] / TGeant4 / TG4IntMap.cxx
1 // $Id$
2 // Category: global
3 //
4 // See the class description in the header file.
5
6 #include "TG4IntMap.h"
7 #include "TG4Globals.h"
8
9 #include "g4std/iomanip"
10 #include "globals.hh"
11
12 typedef G4std::map<G4String, G4int, G4std::less<G4String> >
13   :: iterator IntMapIterator;
14
15 TG4IntMap::TG4IntMap(){
16 //
17 }
18
19 TG4IntMap::TG4IntMap(const TG4IntMap& right) {
20 //
21   TG4Globals::Exception("TG4IntMap is protected from copying.");
22 }  
23
24 TG4IntMap::~TG4IntMap() {
25 //
26 }
27
28 // operators
29
30 TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
31 {
32   // check assignement to self
33   if (this == &right) return *this;
34
35   TG4Globals::Exception("TG4IntMap is protected from assigning.");
36     
37   return *this;  
38 }    
39           
40 // private methods
41
42 G4bool TG4IntMap::IsDefined(const G4String& first)
43 {
44 // Returns true if the first is already in the map.
45 // ---
46
47   IntMapIterator i = fMap.find(first);
48   if (i == fMap.end()) 
49     return false;
50   else                 
51     return true;
52 }
53
54 // public methods
55
56 G4bool TG4IntMap::Add(const G4String& first, G4int second)
57 {  
58 // Adds pair (name, int number) to the map.
59 // ---
60
61   if (!IsDefined(first)) {
62     // insert into map 
63     // only in case it is not yet here
64     fMap[first] = second;
65     return true;
66   }
67   return false;
68 }
69
70 G4int TG4IntMap::GetSecond(const G4String& name)
71 {
72 // Gets second name associated with given name.
73 // ---
74
75   IntMapIterator i = fMap.find(name);
76   if (i == fMap.end()) {
77     G4String text = "   TG4IntMap::GetSecond: ";
78     text = text + name + " is not defined.";
79     TG4Globals::Warning(text);
80     return 0;
81   }  
82   else {                
83     return (*i).second;
84   }  
85 }
86
87 void TG4IntMap::PrintAll()
88 {
89 // Dumps all map.
90 // ---
91
92   if (fMap.size()) {
93     G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
94     G4int counter = 0;
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;
100     }
101   }
102 }
103
104
105 void TG4IntMap::Clear() 
106 {
107 // Clears the map.
108 // ---
109
110   if (fMap.size()>0) fMap.clear();
111 }