Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4IntMap.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
15#include "TG4IntMap.h"
16#include "TG4Globals.h"
17
18#include "globals.hh"
19#include "iomanip"
20
21//_____________________________________________________________________________
23{
25}
26
27//_____________________________________________________________________________
32
33//
34// private methods
35//
36
37//_____________________________________________________________________________
38G4bool TG4IntMap::IsDefined(const G4String& first)
39{
41
42 MapIterator i = fMap.find(first);
43 if (i == fMap.end())
44 return false;
45 else
46 return true;
47}
48
49//
50// public methods
51//
52
53//_____________________________________________________________________________
54G4bool TG4IntMap::Add(const G4String& first, G4int second)
55{
57
58 if (!IsDefined(first)) {
59 // insert into map
60 // only in case it is not yet here
61 fMap[first] = second;
62 return true;
63 }
64 return false;
65}
66
67//_____________________________________________________________________________
68G4int TG4IntMap::GetSecond(const G4String& name, G4bool warn)
69{
71
72 MapIterator i = fMap.find(name);
73 if (i == fMap.end()) {
74 if (warn) {
76 "TG4IntMap", "GetSecond", TString(name) + " is not defined.");
77 }
78 return 0;
79 }
80 else {
81 return (*i).second;
82 }
83}
84//_____________________________________________________________________________
85G4int TG4IntMap::GetSize() const
86{
88
89 return fMap.size();
90}
91
92//_____________________________________________________________________________
94{
96
97 if (fMap.size()) {
98 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
99 G4int counter = 0;
100 for (MapConstIterator i = fMap.begin(); i != fMap.end(); i++) {
101 const G4String& first = (*i).first;
102 G4int second = (*i).second;
103 G4cout << "Map element " << std::setw(3) << counter++ << " " << first
104 << " " << second << G4endl;
105 }
106 }
107}
108
109//_____________________________________________________________________________
111{
113
114 if (fMap.size() > 0) fMap.clear();
115}
Definition of the TG4Globals class and basic container types.
Definition of the TG4IntMap class.
static void Warning(const TString &className, const TString &methodName, const TString &text)
Map::iterator MapIterator
The iterator for the map of integers to strings.
Definition TG4IntMap.h:33
Map::const_iterator MapConstIterator
The constant iterator for the map of integers to strings.
Definition TG4IntMap.h:36
void Clear()
Map fMap
map container
Definition TG4IntMap.h:60
G4int GetSize() const
Definition TG4IntMap.cxx:85
G4int GetSecond(const G4String &name, G4bool warn=true)
Definition TG4IntMap.cxx:68
G4bool Add(const G4String &first, G4int second)
Definition TG4IntMap.cxx:54
G4bool IsDefined(const G4String &first)
Definition TG4IntMap.cxx:38
void PrintAll() const
Definition TG4IntMap.cxx:93