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