Advertisement
WeltEnSTurm

Untitled

Oct 25th, 2011
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1.  
  2. #ifndef CLASS_HASH_HPP_
  3. #define CLASS_HASH_HPP_
  4.  
  5. #include <string>
  6. #include <map>
  7.  
  8. template<typename T_base, typename T_key = std::string>
  9. class class_hash {
  10.     public:
  11.         template<typename T_sub>
  12.         static void Register(const T_key& key){
  13.             Get().Classes[key] = []() -> T_base* {return new T_sub;};
  14.         }
  15.  
  16.         static T_base* Create(const T_key& key){
  17.             return Get().Classes[key]();
  18.         }
  19.  
  20.     protected:
  21.  
  22.         static class_hash& Get(){
  23.             static class_hash Manager;
  24.             return Manager;
  25.         }
  26.  
  27.         class_hash(){}
  28.  
  29.         std::map<T_key, T_base*(*)()> Classes;
  30.  
  31. };
  32.  
  33. #endif /* CLASS_HASH_HPP_ */
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement