Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4VisModelManager.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// Generic model manager. Manages models, associated
29// factories, messengers, command placement etc
30//
31// Jane Tinslay, March 2006
32//
33#ifndef G4VISMODELMANAGER_HH
34#define G4VISMODELMANAGER_HH
35
36#include "G4UImessenger.hh"
38#include "G4VisListManager.hh"
39#include "G4VModelFactory.hh"
40#include <vector>
41
42template <typename Model>
44
45public: // With description
46
47 // Useful typedef's
50
53
54 // Registration methods
55 void Register(Model*);
57
58 // Change/Retrieve "Current" object
59 void SetCurrent(const G4String&);
60 const Model* Current() const;
61
62 // Command placement
64
65 // Print factory and model data
66 void Print(std::ostream& ostr, const G4String& name="") const;
67
68 // Accessors
69 const List* ListManager() const;
70 const std::vector<Factory*>& FactoryList() const;
71
72private:
73
74 // Private copy constructor and assigment operator - copying and
75 // assignment not allowed. Keeps Coverity happy.
77 G4VisModelManager& operator = (const G4VisModelManager&);
78
79 // Data members
80 G4String fPlacement;
81 List* fpModelList;
82 std::vector<Factory*> fFactoryList;
83 std::vector<G4UImessenger*> fMessengerList;
84
85};
86
87template <typename Model>
89 :fPlacement(placement)
90 ,fpModelList(new List)
91{}
92
93template <typename Model>
95{
96 // Cleanup
97 std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
98
99 while (iterMsgr != fMessengerList.end()) {
100 delete *iterMsgr;
101 iterMsgr++;
102 }
103
104 typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
105
106 while (iterFactory != fFactoryList.end()) {
107 delete *iterFactory;
108 iterFactory++;
109 }
110
111 delete fpModelList;
112}
113
114template <typename Model>
115void
117{
118 fpModelList->Register(model);
119}
120
121template <typename Model>
122void
124{
125 // Assume ownership
126 fFactoryList.push_back(factory);
127
128 // Generate "create" command for this factory
129 fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
130}
131
132template <typename Model>
133void
135{
136 fpModelList->SetCurrent(model);
137}
138
139template <typename Model>
140const Model*
142{
143 return fpModelList->Current();
144}
145
146template <typename Model>
149{
150 return fPlacement;
151}
152
153template <typename Model>
154void
155G4VisModelManager<Model>::Print(std::ostream& ostr, const G4String& name) const
156{
157 ostr<<"Registered model factories:"<<std::endl;
158
159 typename std::vector<Factory*>::const_iterator iter = fFactoryList.begin();
160
161 while (iter != fFactoryList.end()) {
162 (*iter)->Print(ostr);
163 iter++;
164 }
165
166 if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
167
168 ostr<<std::endl;
169 ostr<<"Registered models: "<<std::endl;
170
171 fpModelList->Print(ostr, name);
172}
173
174template <typename Model>
177{
178 return fpModelList;
179}
180
181template <typename Model>
182const std::vector<G4VModelFactory<Model>*>&
184{
185 return fFactoryList;
186}
187
188#endif
const List * ListManager() const
const Model * Current() const
G4VisListManager< Model > List
void SetCurrent(const G4String &)
void Register(Factory *)
G4VisModelManager(const G4String &)
void Register(Model *)
const std::vector< Factory * > & FactoryList() const
G4String Placement() const
G4VModelFactory< Model > Factory
void Print(std::ostream &ostr, const G4String &name="") const
virtual ~G4VisModelManager()