CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/PluginManager/interface/PluginFactory.h

Go to the documentation of this file.
00001 #ifndef FWCore_PluginManager_PluginFactory_h
00002 #define FWCore_PluginManager_PluginFactory_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     PluginManager
00006 // Class  :     PluginFactory
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Thu Apr  5 12:10:23 EDT 2007
00019 //
00020 
00021 // system include files
00022 #include <map>
00023 #include <vector>
00024 
00025 // user include files
00026 #include "FWCore/PluginManager/interface/PluginFactoryBase.h"
00027 #include "FWCore/PluginManager/interface/PluginManager.h"
00028 // forward declarations
00029 
00030 namespace edmplugin {
00031   template< class T> class PluginFactory;
00032   class DummyFriend;
00033   
00034 template<class R>
00035 class PluginFactory<R * (void)> : public PluginFactoryBase
00036 {
00037       friend class DummyFriend;
00038    public:
00039       struct PMakerBase {
00040         virtual R* create(void) const = 0;
00041         virtual ~PMakerBase() {}
00042       };
00043       template<class TPlug>
00044       struct PMaker : public PMakerBase {
00045         PMaker(const std::string& iName) {
00046           PluginFactory<R*(void)>::get()->registerPMaker(this,iName);
00047         }
00048         virtual R* create() const {
00049           return new TPlug();
00050         }
00051       };
00052 
00053       // ---------- const member functions ---------------------
00054       virtual const std::string& category() const ;
00055       
00056       R* create(const std::string& iName) const {
00057         return reinterpret_cast<PMakerBase*>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create();
00058       }
00059 
00061       R* tryToCreate(const std::string& iName) const {
00062         typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
00063         if(itFound ==m_plugins.end() ) {
00064           return 0;
00065         }
00066         return reinterpret_cast<PMakerBase*>(itFound->second.front().first)->create();
00067       }
00068       // ---------- static member functions --------------------
00069 
00070       static PluginFactory<R*(void)>* get();
00071       // ---------- member functions ---------------------------
00072       void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
00073         PluginFactoryBase::registerPMaker(iPMaker, iName);
00074       }
00075 
00076    private:
00077       PluginFactory() {
00078         finishedConstruction();
00079       }
00080       PluginFactory(const PluginFactory&); // stop default
00081 
00082       const PluginFactory& operator=(const PluginFactory&); // stop default
00083 
00084 };
00085 
00086 template<class R, class Arg>
00087 class PluginFactory<R * (Arg)> : public PluginFactoryBase
00088 {
00089   friend class DummyFriend;
00090 public:
00091   struct PMakerBase {
00092     virtual R* create(Arg) const = 0;
00093     virtual ~PMakerBase() {}
00094   };
00095   template<class TPlug>
00096     struct PMaker : public PMakerBase {
00097       PMaker(const std::string& iName) {
00098         PluginFactory<R*(Arg)>::get()->registerPMaker(this,iName);
00099       }
00100       virtual R* create(Arg iArg) const {
00101         return new TPlug(iArg);
00102       }
00103     };
00104   
00105   // ---------- const member functions ---------------------
00106   virtual const std::string& category() const ;
00107   
00108   R* create(const std::string& iName, Arg iArg) const {
00109     return reinterpret_cast<PMakerBase *>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create(iArg);
00110   }
00112   R* tryToCreate(const std::string& iName, Arg iArg) const {
00113     typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
00114     if(itFound ==m_plugins.end() ) {
00115       return 0;
00116     }
00117     return reinterpret_cast<PMakerBase *>(itFound->second.front().first)->create(iArg);
00118   }
00119   // ---------- static member functions --------------------
00120   
00121   static PluginFactory<R*(Arg)>* get();
00122   // ---------- member functions ---------------------------
00123   void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
00124     PluginFactoryBase::registerPMaker(iPMaker, iName);
00125   }
00126   
00127 private:
00128     PluginFactory() {
00129       finishedConstruction();
00130     }
00131   PluginFactory(const PluginFactory&); // stop default
00132   
00133   const PluginFactory& operator=(const PluginFactory&); // stop default
00134   
00135 };
00136 
00137 template<class R, class Arg1, class Arg2>
00138 class PluginFactory<R * (Arg1, Arg2)> : public PluginFactoryBase
00139 {
00140   friend class DummyFriend;
00141 public:
00142   struct PMakerBase {
00143     virtual R* create(Arg1, Arg2) const = 0;
00144     virtual ~PMakerBase() {}
00145   };
00146   template<class TPlug>
00147     struct PMaker : public PMakerBase {
00148       PMaker(const std::string& iName) {
00149         PluginFactory<R*(Arg1,Arg2)>::get()->registerPMaker(this,iName);
00150       }
00151       virtual R* create(Arg1 iArg1, Arg2 iArg2) const {
00152         return new TPlug(iArg1, iArg2);
00153       }
00154     };
00155   
00156   // ---------- const member functions ---------------------
00157   virtual const std::string& category() const ;
00158   
00159   R* create(const std::string& iName, Arg1 iArg1, Arg2 iArg2) const {
00160     return reinterpret_cast<PMakerBase *>(PluginFactoryBase::findPMaker(iName)->second.front().first)->create(iArg1, iArg2);
00161   }
00163   R* tryToCreate(const std::string& iName, Arg1 iArg1, Arg2 iArg2) const {
00164     typename Plugins::const_iterator itFound = PluginFactoryBase::tryToFindPMaker(iName);
00165     if(itFound ==m_plugins.end() ) {
00166       return 0;
00167     }
00168     return reinterpret_cast<PMakerBase *>(itFound->second.front().first)->create(iArg1,iArg2);
00169   }
00170 
00171   // ---------- static member functions --------------------
00172   
00173   static PluginFactory<R*(Arg1,Arg2)>* get();
00174   // ---------- member functions ---------------------------
00175   void registerPMaker(PMakerBase* iPMaker, const std::string& iName) {
00176     PluginFactoryBase::registerPMaker(iPMaker, iName);
00177   }
00178   
00179 private:
00180     PluginFactory() {
00181       finishedConstruction();
00182     }
00183   PluginFactory(const PluginFactory&); // stop default
00184   
00185   const PluginFactory& operator=(const PluginFactory&); // stop default
00186   
00187 };
00188 
00189 }
00190 #define CONCATENATE_HIDDEN(a,b) a ## b 
00191 #define CONCATENATE(a,b) CONCATENATE_HIDDEN(a,b)
00192 #define EDM_REGISTER_PLUGINFACTORY(_factory_,_category_) \
00193 namespace edmplugin {\
00194   template<> _factory_* _factory_::get() { static _factory_ s_instance; return &s_instance;}\
00195   template<> const std::string& _factory_::category() const { static std::string s_cat(_category_);  return s_cat;}\
00196 } enum {CONCATENATE(dummy_edm_register_pluginfactory_, __LINE__)}
00197 
00198 #endif
00199 
00200 #define EDM_PLUGIN_SYM(x,y) EDM_PLUGIN_SYM2(x,y)
00201 #define EDM_PLUGIN_SYM2(x,y) x ## y
00202 
00203 #define DEFINE_EDM_PLUGIN(factory,type,name) \
00204 static factory::PMaker<type> EDM_PLUGIN_SYM(s_maker , __LINE__ ) (name)
00205