CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/SimG4Core/Notification/interface/ComponentFactoryByName.h

Go to the documentation of this file.
00001 #ifndef SimG4Core_ComponentFactoryByName_H 
00002 #define SimG4Core_ComponentFactoryByName_H 
00003 
00004 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00005 
00006 #include <string>
00007 #include <map>
00008 
00009 template <class B>
00010 class ComponentFactoryByName
00011 {
00012 public:
00013     static B * getBuilder(const std::string & name)
00014     {
00015         if (myMap().size() == 0)
00016             throw SimG4Exception("No Builder registered to the Factory.");
00017         if (myMap().find(name) == myMap().end())
00018             throw SimG4Exception("The Component "+name+" is not registered to the Factory.");
00019         return (myMap()[name]);
00020     }
00021     static void setBuilder(B * in , const std::string & name)
00022     {
00023         if (name.empty())
00024             throw SimG4Exception("The registration of Components without name is not allowed.");
00025         myMap()[name] = in;
00026     }
00027     typedef std::map<std::string,B *> BuilderMapType;
00028 protected:
00029     static BuilderMapType & myMap()
00030     {
00031         static BuilderMapType me_;
00032         return me_;
00033     }
00034 };
00035 
00036 #endif
00037 
00038 
00039