#pragma once #include #include #include #include #include "imaging/PixelariumImage.hpp" namespace pixelarium::resources { struct IResource { virtual ~IResource() = default; }; template concept ResT = requires(R& r) { static_cast(r); }; // template template class IResourcePool { public: virtual ~IResourcePool() = default; virtual std::optional GetResource(size_t id) const = 0; virtual size_t SetResource(std::unique_ptr res) = 0; virtual bool ModifyResource(size_t id, std::unique_ptr res) = 0; virtual bool DeleteResource(size_t id) = 0; virtual void EnumerateResources(const std::function& func) = 0; }; // Now with the =GetResource= method, I do not want to transfer ownership to the caller of that method. The ownership // should still // reside with the =ResourcePool=! // In fact, the intention is, that there is no way back once the =ResourcePool= took ownership of an object. // Callers can get references, but no ownership. A caller might delete a resource though. class ImageResourcePool : public IResourcePool { public: ImageResourcePool() = default; ImageResourcePool(ImageResourcePool&) = delete; ImageResourcePool(const ImageResourcePool&) = delete; ImageResourcePool(ImageResourcePool&&) = delete; ImageResourcePool& operator=(ImageResourcePool&) = delete; ImageResourcePool& operator=(ImageResourcePool&&) = delete; std::optional GetResource(size_t id) const override; size_t SetResource(std::unique_ptr res) override; bool ModifyResource(size_t id, std::unique_ptr res) override; bool DeleteResource(size_t id) override; void EnumerateResources(const std::function& func) override; private: std::unordered_map> resources_; }; } // namespace pixelarium::resources