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  using TemplateArgType = R*(Args...);
41  using CreatedType = R;
42 
43  struct PMakerBase {
44  virtual R* create(Args...) const = 0;
45  virtual ~PMakerBase() {}
46  };
47  template<class TPlug>
48  struct PMaker : public PMakerBase {
49  PMaker(const std::string& iName) {
50  PluginFactory<R*(Args...)>::get()->registerPMaker(this,iName);
51  }
52  R* create(Args... args) const override {
53  return new TPlug(std::forward<Args>(args)...);
54  }
55  };
56 
57  // ---------- const member functions ---------------------
58  const std::string& category() const override ;
59 
60  R* create(const std::string& iName, Args... args) const {
61  return reinterpret_cast<PMakerBase*>(PluginFactoryBase::findPMaker(iName))->create(std::forward<Args>(args)...);
62  }
63 
65  R* tryToCreate(const std::string& iName, Args... args) const {
67  if(found ==nullptr) {
68  return nullptr;
69  }
70  return reinterpret_cast<PMakerBase*>(found)->create(args...);
71  }
72  // ---------- static member functions --------------------
73 
74  static PluginFactory<R*(Args...)>* get();
75  // ---------- member functions ---------------------------
76  void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
77  PluginFactoryBase::registerPMaker(iPMaker, iName);
78  }
79 
80  private:
82  finishedConstruction();
83  }
84  PluginFactory(const PluginFactory&) = delete; // stop default
85 
86  const PluginFactory& operator=(const PluginFactory&) = delete; // stop default
87 
88 };
89 }
90 #define CONCATENATE_HIDDEN(a,b) a ## b
91 #define CONCATENATE(a,b) CONCATENATE_HIDDEN(a,b)
92 #define EDM_REGISTER_PLUGINFACTORY(_factory_,_category_) \
93 namespace edmplugin {\
94  template<> edmplugin::PluginFactory<_factory_::TemplateArgType>* edmplugin::PluginFactory<_factory_::TemplateArgType>::get() { CMS_THREAD_SAFE static edmplugin::PluginFactory<_factory_::TemplateArgType> s_instance; return &s_instance;}\
95  template<> const std::string& edmplugin::PluginFactory<_factory_::TemplateArgType>::category() const { static const std::string s_cat(_category_); return s_cat;}\
96  } enum {CONCATENATE(dummy_edm_register_pluginfactory_, __LINE__)}
97 
98 #define EDM_REGISTER_PLUGINFACTORY2(_factory_,_category_) \
99 namespace edmplugin {\
100 template<> edmplugin::PluginFactory<_factory_::TemplateArgType>* edmplugin::PluginFactory<_factory_::TemplateArgType>::get() { CMS_THREAD_SAFE static edmplugin::PluginFactory<_factory_::TemplateArgType> s_instance; return &s_instance;}\
101 template<> const std::string& edmplugin::PluginFactory<_factory_::TemplateArgType>::category() const { static const std::string s_cat(_category_); return s_cat;}\
102 } enum {CONCATENATE(dummy_edm_register_pluginfactory_2_, __LINE__)}
103 
104 #endif
105 
106 #define EDM_PLUGIN_SYM(x,y) EDM_PLUGIN_SYM2(x,y)
107 #define EDM_PLUGIN_SYM2(x,y) x ## y
108 
109 #define DEFINE_EDM_PLUGIN(factory,type,name) \
110 static const factory::PMaker<type> EDM_PLUGIN_SYM(s_maker , __LINE__ ) (name)
111 
112 #define DEFINE_EDM_PLUGIN2(factory,type,name) \
113 static const factory::PMaker<type> EDM_PLUGIN_SYM(s_maker2 , __LINE__ ) (name)
114 
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:60
R * create(Args...args) const override
Definition: PluginFactory.h:52
void registerPMaker(PMakerBase *iPMaker, const std::string &iName)
Definition: PluginFactory.h:76
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:65
T get(const Candidate &c)
Definition: component.h:55
void * tryToFindPMaker(const std::string &iName) const