8#include <Common/logging.h>
24 template<
typename Resource>
25 static std::size_t
addResource(std::unique_ptr<Resource> resource);
27 template<
typename Resource>
30 template<
typename Resource>
33 template<
typename Resource>
34 static std::weak_ptr<Resource>
useResource(std::size_t
id);
39 template<
typename Resource>
42 static std::mutex& MUTEX();
47template<
typename Resource>
50 std::lock_guard<std::mutex> lock(MUTEX());
52 const std::size_t
id = RESOURCES<Resource>().add(std::move(resource));
54 PH_LOG(
ApiDatabase, Note,
"added resource<{}>",
id);
59template<
typename Resource>
62 std::lock_guard<std::mutex> lock(MUTEX());
64 auto*
const resource = RESOURCES<Resource>().get(
id);
68 PH_LOG(
ApiDatabase, Warning,
"resource<{}> does not exist",
id);
71 return resource ? resource->get() :
nullptr;
74template<
typename Resource>
77 std::lock_guard<std::mutex> lock(MUTEX());
79 const bool isRemoved = RESOURCES<Resource>().remove(
id);
83 PH_LOG(
ApiDatabase, Note,
"removed resource<{}>",
id);
87 PH_LOG(
ApiDatabase, Warning,
"failed removing resource<{}>",
id);
93template<
typename Resource>
96 std::lock_guard<std::mutex> lock(MUTEX());
98 return RESOURCES<Resource>().isStableIndexValid(
id) ? RESOURCES<Resource>()[id] :
nullptr;
101template<
typename Resource>
105 std::is_same_v<Resource, Engine> ||
106 std::is_same_v<Resource, HdrRgbFrame> ||
107 std::is_same_v<Resource, ByteBuffer>,
108 "error: in ApiDatabase::getResource(), "
109 "type of the specified resource is unsupported");
115inline std::mutex& ApiDatabase::MUTEX()
117 static std::mutex lock;
Definition ApiDatabase.h:22
static bool removeResource(std::size_t id)
Definition ApiDatabase.h:75
static std::size_t addResource(std::unique_ptr< Resource > resource)
Definition ApiDatabase.h:48
static void clear()
Definition ApiDatabase.cpp:6
static std::weak_ptr< Resource > useResource(std::size_t id)
Definition ApiDatabase.h:94
static Resource * getResource(std::size_t id)
Definition ApiDatabase.h:60
A container offering stable index and efficient iteration.
Definition TStableIndexDenseVector.h:35
The root for all renderer implementations.
Definition EEngineProject.h:6
PH_DEFINE_EXTERNAL_LOG_GROUP(ApiDatabase, Core)