Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef CLASS_HASH_HPP_
- #define CLASS_HASH_HPP_
- #include <string>
- #include <map>
- template<typename T_base, typename T_key = std::string>
- class class_hash {
- public:
- template<typename T_sub>
- static void Register(const T_key& key){
- Get().Classes[key] = []() -> T_base* {return new T_sub;};
- }
- static T_base* Create(const T_key& key){
- return Get().Classes[key]();
- }
- protected:
- static class_hash& Get(){
- static class_hash Manager;
- return Manager;
- }
- class_hash(){}
- std::map<T_key, T_base*(*)()> Classes;
- };
- #endif /* CLASS_HASH_HPP_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement