32#ifndef G4CREATORFACTORYT_HH
33#define G4CREATORFACTORYT_HH
38template <
typename T,
typename Identifier,
typename Creator>
53 T*
Create(
const Identifier&
id)
const;
57 typedef std::map<Identifier, Creator> Map;
64template <
typename T,
typename Identifier,
typename Creator>
67template <
typename T,
typename Identifier,
typename Creator>
70template <
typename T,
typename Identifier,
typename Creator>
75 if (fMap.find(
id) != fMap.end()) {
77 ed <<
"Creator with identifier "<<
id<<
" already exists."<<
G4endl;
79 (
"G4CreatorFactoryT::Register(const Identifier& id, Creator creator)",
86 std::pair<Identifier, Creator> myPair(
id, creator);
87 return fMap.insert(myPair).second;
90template <
typename T,
typename Identifier,
typename Creator>
94 typename Map::const_iterator iter = fMap.find(
id);
96 if (iter == fMap.end()) {
98 ed <<
"Identifier "<<
id<<
" does not exist."<<
G4endl;
99 G4Exception(
"G4CreatorFactoryT::Create(const Identifier& id)",
101 "Non-existent identifier");
105 return iter->second();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4bool Register(const Identifier &id, Creator creator)
T * Create(const Identifier &id) const
virtual ~G4CreatorFactoryT()