]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4IntMap.cxx
added comment lines separating methods
[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 //_____________________________________________________________________________
16 TG4IntMap::TG4IntMap(){
17 //
18 }
19
20 //_____________________________________________________________________________
21 TG4IntMap::TG4IntMap(const TG4IntMap& right) {
22 //
23   TG4Globals::Exception("TG4IntMap is protected from copying.");
24 }  
25
26 //_____________________________________________________________________________
27 TG4IntMap::~TG4IntMap() {
28 //
29 }
30
31 // operators
32
33 //_____________________________________________________________________________
34 TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
35 {
36   // check assignement to self
37   if (this == &right) return *this;
38
39   TG4Globals::Exception("TG4IntMap is protected from assigning.");
40     
41   return *this;  
42 }    
43           
44 // private methods
45
46 //_____________________________________________________________________________
47 G4bool TG4IntMap::IsDefined(const G4String& first)
48 {
49 // Returns true if the first is already in the map.
50 // ---
51
52   IntMapIterator i = fMap.find(first);
53   if (i == fMap.end()) 
54     return false;
55   else                 
56     return true;
57 }
58
59 // public methods
60
61 //_____________________________________________________________________________
62 G4bool TG4IntMap::Add(const G4String& first, G4int second)
63 {  
64 // Adds pair (name, int number) to the map.
65 // ---
66
67   if (!IsDefined(first)) {
68     // insert into map 
69     // only in case it is not yet here
70     fMap[first] = second;
71     return true;
72   }
73   return false;
74 }
75
76 //_____________________________________________________________________________
77 G4int TG4IntMap::GetSecond(const G4String& name)
78 {
79 // Gets second name associated with given name.
80 // ---
81
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);
87     return 0;
88   }  
89   else {                
90     return (*i).second;
91   }  
92 }
93
94 //_____________________________________________________________________________
95 void TG4IntMap::PrintAll()
96 {
97 // Dumps all map.
98 // ---
99
100   if (fMap.size()) {
101     G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
102     G4int counter = 0;
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;
108     }
109   }
110 }
111
112 //_____________________________________________________________________________
113 void TG4IntMap::Clear() 
114 {
115 // Clears the map.
116 // ---
117
118   if (fMap.size()>0) fMap.clear();
119 }