#ifndef REFLECTION_CC_CLASS_FACTORY_H #define REFLECTION_CC_CLASS_FACTORY_H #include #include #include #include "iostream" #include "CCClassFactoryInfo.h" #include "CCObject.h" namespace CTL { class ClassFactory { std::map> m_map; std::map> m_map_info; ClassFactory(); ~ClassFactory(); public: static ClassFactory* getInstance(); void register_class(const std::string& name, const std::function &create_func); Object* create_class(const std::string& name); void register_info(const std::string& name, const std::string& infoName, const std::string& type,size_t offset); int get_info_count(const std::string& className); ClassFactoryInfo* get_info(const std::string& className, int pos); ClassFactoryInfo* get_info(const std::string& className, const std::string& infoName); }; #define CC_CREATE_CLASS(className) (className*)CTL::ClassFactory::getInstance()->create_class(#className) #define CC_CREATE_CLASS_FROM_STRING(classNameStr) \ [](const std::string& str) -> void* { \ return CTL::ClassFactory::getInstance()->create_class(str); \ }(classNameStr) } #endif