CMS 3D CMS Logo

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
29 // forward declarations
30 
31 namespace edmplugin {
32 template< class T> class PluginFactory;
33  class DummyFriend;
34 
35 template<typename R, typename... Args>
36 class PluginFactory<R*(Args...)> : public PluginFactoryBase
37 {
38  friend class DummyFriend;
39  public:
40  typedef R* TemplateArgType(Args...);
41 
42  struct PMakerBase {
43  virtual R* create(Args...) const = 0;
44  virtual ~PMakerBase() {}
45  };
46  template<class TPlug>
47  struct PMaker : public PMakerBase {
48  PMaker(const std::string& iName) {
49  PluginFactory<R*(Args...)>::get()->registerPMaker(this,iName);
50  }
51  R* create(Args... args) const override {
52  return new TPlug(std::forward<Args>(args)...);
53  }
54  };
55 
56  // ---------- const member functions ---------------------
57  const std::string& category() const override ;
58 
59  R* create(const std::string& iName, Args... args) const {
60  return reinterpret_cast<PMakerBase*>(PluginFactoryBase::findPMaker(iName))->create(std::forward<Args>(args)...);
61  }
62 
64  R* tryToCreate(const std::string& iName, Args... args) const {
66  if(found ==nullptr) {
67  return nullptr;
68  }
69  return reinterpret_cast<PMakerBase*>(found)->create(args...);
70  }
71  // ---------- static member functions --------------------
72 
73  static PluginFactory<R*(Args...)>* get();
74  // ---------- member functions ---------------------------
75  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
76  PluginFactoryBase::registerPMaker(iPMaker, iName);
77  }
78 
79  private:
81  finishedConstruction();
82  }
83  PluginFactory(const PluginFactory&) = delete; // stop default
84 
85  const PluginFactory& operator=(const PluginFactory&) = delete; // stop default
86 
87 };
88 }
89 #define CONCATENATE_HIDDEN(a,b) a ## b
90 #define CONCATENATE(a,b) CONCATENATE_HIDDEN(a,b)
91 #define EDM_REGISTER_PLUGINFACTORY(_factory_,_category_) \
92 namespace edmplugin {\
93  template<> edmplugin::PluginFactory<_factory_::TemplateArgType>* edmplugin::PluginFactory<_factory_::TemplateArgType>::get() { CMS_THREAD_SAFE static edmplugin::PluginFactory<_factory_::TemplateArgType> s_instance; return &s_instance;}\
94  template<> const std::string& edmplugin::PluginFactory<_factory_::TemplateArgType>::category() const { static const std::string s_cat(_category_); return s_cat;}\
95  } enum {CONCATENATE(dummy_edm_register_pluginfactory_, __LINE__)}
96 
97 #endif
98 
99 #define EDM_PLUGIN_SYM(x,y) EDM_PLUGIN_SYM2(x,y)
100 #define EDM_PLUGIN_SYM2(x,y) x ## y
101 
102 #define DEFINE_EDM_PLUGIN(factory,type,name) \
103 static const factory::PMaker<type> EDM_PLUGIN_SYM(s_maker , __LINE__ ) (name)
104 
def create(alignables, pedeDump, additionalData, outputFile, config)
void registerPMaker(void *iPMaker, const std::string &iName)
R * create(const std::string &iName, Args...args) const
Definition: PluginFactory.h:59
R * create(Args...args) const override
Definition: PluginFactory.h:51
void registerPMaker(PMakerBase *iPMaker, const std::string &iName)
Definition: PluginFactory.h:75
void * findPMaker(const std::string &iName) const
R * tryToCreate(const std::string &iName, Args...args) const
like above but returns 0 if iName is unknown
Definition: PluginFactory.h:64
T get(const Candidate &c)
Definition: component.h:55
void * tryToFindPMaker(const std::string &iName) const