Geant4 Cross Reference |
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 // 27 // Visualisation attribute filter utility functions. 28 // 29 // Jane Tinslay, September 2006 30 // 31 #include "G4AttFilterUtils.hh" 32 #include "G4AttDef.hh" 33 #include "G4AttUtils.hh" 34 #include "G4AttValueFilterT.hh" 35 #include "G4CreatorFactoryT.hh" 36 #include "G4DimensionedDouble.hh" 37 #include "G4DimensionedThreeVector.hh" 38 #include "G4String.hh" 39 #include "G4ThreeVector.hh" 40 #include "G4TypeKey.hh" 41 #include "G4TypeKeyT.hh" 42 #include <assert.h> 43 44 namespace G4AttFilterUtils { 45 46 namespace { 47 template <typename T> 48 G4VAttValueFilter* newFilter() { 49 return new G4AttValueFilterT<T>; 50 } 51 } 52 53 // Create new G4AttValue filter factory 54 G4AttValueFilterFactory* GetAttValueFilterFactory() { 55 static G4AttValueFilterFactory* factory = new G4AttValueFilterFactory; 56 static G4bool init(false); 57 58 if (!init) { 59 // Register typekey<->creator pairs 60 factory->Register(G4TypeKeyT<G4String>(), newFilter<G4String>); 61 factory->Register(G4TypeKeyT<G4int>(), newFilter<G4int>); 62 factory->Register(G4TypeKeyT<G4double>(), newFilter<G4double>); 63 factory->Register(G4TypeKeyT<G4ThreeVector>(), newFilter<G4ThreeVector>); 64 factory->Register(G4TypeKeyT<G4bool>(), newFilter<G4bool>); 65 factory->Register(G4TypeKeyT<G4DimensionedDouble>(), newFilter<G4DimensionedDouble>); 66 factory->Register(G4TypeKeyT<G4DimensionedThreeVector>(), newFilter<G4DimensionedThreeVector>); 67 init = true; 68 } 69 70 return factory; 71 } 72 73 G4VAttValueFilter* GetNewFilter(const G4AttDef& def) { 74 75 G4TypeKey myKey = def.GetTypeKey(); 76 77 // Get correct type key if original G4AttDef's being used 78 if (!myKey.IsValid()) { 79 myKey = G4AttUtils::GetKey(def); 80 } 81 82 // Should be valid now 83 assert(myKey.IsValid()); 84 85 G4AttValueFilterFactory* factory = GetAttValueFilterFactory(); 86 87 G4VAttValueFilter* filter = factory->Create(myKey); 88 assert (0 != filter); 89 90 return filter; 91 } 92 93 } 94