#ifndef _REFLECTOR_H #define _REFLECTOR_H #include #include #include #include #include #include class Reflector{ public: typedef std::function FuncType; private: std::map> objectMap; public: std::vector getAllRegisterFun(){ std::vector re; for(auto& x : objectMap){ re.push_back(x.second.first); } return re; } bool registerFun(const char* name, const std::string& proto, FuncType && generator){ assert(objectMap.find(name) == objectMap.end()); objectMap[name] = std::make_pair(proto, generator); return true; } bool runFun(const char* name, int argc, char const *argv[]){ auto ptr = objectMap.find(name); if(ptr == objectMap.end()){ std::cout << "err! not find "<< name << std::endl; return false; } ptr->second.second(argc, argv); return true; } static Reflector* Instance(){ static Reflector ptr; return &ptr; } }; #endif