33 #ifndef G4CREATORFACTORYT_HH
34 #define G4CREATORFACTORYT_HH
39 template <
typename T,
typename Identifier,
typename Creator>
54 T*
Create(
const Identifier&
id)
const;
58 typedef std::map<Identifier, Creator>
Map;
65 template <
typename T,
typename Identifier,
typename Creator>
68 template <
typename T,
typename Identifier,
typename Creator>
71 template <
typename T,
typename Identifier,
typename Creator>
76 if (fMap.find(
id) != fMap.end()) {
78 ed <<
"Creator with identifier "<<
id<<
" already exists."<<
G4endl;
80 (
"G4CreatorFactoryT::Register(const Identifier& id, Creator creator)",
87 std::pair<Identifier, Creator> myPair(
id, creator);
88 return fMap.insert(myPair).second;
91 template <
typename T,
typename Identifier,
typename Creator>
95 typename Map::const_iterator iter = fMap.find(
id);
97 if (iter == fMap.end()) {
99 ed <<
"Identifier "<<
id<<
" does not exist."<<
G4endl;
100 G4Exception(
"G4CreatorFactoryT::Create(const Identifier& id)",
102 "Non-existent identifier");
106 return iter->second();
std::ostringstream G4ExceptionDescription
std::map< Identifier, Creator > Map
virtual ~G4CreatorFactoryT()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4bool Register(const Identifier &id, Creator creator)
T * Create(const Identifier &id) const