21 template <
class CLASS,
typename ARG1 =
void,
typename ARG2 =
int>
25 using Ptr = std::shared_ptr<CLASS>;
29 CLASS* (*ptr_factory1)(ARG1);
30 CLASS* (*ptr_factory2)(ARG1, ARG2);
39 Ptr create(
const std::string& class_name, ARG1 a1)
const 43 throw std::runtime_error(
44 (std::string(
"ClassFactory: Unknown class ") + class_name)
46 if (!it->second.ptr_factory1)
47 throw std::runtime_error(
49 "ClassFactory: factory(1) pointer is nullptr for ") +
52 return Ptr((*it->second.ptr_factory1)(a1));
54 Ptr create(
const std::string& class_name, ARG1 a1, ARG2 a2)
const 58 throw std::runtime_error(
59 (std::string(
"ClassFactory: Unknown class ") + class_name)
61 if (!it->second.ptr_factory2)
62 throw std::runtime_error(
64 "ClassFactory: factory(2) pointer is nullptr for ") +
67 return Ptr((*it->second.ptr_factory2)(a1, a2));
74 #define DECLARES_REGISTER_CLASS1(CLASS_NAME, BASE_CLASS, ARG1) \ 76 static BASE_CLASS* Create(ARG1 a1) { return new CLASS_NAME(a1); } 77 #define DECLARES_REGISTER_CLASS2(CLASS_NAME, BASE_CLASS, ARG1, ARG2) \ 79 static BASE_CLASS* Create(ARG1 a1, ARG2 a2) \ 81 return new CLASS_NAME(a1, a2); \ 84 #define REGISTER_CLASS1(FACTORY_TYPE, FACTORY_OBJ, TEXTUAL_NAME, CLASS_NAME) \ 86 FACTORY_TYPE::TClassData data; \ 87 data.ptr_factory1 = &CLASS_NAME::Create; \ 88 FACTORY_OBJ.do_register(TEXTUAL_NAME, data); \ 91 #define REGISTER_CLASS2(FACTORY_TYPE, FACTORY_OBJ, TEXTUAL_NAME, CLASS_NAME) \ 93 FACTORY_TYPE::TClassData data; \ 94 data.ptr_factory2 = &CLASS_NAME::Create; \ 95 FACTORY_OBJ.do_register(TEXTUAL_NAME, data); \
Ptr create(const std::string &class_name, ARG1 a1, ARG2 a2) const
void do_register(const std::string &class_name, const TClassData &data)
CLASS *(* ptr_factory1)(ARG1)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Ptr create(const std::string &class_name, ARG1 a1) const
std::shared_ptr< CLASS > Ptr
CLASS *(* ptr_factory2)(ARG1, ARG2)
std::map< std::string, TClassData > m_classes