source: trunk/source/visualization/management/include/G4VisListManager.hh@ 1350

Last change on this file since 1350 was 1348, checked in by garnier, 15 years ago

update

  • Property svn:mime-type set to text/cpp
File size: 4.3 KB
RevLine 
[531]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//
[1348]26// $Id: G4VisListManager.hh,v 1.9 2010/12/11 17:01:25 allison Exp $
[1346]27// GEANT4 tag $Name: $
[531]28//
29// Jane Tinslay, John Allison, Joseph Perl October 2005
30//
31// Class Description:
32// Templated class to manage a set of objects, with one named
33// as current. Owns registered objects.
34// Class Description - End:
35
36#ifndef G4VISLISTMANAGER_HH
37#define G4VISLISTMANAGER_HH
38
39#include "G4String.hh"
40#include <map>
41#include <ostream>
42#include <sstream>
43
44template <typename T>
45class G4VisListManager {
46
47public: // With description
48
49 G4VisListManager();
50
51 virtual ~G4VisListManager();
52
53 // Register ptr. Manager assumes ownership and
54 // ptr becomes current
55 void Register(T* ptr);
56
57 void SetCurrent(const G4String& name);
58
59 // Accessors
60 const T* Current() const {return fpCurrent;}
61 const std::map<G4String, T*>& Map() const;
62
63 // Print configuration
64 void Print(std::ostream& ostr, const G4String& name="") const;
65
66private:
67
68 // Data members
69 std::map<G4String, T*> fMap;
70 T* fpCurrent;
71
72};
73
74template <typename T>
75G4VisListManager<T>::G4VisListManager()
76 :fpCurrent(0)
77{}
78
79template <typename T>
80G4VisListManager<T>::~G4VisListManager()
81{
82 typename std::map<G4String, T*>::iterator iter = fMap.begin();
83
84 while (iter != fMap.end()) {
85 delete iter->second;
86 iter++;
87 }
88}
89
90template <typename T>
91void
92G4VisListManager<T>::Register(T* ptr)
93{
94 assert (0 != ptr);
95
[1348]96 // Add to map. Replace if name the same.
97 fMap[ptr->Name()] = ptr;
98 fpCurrent = ptr;
[531]99}
100
101template <typename T>
102void
103G4VisListManager<T>::SetCurrent(const G4String& name)
104{
105 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
106
107 if (iter != fMap.end()) fpCurrent = fMap[name];
108 else {
109 std::ostringstream o;
110 o << "Key "<<name<<" has not been registered";
111 G4Exception
112 ("G4VisListManager<T>::SetCurrent(T* ptr) ",
113 "NonExistentName", FatalErrorInArgument, o.str().c_str());
114 }
115}
116
117template <typename T>
118void
119G4VisListManager<T>::Print(std::ostream& ostr, const G4String& name) const
120{
121 if (0 == fMap.size()) {
122 G4cout<<" None"<<std::endl;
123 return;
124 }
125
126 ostr<<" Current: "<<fpCurrent->Name()<<std::endl;
127
128 if (!name.isNull()) {
129 // Print out specified object
130 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
131
132 if (iter != fMap.end()) {
133 iter->second->Print(ostr);
134 }
135 else {
136 ostr<<name<<" not found "<<std::endl;
137 }
138 }
139 else {
140 typename std::map<G4String, T*>::const_iterator iter = fMap.begin();
141 while (iter != fMap.end()) {
142 iter->second->Print(ostr);
143 ostr<<std::endl;
144 iter++;
145 }
146 }
147}
148
149template <typename T>
150const std::map<G4String, T*>&
151G4VisListManager<T>::Map() const
152{
153 return fMap;
154}
155
156#endif
Note: See TracBrowser for help on using the repository browser.