.. _program_listing_file_PrismEngine_src_resourceManager.h: Program Listing for File resourceManager.h ========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``PrismEngine/src/resourceManager.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "resource.h" #include #include #include #include #include #include namespace prism { namespace scene { class ResourceManager { public: ResourceManager() = default; template void set(T resource) { auto typeIndex = std::type_index(typeid(T)); resources[typeIndex] = std::move(resource); } template T* get() { auto typeIndex = std::type_index(typeid(T)); auto it = resources.find(typeIndex); return it != resources.end() ? std::any_cast(&it->second) : nullptr; } template const T* get() const { auto typeIndex = std::type_index(typeid(T)); auto it = resources.find(typeIndex); return it != resources.end() ? std::any_cast(&it->second) : nullptr; } template bool has() const { auto typeIndex = std::type_index(typeid(T)); return resources.find(typeIndex) != resources.end(); } template bool remove() { auto typeIndex = std::type_index(typeid(T)); return resources.erase(typeIndex) > 0; } void clear() { resources.clear(); } ~ResourceManager() { clear(); } private: std::unordered_map resources; }; } }