20 template <
class CLASS,
typename ARG1 =
void,
typename ARG2 =
int>
26 CLASS* (*ptr_factory1)(ARG1);
27 CLASS* (*ptr_factory2)(ARG1, ARG2);
36 CLASS*
create(
const std::string& class_name, ARG1 a1)
const 38 typename std::map<std::string, TClassData>::const_iterator it =
41 throw std::runtime_error(
42 (std::string(
"ClassFactory: Unknown class ") + class_name)
44 if (!it->second.ptr_factory1)
45 throw std::runtime_error(
46 (std::string(
"ClassFactory: factory(1) pointer is NULL for ") +
49 return (*it->second.ptr_factory1)(a1);
51 CLASS*
create(
const std::string& class_name, ARG1 a1, ARG2 a2)
const 53 typename std::map<std::string, TClassData>::const_iterator it =
56 throw std::runtime_error(
57 (std::string(
"ClassFactory: Unknown class ") + class_name)
59 if (!it->second.ptr_factory2)
60 throw std::runtime_error(
61 (std::string(
"ClassFactory: factory(2) pointer is NULL for ") +
64 return (*it->second.ptr_factory2)(a1, a2);
71 #define DECLARES_REGISTER_CLASS1(CLASS_NAME, BASE_CLASS, ARG1) \ 73 static BASE_CLASS* Create(ARG1 a1) { return new CLASS_NAME(a1); } 74 #define DECLARES_REGISTER_CLASS2(CLASS_NAME, BASE_CLASS, ARG1, ARG2) \ 76 static BASE_CLASS* Create(ARG1 a1, ARG2 a2) \ 78 return new CLASS_NAME(a1, a2); \ 81 #define REGISTER_CLASS1(FACTORY_TYPE, FACTORY_OBJ, TEXTUAL_NAME, CLASS_NAME) \ 83 FACTORY_TYPE::TClassData data; \ 84 data.ptr_factory1 = &CLASS_NAME::Create; \ 85 FACTORY_OBJ.do_register(TEXTUAL_NAME, data); \ 88 #define REGISTER_CLASS2(FACTORY_TYPE, FACTORY_OBJ, TEXTUAL_NAME, CLASS_NAME) \ 90 FACTORY_TYPE::TClassData data; \ 91 data.ptr_factory2 = &CLASS_NAME::Create; \ 92 FACTORY_OBJ.do_register(TEXTUAL_NAME, data); \
void do_register(const std::string &class_name, const TClassData &data)
CLASS *(* ptr_factory1)(ARG1)
CLASS * create(const std::string &class_name, ARG1 a1) const
CLASS *(* ptr_factory2)(ARG1, ARG2)
std::map< std::string, TClassData > m_classes
CLASS * create(const std::string &class_name, ARG1 a1, ARG2 a2) const