CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PluginFactory.h
Go to the documentation of this file.
1 #ifndef FWCore_PluginManager_PluginFactory_h
2 #define FWCore_PluginManager_PluginFactory_h
3 // -*- C++ -*-
4 //
5 // Package: PluginManager
6 // Class : PluginFactory
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu Apr 5 12:10:23 EDT 2007
19 //
20 
21 // system include files
22 #include <map>
23 #include <vector>
24 
25 // user include files
28 // forward declarations
29 
30 namespace edmplugin {
31  template< class T> class PluginFactory;
32  class DummyFriend;
33 
34 template<class R>
35 class PluginFactory<R * (void)> : public PluginFactoryBase
36 {
37  friend class DummyFriend;
38  public:
39  struct PMakerBase {
40  virtual R* create(void) const = 0;
41  virtual ~PMakerBase() {}
42  };
43  template<class TPlug>
44  struct PMaker : public PMakerBase {
45  PMaker(const std::string& iName) {
46  PluginFactory<R*(void)>::get()->registerPMaker(this,iName);
47  }
48  virtual R* create() const {
49  return new TPlug();
50  }
51  };
52 
53  // ---------- const member functions ---------------------
54  virtual const std::string& category() const ;
55 
56  R* create(const std::string& iName) const {
57  return reinterpret_cast<PMakerBase*>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create();
58  }
59 
61  R* tryToCreate(const std::string& iName) const {
62  typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
63  if(itFound ==m_plugins.end() ) {
64  return 0;
65  }
66  return reinterpret_cast<PMakerBase*>(itFound->second.front().first)->create();
67  }
68  // ---------- static member functions --------------------
69 
70  static PluginFactory<R*(void)>* get();
71  // ---------- member functions ---------------------------
72  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
73  PluginFactoryBase::registerPMaker(iPMaker, iName);
74  }
75 
76  private:
78  finishedConstruction();
79  }
80  PluginFactory(const PluginFactory&); // stop default
81 
82  const PluginFactory& operator=(const PluginFactory&); // stop default
83 
84 };
85 
86 template<class R, class Arg>
87 class PluginFactory<R * (Arg)> : public PluginFactoryBase
88 {
89  friend class DummyFriend;
90 public:
91  struct PMakerBase {
92  virtual R* create(Arg) const = 0;
93  virtual ~PMakerBase() {}
94  };
95  template<class TPlug>
96  struct PMaker : public PMakerBase {
97  PMaker(const std::string& iName) {
98  PluginFactory<R*(Arg)>::get()->registerPMaker(this,iName);
99  }
100  virtual R* create(Arg iArg) const {
101  return new TPlug(iArg);
102  }
103  };
104 
105  // ---------- const member functions ---------------------
106  virtual const std::string& category() const ;
107 
108  R* create(const std::string& iName, Arg iArg) const {
109  return reinterpret_cast<PMakerBase *>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create(iArg);
110  }
112  R* tryToCreate(const std::string& iName, Arg iArg) const {
113  typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
114  if(itFound ==m_plugins.end() ) {
115  return 0;
116  }
117  return reinterpret_cast<PMakerBase *>(itFound->second.front().first)->create(iArg);
118  }
119  // ---------- static member functions --------------------
120 
121  static PluginFactory<R*(Arg)>* get();
122  // ---------- member functions ---------------------------
123  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
124  PluginFactoryBase::registerPMaker(iPMaker, iName);
125  }
126 
127 private:
129  finishedConstruction();
130  }
131  PluginFactory(const PluginFactory&); // stop default
132 
133  const PluginFactory& operator=(const PluginFactory&); // stop default
134 
135 };
136 
137 template<class R, class Arg1, class Arg2>
138 class PluginFactory<R * (Arg1, Arg2)> : public PluginFactoryBase
139 {
140  friend class DummyFriend;
141 public:
142  struct PMakerBase {
143  virtual R* create(Arg1, Arg2) const = 0;
144  virtual ~PMakerBase() {}
145  };
146  template<class TPlug>
147  struct PMaker : public PMakerBase {
148  PMaker(const std::string& iName) {
149  PluginFactory<R*(Arg1,Arg2)>::get()->registerPMaker(this,iName);
150  }
151  virtual R* create(Arg1 iArg1, Arg2 iArg2) const {
152  return new TPlug(iArg1, iArg2);
153  }
154  };
155 
156  // ---------- const member functions ---------------------
157  virtual const std::string& category() const ;
158 
159  R* create(const std::string& iName, Arg1 iArg1, Arg2 iArg2) const {
160  return reinterpret_cast<PMakerBase *>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create(iArg1, iArg2);
161  }
163  R* tryToCreate(const std::string& iName, Arg1 iArg1, Arg2 iArg2) const {
164  typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
165  if(itFound ==m_plugins.end() ) {
166  return 0;
167  }
168  return reinterpret_cast<PMakerBase *>(itFound->second.front().first)->create(iArg1,iArg2);
169  }
170 
171  // ---------- static member functions --------------------
172 
173  static PluginFactory<R*(Arg1,Arg2)>* get();
174  // ---------- member functions ---------------------------
175  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
176  PluginFactoryBase::registerPMaker(iPMaker, iName);
177  }
178 
179 private:
181  finishedConstruction();
182  }
183  PluginFactory(const PluginFactory&); // stop default
184 
185  const PluginFactory& operator=(const PluginFactory&); // stop default
186 
187 };
188 
189 }
190 #define CONCATENATE_HIDDEN(a,b) a ## b
191 #define CONCATENATE(a,b) CONCATENATE_HIDDEN(a,b)
192 #define EDM_REGISTER_PLUGINFACTORY(_factory_,_category_) \
193 namespace edmplugin {\
194  template<> _factory_* _factory_::get() { static _factory_ s_instance; return &s_instance;}\
195  template<> const std::string& _factory_::category() const { static std::string s_cat(_category_); return s_cat;}\
196 } enum {CONCATENATE(dummy_edm_register_pluginfactory_, __LINE__)}
197 
198 #endif
199 
200 #define EDM_PLUGIN_SYM(x,y) EDM_PLUGIN_SYM2(x,y)
201 #define EDM_PLUGIN_SYM2(x,y) x ## y
202 
203 #define DEFINE_EDM_PLUGIN(factory,type,name) \
204 static factory::PMaker<type> EDM_PLUGIN_SYM(s_maker , __LINE__ ) (name)
205 
nocap nocap const skelname & operator=(const skelname &)
void registerPMaker(PMakerBase *iPMaker, const std::string &iName)
Definition: PluginFactory.h:72
void registerPMaker(PMakerBase *iPMaker, const std::string &iName)
virtual R * create(Arg1 iArg1, Arg2 iArg2) const
void registerPMaker(void *iPMaker, const std::string &iName)
R * tryToCreate(const std::string &iName, Arg1 iArg1, Arg2 iArg2) const
like above but returns 0 if iName is unknown
R * create(const std::string &iName, Arg1 iArg1, Arg2 iArg2) const
R * tryToCreate(const std::string &iName, Arg iArg) const
like above but returns 0 if iName is unknown
R * create(const std::string &iName) const
Definition: PluginFactory.h:56
R * tryToCreate(const std::string &iName) const
like above but returns 0 if iName is unknown
Definition: PluginFactory.h:61
virtual R * create(Arg iArg) const
R * create(const std::string &iName, Arg iArg) const
Plugins::const_iterator tryToFindPMaker(const std::string &iName) const
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
void registerPMaker(PMakerBase *iPMaker, const std::string &iName)
Plugins::const_iterator findPMaker(const std::string &iName) const
SurfaceDeformation * create(int type, const std::vector< double > &params)