From e8d85d926993971d02f70899a1ab8d2eb53eca71 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 22 Feb 2022 08:15:09 +0100 Subject: [PATCH] resource: updated doc/tests --- docs/md/resource.md | 18 ++++++++---------- test/entt/resource/resource.cpp | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/md/resource.md b/docs/md/resource.md index 29328edd5..cf74baebc 100644 --- a/docs/md/resource.md +++ b/docs/md/resource.md @@ -51,14 +51,12 @@ struct my_loader final: entt::resource_loader { ``` Where `my_resource` is the type of resources it creates.
-A resource loader must also expose a public const member function named `load` -that accepts a variable number of arguments and returns a shared pointer to a -resource.
-As an example: +It must also expose a public const member function named `load` that accepts a +variable number of arguments and returns a resource handle: ```cpp struct my_loader: entt::resource_loader { - std::shared_ptr load(int value) const { + entt::resource_handle load(int value) const { // ... return std::shared_ptr(new my_resource{ value }); } @@ -130,9 +128,9 @@ cache.load(identifier, 0); cache.load("another/identifier"_hs, 42); ``` -The function returns a handle to the resource, whether it already exists or is -loaded. In case the loader returns an invalid pointer, the handle is invalid as -well and therefore it can be easily used with an `if` statement: +The function returns a resource handle, whether it already exists or is loaded. +In case the loader returns an invalid pointer, the handle is invalid as well and +therefore it can be easily used with an `if` statement: ```cpp if(entt::resource_handle handle = cache.load("another/identifier"_hs, 42); handle) { @@ -154,8 +152,8 @@ existing resource if needed: auto handle = cache.reload("another/identifier"_hs, 42); ``` -As above, the function returns a handle to the resource that is invalid in case -of errors. The `reload` member function is a kind of alias of the following +As above, the function returns a resource handle that is invalid in case of +errors. The `reload` member function is a kind of alias of the following snippet: ```cpp diff --git a/test/entt/resource/resource.cpp b/test/entt/resource/resource.cpp index 6d56fcbc8..4caf82a46 100644 --- a/test/entt/resource/resource.cpp +++ b/test/entt/resource/resource.cpp @@ -27,7 +27,7 @@ struct derived_resource: resource { template struct loader: entt::resource_loader, Resource> { - std::shared_ptr load(int value) const { + entt::resource_handle load(int value) const { auto res = std::shared_ptr(new Resource); res->value = value; return res; @@ -36,7 +36,7 @@ struct loader: entt::resource_loader, Resource> { template struct broken_loader: entt::resource_loader, Resource> { - std::shared_ptr load(int) const { + entt::resource_handle load(int) const { return nullptr; } };