1#ifndef RESOURCE_MANAGEMENT_H
2#define RESOURCE_MANAGEMENT_H
7#include <unordered_map>
17 template <
typename Resource,
typename Identifier>
27 template <
typename Concrete,
typename... Args>
30 auto resource = std::make_unique<Concrete>(std::forward<Args>(
args)...);
33 throw std::runtime_error(
"Failed to load resource");
35 insert_resource(
id, std::move(resource));
41 Resource &
get(Identifier
id);
46 const Resource &
get(Identifier
id)
const;
51 m_resources_map.clear();
55 [[nodiscard]]
bool is_empty() const noexcept {
return m_resources_map.empty(); }
61 void insert_resource(Identifier
id, std::unique_ptr<Resource> resource);
63 std::unordered_map<Identifier, std::unique_ptr<Resource>> m_resources_map;
71 template <
typename Resource,
typename Identifier>
74 auto found = m_resources_map.find(
id);
75 if (found == m_resources_map.cend())
77 throw std::out_of_range(
"Key not found");
80 return *found->second;
88 template <
typename Resource,
typename Identifier>
91 auto found = m_resources_map.find(
id);
92 if (found == m_resources_map.cend())
94 throw std::out_of_range(
"Key not found");
97 return *found->second;
105 template <
typename Resource,
typename Identifier>
106 void resource_management<Resource, Identifier>::insert_resource(Identifier
id, std::unique_ptr<Resource> resource)
108 m_resources_map.insert_or_assign(
id, std::move(resource));
Command-line argument handler with JSON support.
Definition args.h:19
Template class for managing resources.
Definition resource_management.h:19
void load(Identifier id, Args &&...args)
Loads a resource of a specific type.
Definition resource_management.h:28
void clear() noexcept
Clears all resources from the manager.
Definition resource_management.h:49
bool is_empty() const noexcept
Checks if the resource manager is empty.
Definition resource_management.h:55
Resource & get(Identifier id)
Retrieves a resource by its identifier.
Definition resource_management.h:72
const Resource & get(Identifier id) const
Retrieves a const reference to a resource by its identifier.
Definition resource_management.h:89