G4AttFilterUtils.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // Visualisation attribute filter utility functions.
00029 //
00030 // Jane Tinslay, September 2006
00031 //
00032 #include "G4AttFilterUtils.hh"
00033 #include "G4AttDef.hh"
00034 #include "G4AttUtils.hh"
00035 #include "G4AttValueFilterT.hh"
00036 #include "G4CreatorFactoryT.hh"
00037 #include "G4DimensionedDouble.hh"
00038 #include "G4DimensionedThreeVector.hh"
00039 #include "G4String.hh"
00040 #include "G4ThreeVector.hh"
00041 #include "G4TypeKey.hh"
00042 #include "G4TypeKeyT.hh"
00043 #include <assert.h>
00044 
00045 namespace G4AttFilterUtils {
00046   
00047   namespace {
00048     template <typename T>
00049     G4VAttValueFilter* newFilter() {
00050       return new G4AttValueFilterT<T>;
00051     }
00052   }
00053   
00054   // Create new G4AttValue filter factory
00055   G4AttValueFilterFactory* GetAttValueFilterFactory() {
00056     static G4AttValueFilterFactory* factory = new G4AttValueFilterFactory;
00057     static G4bool init(false);
00058     
00059     if (!init) {
00060       // Register typekey<->creator pairs
00061       factory->Register(G4TypeKeyT<G4String>(), newFilter<G4String>);
00062       factory->Register(G4TypeKeyT<G4int>(), newFilter<G4int>);
00063       factory->Register(G4TypeKeyT<G4double>(), newFilter<G4double>);
00064       factory->Register(G4TypeKeyT<G4ThreeVector>(), newFilter<G4ThreeVector>);
00065       factory->Register(G4TypeKeyT<G4bool>(), newFilter<G4bool>);
00066       factory->Register(G4TypeKeyT<G4DimensionedDouble>(), newFilter<G4DimensionedDouble>);
00067       factory->Register(G4TypeKeyT<G4DimensionedThreeVector>(), newFilter<G4DimensionedThreeVector>);
00068       init = true;
00069     }
00070     
00071     return factory;
00072   }
00073   
00074   G4VAttValueFilter* GetNewFilter(const G4AttDef& def) {
00075     
00076     G4TypeKey myKey = def.GetTypeKey();
00077     
00078     // Get correct type key if original G4AttDef's being used
00079     if (!myKey.IsValid()) {
00080       myKey = G4AttUtils::GetKey(def);
00081     }
00082     
00083     // Should be valid now
00084     assert(myKey.IsValid());
00085 
00086     G4AttValueFilterFactory* factory = GetAttValueFilterFactory();
00087  
00088     G4VAttValueFilter*  filter = factory->Create(myKey);
00089     assert (0 != filter);
00090 
00091     return filter;
00092   }
00093   
00094 }

Generated on Mon May 27 17:47:41 2013 for Geant4 by  doxygen 1.4.7