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