resource: updated doc/tests

This commit is contained in:
Michele Caini
2022-02-22 08:15:09 +01:00
parent 5cf0ba079f
commit e8d85d9269
2 changed files with 10 additions and 12 deletions

View File

@@ -51,14 +51,12 @@ struct my_loader final: entt::resource_loader<my_loader, my_resource> {
```
Where `my_resource` is the type of resources it creates.<br/>
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.<br/>
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<my_loader, my_resource> {
std::shared_ptr<my_resource> load(int value) const {
entt::resource_handle<my_resource> load(int value) const {
// ...
return std::shared_ptr<my_resource>(new my_resource{ value });
}
@@ -130,9 +128,9 @@ cache.load<my_loader>(identifier, 0);
cache.load<my_loader>("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<my_loader>("another/identifier"_hs, 42); handle) {
@@ -154,8 +152,8 @@ existing resource if needed:
auto handle = cache.reload<my_loader>("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

View File

@@ -27,7 +27,7 @@ struct derived_resource: resource {
template<typename Resource>
struct loader: entt::resource_loader<loader<Resource>, Resource> {
std::shared_ptr<Resource> load(int value) const {
entt::resource_handle<Resource> load(int value) const {
auto res = std::shared_ptr<Resource>(new Resource);
res->value = value;
return res;
@@ -36,7 +36,7 @@ struct loader: entt::resource_loader<loader<Resource>, Resource> {
template<typename Resource>
struct broken_loader: entt::resource_loader<broken_loader<Resource>, Resource> {
std::shared_ptr<Resource> load(int) const {
entt::resource_handle<Resource> load(int) const {
return nullptr;
}
};