Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4AttFilterUtils.cc
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: G4AttFilterUtils.cc 66870 2013-01-14 23:38:59Z adotti $
27 //
28 // Visualisation attribute filter utility functions.
29 //
30 // Jane Tinslay, September 2006
31 //
32 #include "G4AttFilterUtils.hh"
33 #include "G4AttDef.hh"
34 #include "G4AttUtils.hh"
35 #include "G4AttValueFilterT.hh"
36 #include "G4CreatorFactoryT.hh"
37 #include "G4DimensionedDouble.hh"
39 #include "G4String.hh"
40 #include "G4ThreeVector.hh"
41 #include "G4TypeKey.hh"
42 #include "G4TypeKeyT.hh"
43 #include <assert.h>
44 
45 namespace G4AttFilterUtils {
46 
47  namespace {
48  template <typename T>
49  G4VAttValueFilter* newFilter() {
50  return new G4AttValueFilterT<T>;
51  }
52  }
53 
54  // Create new G4AttValue filter factory
57  static G4bool init(false);
58 
59  if (!init) {
60  // Register typekey<->creator pairs
61  factory->Register(G4TypeKeyT<G4String>(), newFilter<G4String>);
62  factory->Register(G4TypeKeyT<G4int>(), newFilter<G4int>);
63  factory->Register(G4TypeKeyT<G4double>(), newFilter<G4double>);
64  factory->Register(G4TypeKeyT<G4ThreeVector>(), newFilter<G4ThreeVector>);
65  factory->Register(G4TypeKeyT<G4bool>(), newFilter<G4bool>);
66  factory->Register(G4TypeKeyT<G4DimensionedDouble>(), newFilter<G4DimensionedDouble>);
67  factory->Register(G4TypeKeyT<G4DimensionedThreeVector>(), newFilter<G4DimensionedThreeVector>);
68  init = true;
69  }
70 
71  return factory;
72  }
73 
75 
76  G4TypeKey myKey = def.GetTypeKey();
77 
78  // Get correct type key if original G4AttDef's being used
79  if (!myKey.IsValid()) {
80  myKey = G4AttUtils::GetKey(def);
81  }
82 
83  // Should be valid now
84  assert(myKey.IsValid());
85 
87 
88  G4VAttValueFilter* filter = factory->Create(myKey);
89  assert (0 != filter);
90 
91  return filter;
92  }
93 
94 }
pid_t filter
Definition: tracer.cxx:30
G4CreatorFactoryT< G4VAttValueFilter, G4TypeKey, G4VAttValueFilter *(*)()> G4AttValueFilterFactory
#define assert(x)
Definition: mymalloc.cc:1309
G4TypeKey GetKey(const G4AttDef &def)
Definition: G4AttUtils.cc:41
G4AttValueFilterFactory * GetAttValueFilterFactory()
bool G4bool
Definition: G4Types.hh:79
G4bool IsValid()
Definition: G4TypeKey.hh:50
G4bool Register(const Identifier &id, Creator creator)
G4VAttValueFilter * GetNewFilter(const G4AttDef &def)
const G4TypeKey & GetTypeKey() const
Definition: G4AttDef.hh:89