From Flying Sloth, 7 Months ago, written in Plain Text.
This paste will shuffle off the mortal coil in 3 Months.
Embed
  1. #ifndef SYSTEM_MANAGER_HPP
  2. #define SYSTEM_MANAGER_HPP
  3.  
  4. #include <map>
  5. #include <typeindex>
  6.  
  7. #include "../System.hpp"
  8.  
  9. class SystemManager {
  10.     private:
  11.         std::map<std::type_index, System*> systems;
  12.     public:
  13.         void addSystem(std::type_index type, System* s){
  14.             systems[type] = s;
  15.         }
  16.         template <typename T>
  17.         T* get() {
  18.             auto it = systems.find(std::type_index(typeid(T)));
  19.             if (it != systems.end()) {
  20.                 return dynamic_cast<T*>(it->second);
  21.             }
  22.             return nullptr;
  23.         }      
  24. };
  25.  
  26. #endif /* SYSTEM_MANAGER_HPP */
  27.