Geant4  10.00.p03
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: G4VisModelManager.hh 66373 2012-12-18 09:41:34Z gcosmo $
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 
42 template <typename Model>
43 class G4VisModelManager {
44 
45 public: // With description
46 
47  // Useful typedef's
50 
52  virtual ~G4VisModelManager();
53 
54  // Registration methods
55  void Register(Model*);
56  void Register(Factory*);
57 
58  // Change/Retrieve "Current" object
59  void SetCurrent(const G4String&);
60  const Model* Current() const;
61 
62  // Command placement
63  G4String Placement() const;
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 
72 private:
73 
74  // Private copy constructor and assigment operator - copying and
75  // assignment not allowed. Keeps Coverity happy.
78 
79  // Data members
81  List* fpModelList;
82  std::vector<Factory*> fFactoryList;
83  std::vector<G4UImessenger*> fMessengerList;
84 
85 };
86 
87 template <typename Model>
89  :fPlacement(placement)
90  ,fpModelList(new List)
91 {}
92 
93 template <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 
114 template <typename Model>
115 void
117 {
118  fpModelList->Register(model);
119 }
120 
121 template <typename Model>
122 void
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 
132 template <typename Model>
133 void
135 {
136  fpModelList->SetCurrent(model);
137 }
138 
139 template <typename Model>
140 const Model*
142 {
143  return fpModelList->Current();
144 }
145 
146 template <typename Model>
147 G4String
149 {
150  return fPlacement;
151 }
152 
153 template <typename Model>
154 void
155 G4VisModelManager<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 
174 template <typename Model>
177 {
178  return fpModelList;
179 }
180 
181 template <typename Model>
182 const std::vector<G4VModelFactory<Model>*>&
184 {
185  return fFactoryList;
186 }
187 
188 #endif
const std::vector< Factory * > & FactoryList() const
G4String name
Definition: TRTMaterials.hh:40
void Print(std::ostream &ostr, const G4String &name="") const
const Model * Current() const
G4VisModelManager & operator=(const G4VisModelManager &)
std::vector< G4UImessenger * > fMessengerList
G4VisListManager< Model > List
G4VModelFactory< Model > Factory
G4VisModelManager(const G4String &)
void Register(Model *)
virtual ~G4VisModelManager()
G4String Placement() const
void SetCurrent(const G4String &)
const List * ListManager() const
std::vector< Factory * > fFactoryList