Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VisFilterManager.hh
이 파일의 문서화 페이지로 가기
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: G4VisFilterManager.hh 66373 2012-12-18 09:41:34Z gcosmo $
27 //
28 // Filter manager. Manages filter models, factories, messengers,
29 // command placement, filter mode etc
30 //
31 // Jane Tinslay, March 2006
32 //
33 #ifndef G4VISFILTERMANAGER_HH
34 #define G4VISFILTERMANAGER_HH
35 
36 #include "G4String.hh"
37 #include "G4UImessenger.hh"
38 #include "G4VFilter.hh"
39 #include "G4VModelFactory.hh"
40 #include <vector>
41 
42 namespace FilterMode {
43  enum Mode {Soft, Hard};
44 }
45 
46 template <typename T>
48 
49 public:
50 
51  // Construct with command placement
53 
54  virtual ~G4VisFilterManager();
55 
56  // Useful typedef's
59 
60  // Registration methods
61  void Register(Filter*);
62  void Register(Factory*);
63 
64  // Do filtering
65  bool Accept(const T&);
66 
67  // Command placement
68  G4String Placement() const;
69 
70  // Filter mode operations
71  void SetMode(const FilterMode::Mode&);
72  void SetMode(const G4String&);
73  FilterMode::Mode GetMode() const;
74 
75  // Print configuration
76  void Print(std::ostream& ostr, const G4String& name="") const;
77 
78  // Accessors
79  const std::vector<Filter*>& FilterList() const;
80  const std::vector<Factory*>& FactoryList() const;
81 
82 private:
83 
84  // Data members
85  G4String fPlacement; // Placement
87  std::vector<Factory*> fFactoryList;
88  std::vector<Filter*> fFilterList;
89  std::vector<G4UImessenger*> fMessengerList;
90 
91 };
92 
93 template <typename T>
95  :fPlacement(placement)
96 {
98 }
99 
100 template <typename T>
102 {
103  // Cleanup
104  std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
105 
106  while (iterMsgr != fMessengerList.end()) {
107  delete *iterMsgr;
108  iterMsgr++;
109  }
110 
111  typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
112 
113  while (iterFactory != fFactoryList.end()) {
114  delete *iterFactory;
115  iterFactory++;
116  }
117 
118  typename std::vector<Filter*>::iterator iterFilter = fFilterList.begin();
119 
120  while (iterFilter != fFilterList.end()) {
121  delete *iterFilter;
122  iterFilter++;
123  }
124 }
125 
126 template <typename T>
127 void
129 {
130  fFilterList.push_back(filter);
131 }
132 
133 template <typename T>
134 void
136 {
137  fFactoryList.push_back(factory);
138 
139  fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
140 }
141 
142 template <typename T>
143 bool
145 {
146  typename std::vector<Filter*>::const_iterator iter = fFilterList.begin();
147  bool passed(true);
148 
149  while (passed && (iter != fFilterList.end())) {
150  passed = (*iter)->Accept(obj);
151  iter++;
152  }
153 
154  return passed;
155 }
156 
157 template <typename T>
158 G4String
160 {
161  return fPlacement;
162 }
163 
164 template <typename T>
165 void
167 {
168  bool result(false);
169 
170  G4String myMode(mode);
171  myMode.toLower();
172 
173  if (myMode == "soft") {result = true; SetMode(FilterMode::Soft);}
174  else if (myMode == "hard") {result = true; SetMode(FilterMode::Hard);}
175 
176  if (!result) {
178  ed << "Invalid Filter mode: "<<mode;
180  ("G4VisFilterManager::SetMode(const G4String& mode)", "visman0101", JustWarning, ed);
181  }
182 }
183 
184 template <typename T>
185 void
187 {
188  fMode = mode;
189 }
190 
191 template <typename T>
194 {
195  return fMode;
196 }
197 
198 template <typename T>
199 void
200 G4VisFilterManager<T>::Print(std::ostream& ostr, const G4String& name) const
201 {
202  ostr<<"Registered filter factories:"<<std::endl;
203  typename std::vector<Factory*>::const_iterator iterFactory = fFactoryList.begin();
204 
205  while (iterFactory != fFactoryList.end()) {
206  (*iterFactory)->Print(ostr);
207  iterFactory++;
208  }
209 
210  if (0 == fFactoryList.size()) ostr<<" None"<<std::endl;
211 
212  ostr<<std::endl;
213  ostr<<"Registered filters:"<<std::endl;
214 
215  typename std::vector<Filter*>::const_iterator iterFilter = fFilterList.begin();
216 
217  while (iterFilter != fFilterList.end()) {
218  if (!name.isNull()) {
219  if ((*iterFilter)->Name() == name) (*iterFilter)->PrintAll(ostr);
220  }
221  else {
222  (*iterFilter)->PrintAll(ostr);
223  }
224  iterFilter++;
225  }
226 
227  if (0 == fFilterList.size()) ostr<<" None"<<std::endl;
228 }
229 
230 template <typename T>
231 const std::vector< G4VFilter<T>* >&
233 {
234  return fFilterList;
235 }
236 
237 template <typename T>
238 const std::vector< G4VModelFactory< G4VFilter<T> >* >&
240 {
241  return fFactoryList;
242 }
243 
244 #endif
G4VisFilterManager(const G4String &)
const XML_Char * name
Definition: expat.h:151
G4bool isNull() const
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
FilterMode::Mode fMode
const std::vector< Filter * > & FilterList() const
const std::vector< Factory * > & FactoryList() const
void toLower()
std::vector< Factory * > fFactoryList
std::vector< G4UImessenger * > fMessengerList
G4double G4ParticleHPJENDLHEData::G4double result
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
std::vector< Filter * > fFilterList
FilterMode::Mode GetMode() const
void Print(std::ostream &ostr, const G4String &name="") const
G4String Placement() const
void SetMode(const FilterMode::Mode &)
bool Accept(const T &)
G4VModelFactory< Filter > Factory