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  typedef R* TemplateArgType(void);
40 
41  struct PMakerBase {
42  virtual R* create(void) const = 0;
43  virtual ~PMakerBase() {}
44  };
45  template<class TPlug>
46  struct PMaker : public PMakerBase {
47  PMaker(const std::string& iName) {
48  PluginFactory<R*(void)>::get()->registerPMaker(this,iName);
49  }
50  virtual R* create() const {
51  return new TPlug();
52  }
53  };
54 
55  // ---------- const member functions ---------------------
56  virtual const std::string& category() const ;
57 
58  R* create(const std::string& iName) const {
59  return reinterpret_cast<PMakerBase*>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create();
60  }
61 
63  R* tryToCreate(const std::string& iName) const {
64  typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
65  if(itFound ==m_plugins.end() ) {
66  return 0;
67  }
68  return reinterpret_cast<PMakerBase*>(itFound->second.front().first)->create();
69  }
70  // ---------- static member functions --------------------
71 
72  static PluginFactory<R*(void)>* get();
73  // ---------- member functions ---------------------------
74  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
75  PluginFactoryBase::registerPMaker(iPMaker, iName);
76  }
77 
78  private:
80  finishedConstruction();
81  }
82  PluginFactory(const PluginFactory&); // stop default
83 
84  const PluginFactory& operator=(const PluginFactory&); // stop default
85 
86 };
87 
88 template<class R, class Arg>
89 class PluginFactory<R * (Arg)> : public PluginFactoryBase
90 {
91  friend class DummyFriend;
92 public:
93  typedef R *TemplateArgType(Arg);
94  struct PMakerBase {
95  virtual R* create(Arg) const = 0;
96  virtual ~PMakerBase() {}
97  };
98  template<class TPlug>
99  struct PMaker : public PMakerBase {
100  PMaker(const std::string& iName) {
101  PluginFactory<R*(Arg)>::get()->registerPMaker(this,iName);
102  }
103  virtual R* create(Arg iArg) const {
104  return new TPlug(iArg);
105  }
106  };
107 
108  // ---------- const member functions ---------------------
109  virtual const std::string& category() const ;
110 
111  R* create(const std::string& iName, Arg iArg) const {
112  return reinterpret_cast<PMakerBase *>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create(iArg);
113  }
115  R* tryToCreate(const std::string& iName, Arg iArg) const {
116  typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
117  if(itFound ==m_plugins.end() ) {
118  return 0;
119  }
120  return reinterpret_cast<PMakerBase *>(itFound->second.front().first)->create(iArg);
121  }
122  // ---------- static member functions --------------------
123 
124  static PluginFactory<R*(Arg)>* get();
125  // ---------- member functions ---------------------------
126  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
127  PluginFactoryBase::registerPMaker(iPMaker, iName);
128  }
129 
130 private:
132  finishedConstruction();
133  }
134  PluginFactory(const PluginFactory&); // stop default
135 
136  const PluginFactory& operator=(const PluginFactory&); // stop default
137 
138 };
139 
140 template<class R, class Arg1, class Arg2>
141 class PluginFactory<R * (Arg1, Arg2)> : public PluginFactoryBase
142 {
143  friend class DummyFriend;
144 public:
145  typedef R *TemplateArgType(Arg1,Arg2);
146  struct PMakerBase {
147  virtual R* create(Arg1, Arg2) const = 0;
148  virtual ~PMakerBase() {}
149  };
150  template<class TPlug>
151  struct PMaker : public PMakerBase {
152  PMaker(const std::string& iName) {
153  PluginFactory<R*(Arg1,Arg2)>::get()->registerPMaker(this,iName);
154  }
155  virtual R* create(Arg1 iArg1, Arg2 iArg2) const {
156  return new TPlug(iArg1, iArg2);
157  }
158  };
159 
160  // ---------- const member functions ---------------------
161  virtual const std::string& category() const ;
162 
163  R* create(const std::string& iName, Arg1 iArg1, Arg2 iArg2) const {
164  return reinterpret_cast<PMakerBase *>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create(iArg1, iArg2);
165  }
167  R* tryToCreate(const std::string& iName, Arg1 iArg1, Arg2 iArg2) const {
168  typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
169  if(itFound ==m_plugins.end() ) {
170  return 0;
171  }
172  return reinterpret_cast<PMakerBase *>(itFound->second.front().first)->create(iArg1,iArg2);
173  }
174 
175  // ---------- static member functions --------------------
176 
177  static PluginFactory<R*(Arg1,Arg2)>* get();
178  // ---------- member functions ---------------------------
179  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
180  PluginFactoryBase::registerPMaker(iPMaker, iName);
181  }
182 
183 private:
185  finishedConstruction();
186  }
187  PluginFactory(const PluginFactory&); // stop default
188 
189  const PluginFactory& operator=(const PluginFactory&); // stop default
190 
191 };
192 
193 }
194 #define CONCATENATE_HIDDEN(a,b) a ## b
195 #define CONCATENATE(a,b) CONCATENATE_HIDDEN(a,b)
196 #define EDM_REGISTER_PLUGINFACTORY(_factory_,_category_) \
197 namespace edmplugin {\
198  template<> edmplugin::PluginFactory<_factory_::TemplateArgType>* edmplugin::PluginFactory<_factory_::TemplateArgType>::get() { static edmplugin::PluginFactory<_factory_::TemplateArgType> s_instance; return &s_instance;}\
199  template<> const std::string& edmplugin::PluginFactory<_factory_::TemplateArgType>::category() const { static std::string s_cat(_category_); return s_cat;}\
200  } enum {CONCATENATE(dummy_edm_register_pluginfactory_, __LINE__)}
201 
202 #endif
203 
204 #define EDM_PLUGIN_SYM(x,y) EDM_PLUGIN_SYM2(x,y)
205 #define EDM_PLUGIN_SYM2(x,y) x ## y
206 
207 #define DEFINE_EDM_PLUGIN(factory,type,name) \
208 static factory::PMaker<type> EDM_PLUGIN_SYM(s_maker , __LINE__ ) (name)
209 
nocap nocap const skelname & operator=(const skelname &)
void registerPMaker(PMakerBase *iPMaker, const std::string &iName)
Definition: PluginFactory.h:74
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:58
R * tryToCreate(const std::string &iName) const
like above but returns 0 if iName is unknown
Definition: PluginFactory.h:63
virtual R * create(Arg iArg) const
R * create(const std::string &iName, Arg iArg) const
Plugins::const_iterator tryToFindPMaker(const std::string &iName) const
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)