00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifndef PATTERNS_DMFACTORY_HPP
00014 #define PATTERNS_DMFACTORY_HPP
00015
00016 #if defined(NT_MSVCPP)
00017 #pragma warning (disable: 4786)
00018 #endif
00019
00020 #include "CLHEP/config/CLHEP.h"
00021 #include "CLHEP/config/iostream.h"
00022 #include <assert.h>
00023 #include <memory>
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 #include <algorithm>
00028 #include <iterator>
00029
00030 #include "CLHEP/HepPDT/DecayModelBase.hh"
00031 #include "CLHEP/HepPDT/pretend.hh"
00032
00033
00034
00035
00036
00037 namespace HepPDT {
00038
00043 template< class Config >
00044 struct MakerBase
00045 {
00046 typedef typename Config::ParticleData PD;
00047 typedef typename Config::PT PT;
00048 typedef DecayModelBase<Config> Product;
00049 virtual Product* make(const std::vector<double>& arg) = 0;
00050 virtual ~MakerBase() {};
00051 };
00052
00057 template <class T, class Config>
00058 struct Maker : public MakerBase<Config>
00059 {
00060 typedef DecayModelBase<Config> Product;
00061 virtual ~Maker() {}
00062 virtual Product* make(const std::vector<double>& arg) { return new T(arg); }
00063 };
00064
00069 template< class Config >
00070 class DMFactory
00071 {
00072 public:
00073 typedef typename Config::ParticleData PD;
00074 typedef typename Config::PT PT;
00075 typedef DecayModelBase<Config> Product;
00076
00077 typedef std::map<std::string, MakerBase<Config>*> funcmap;
00078 typedef typename funcmap::const_iterator const_iterator;
00079 typedef typename funcmap::iterator iterator;
00080
00081
00082 static DMFactory* instance();
00083
00084
00085 void addProduct(const std::string& k, MakerBase<Config>* m);
00086
00087 std::auto_ptr<Product> makeProduct(const std::string& k,
00088 const std::vector<double>& a) const;
00089
00090
00091 Product* unsafeMakeProduct(const std::string& k,
00092 const std::vector<double>& a) const;
00093
00094
00095
00096 unsigned long numKeys() const;
00097
00098
00099 private:
00100
00101 funcmap _makerfuncs;
00102
00103
00104 DMFactory();
00105 ~DMFactory();
00106
00107 DMFactory(const DMFactory&);
00108 DMFactory& operator=(const DMFactory&);
00109
00110 static DMFactory* _inst;
00111 static void destroy_and_clear();
00112
00113 struct Cleaner;
00114 friend struct Cleaner;
00115 struct Cleaner { ~Cleaner() { DMFactory::destroy_and_clear(); } };
00116
00117 };
00118
00119
00120
00121
00122
00123
00124
00129 template <class T, class Config>
00130 struct RegisterMe
00131 {
00132 RegisterMe(const std::string& key)
00133 {
00134 typedef T product_t;
00135 MakerBase<Config>* p = new Maker<product_t,Config>;
00136 DMFactory<Config>::instance()->addProduct(key, p);
00137 }
00138 };
00139
00140 }
00141
00142 #include "CLHEP/HepPDT/DMFactory.icc"
00143
00144 #endif // #ifndef PATTERNS_DMFACTORY_HPP
00145
00146
00147
00148
00149
00150
00151
00152