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