Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisListManager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id$
27//
28// Jane Tinslay, John Allison, Joseph Perl October 2005
29//
30// Class Description:
31// Templated class to manage a set of objects, with one named
32// as current. Owns registered objects.
33// Class Description - End:
34
35#ifndef G4VISLISTMANAGER_HH
36#define G4VISLISTMANAGER_HH
37
38#include "G4String.hh"
39#include <map>
40#include <ostream>
41
42template <typename T>
44
45public: // With description
46
48
49 virtual ~G4VisListManager();
50
51 // Register ptr. Manager assumes ownership and
52 // ptr becomes current
53 void Register(T* ptr);
54
55 void SetCurrent(const G4String& name);
56
57 // Accessors
58 const T* Current() const {return fpCurrent;}
59 const std::map<G4String, T*>& Map() const;
60
61 // Print configuration
62 void Print(std::ostream& ostr, const G4String& name="") const;
63
64private:
65
66 // Data members
67 std::map<G4String, T*> fMap;
68 T* fpCurrent;
69
70};
71
72template <typename T>
74 :fpCurrent(0)
75{}
76
77template <typename T>
79{
80 typename std::map<G4String, T*>::iterator iter = fMap.begin();
81
82 while (iter != fMap.end()) {
83 delete iter->second;
84 iter++;
85 }
86}
87
88template <typename T>
89void
91{
92 assert (0 != ptr);
93
94 // Add to map. Replace if name the same.
95 fMap[ptr->Name()] = ptr;
96 fpCurrent = ptr;
97}
98
99template <typename T>
100void
102{
103 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
104
105 if (iter != fMap.end()) fpCurrent = fMap[name];
106 else {
108 ed << "Key \"" << name << "\" has not been registered";
110 ("G4VisListManager<T>::SetCurrent(T* ptr) ",
111 "visman0102", JustWarning, ed, "Non-existent name");
112 }
113}
114
115template <typename T>
116void
117G4VisListManager<T>::Print(std::ostream& ostr, const G4String& name) const
118{
119 if (0 == fMap.size()) {
120 G4cout<<" None"<<std::endl;
121 return;
122 }
123
124 ostr<<" Current: "<<fpCurrent->Name()<<std::endl;
125
126 if (!name.isNull()) {
127 // Print out specified object
128 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
129
130 if (iter != fMap.end()) {
131 iter->second->Print(ostr);
132 }
133 else {
134 ostr<<name<<" not found "<<std::endl;
135 }
136 }
137 else {
138 typename std::map<G4String, T*>::const_iterator iter = fMap.begin();
139 while (iter != fMap.end()) {
140 iter->second->Print(ostr);
141 ostr<<std::endl;
142 iter++;
143 }
144 }
145}
146
147template <typename T>
148const std::map<G4String, T*>&
150{
151 return fMap;
152}
153
154#endif
@ JustWarning
G4DLLIMPORT std::ostream G4cout
G4bool isNull() const
void SetCurrent(const G4String &name)
void Print(std::ostream &ostr, const G4String &name="") const
virtual ~G4VisListManager()
const std::map< G4String, T * > & Map() const
const T * Current() const
void Register(T *ptr)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76