Warning, file /include/Geant4/G4CrossSectionFactory.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #ifndef G4CrossSectionFactory_h
0027 #define G4CrossSectionFactory_h 1
0028
0029
0030 #include "globals.hh"
0031 #include "G4VCrossSectionDataSet.hh"
0032 #include "G4CrossSectionFactoryRegistry.hh"
0033 #include "G4Threading.hh"
0034
0035 class G4VBaseXSFactory
0036 {
0037
0038 public:
0039
0040 virtual G4VCrossSectionDataSet* Instantiate() = 0;
0041
0042 };
0043
0044
0045
0046 template <typename T, int mode> class G4CrossSectionFactory : public G4VBaseXSFactory
0047 {
0048 public:
0049 G4CrossSectionFactory(const G4String& name)
0050 {
0051 G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0052 }
0053
0054 virtual G4VCrossSectionDataSet* Instantiate()
0055 {
0056 G4ExceptionDescription msg;
0057 msg<<"Factory mode: "<<mode<<" not supported!";
0058 G4Exception("G4CrossSectionFactory::Instantiate","CrossSectionFactory001",FatalException,msg);
0059 return static_cast<T*>(0);
0060 }
0061 };
0062
0063
0064
0065 template <typename T> class G4CrossSectionFactory<T,0> : public G4VBaseXSFactory
0066 {
0067 public:
0068
0069 G4CrossSectionFactory(const G4String& name)
0070 {
0071 G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0072 }
0073
0074 virtual G4VCrossSectionDataSet* Instantiate()
0075 {
0076 return new T();
0077 }
0078 };
0079
0080
0081
0082 template <typename T> class G4CrossSectionFactory<T,1> : public G4VBaseXSFactory
0083 {
0084 public:
0085 G4CrossSectionFactory(const G4String& name)
0086 {
0087 G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0088 }
0089
0090 virtual G4VCrossSectionDataSet* Instantiate()
0091 {
0092 static T* shared = new T();
0093 return shared;
0094 }
0095 };
0096
0097
0098
0099 template <typename T> class G4CrossSectionFactory<T,2> : public G4VBaseXSFactory
0100 {
0101 G4CrossSectionFactory(const G4String& name)
0102 {
0103 G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0104 }
0105
0106 virtual G4VCrossSectionDataSet* Instantiate()
0107 {
0108 static G4ThreadLocal T* shared = new T();
0109 return shared;
0110 }
0111 };
0112
0113
0114 #define G4_BASE_DECLARE_XS_FACTORY(cross_section, flag) \
0115 const G4CrossSectionFactory<cross_section,flag>& cross_section##Factory = G4CrossSectionFactory<cross_section,flag>(cross_section::Default_Name())
0116
0117 #define G4_BASE_REFERENCE_XS_FACTORY(cross_section,flag) \
0118 class cross_section; \
0119 extern const G4CrossSectionFactory<cross_section,flag>& cross_section##Factory; \
0120 const G4CrossSectionFactory<cross_section,flag>& cross_section##FactoryRef = cross_section##Factory
0121
0122
0123 #define G4_DECLARE_XS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,0)
0124 #define G4_DECLARE_SHAREDXS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,1)
0125 #define G4_DECLARE_SHAREDTLSXS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,2)
0126
0127
0128 #define G4_REFERENCE_XS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,0)
0129 #define G4_REFERENCE_SHAREDXS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,1)
0130 #define G4_REFERENCE_SHAREDTLSXS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,2)
0131
0132 #endif