Explorar o código

resource: added prefix resource_ to all classes

Michele Caini %!s(int64=5) %!d(string=hai) anos
pai
achega
900398a632

+ 10 - 10
docs/md/resource.md

@@ -42,10 +42,10 @@ struct my_resource { const int value; };
 ```
 
 A _loader_ is a class the aim of which is to load a specific resource. It has to
-inherit directly from the dedicated base class as in the following example:
+inherit directly from a dedicated base class as in the following example:
 
 ```cpp
-struct my_loader final: entt::loader<my_loader, my_resource> {
+struct my_loader final: entt::resource_loader<my_loader, my_resource> {
     // ...
 };
 ```
@@ -57,7 +57,7 @@ resource.<br/>
 As an example:
 
 ```cpp
-struct my_loader: entt::loader<my_loader, my_resource> {
+struct my_loader: entt::resource_loader<my_loader, my_resource> {
     std::shared_ptr<my_resource> load(int value) const {
         // ...
         return std::shared_ptr<my_resource>(new my_resource{ value });
@@ -76,7 +76,7 @@ Finally, a cache is a specialization of a class template tailored to a specific
 resource:
 
 ```cpp
-using my_cache = entt::cache<my_resource>;
+using my_cache = entt::resource_cache<my_resource>;
 
 // ...
 
@@ -112,7 +112,7 @@ created explicitly as in the following example:
 ```cpp
 constexpr auto identifier = "my/resource/identifier"_hs;
 // this is equivalent to the following
-constexpr auto hs = entt::hashed_string{"my/resource/identifier"};
+constexpr entt::id_type hs = entt::hashed_string{"my/resource/identifier"};
 ```
 
 The class `hashed_string` is described in a dedicated section, so I won't go in
@@ -135,7 +135,7 @@ 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(auto handle = cache.load<my_loader>("another/identifier"_hs, 42); handle) {
+if(entt::resource_handle handle = cache.load<my_loader>("another/identifier"_hs, 42); handle) {
     // ...
 }
 ```
@@ -180,24 +180,24 @@ Users of a resource own a handle that guarantees that a resource isn't destroyed
 until all the handles are destroyed, even if the resource itself is removed from
 the cache.<br/>
 Handles are tiny objects both movable and copyable. They return the contained
-resource as a const reference on request:
+resource as a (possibly const) reference on request:
 
 * By means of the `get` member function:
 
   ```cpp
-  const auto &resource = handle.get();
+  auto &resource = handle.get();
   ```
 
 * Using the proper cast operator:
 
   ```cpp
-  const auto &resource = handle;
+  auto &resource = handle;
   ```
 
 * Through the dereference operator:
 
   ```cpp
-  const auto &resource = *handle;
+  auto &resource = *handle;
   ```
 
 The resource can also be accessed directly using the arrow operator if required:

+ 17 - 17
src/entt/resource/cache.hpp

@@ -27,20 +27,20 @@ namespace entt {
  * @tparam Resource Type of resources managed by a cache.
  */
 template<typename Resource>
-struct cache {
+struct resource_cache {
     /*! @brief Unsigned integer type. */
     using size_type = std::size_t;
     /*! @brief Type of resources managed by a cache. */
     using resource_type = Resource;
 
     /*! @brief Default constructor. */
-    cache() = default;
+    resource_cache() = default;
 
     /*! @brief Default move constructor. */
-    cache(cache &&) = default;
+    resource_cache(resource_cache &&) = default;
 
     /*! @brief Default move assignment operator. @return This cache. */
-    cache & operator=(cache &&) = default;
+    resource_cache & operator=(resource_cache &&) = default;
 
     /**
      * @brief Number of resources managed by a cache.
@@ -91,9 +91,9 @@ struct cache {
      * @return A handle for the given resource.
      */
     template<typename Loader, typename... Args>
-    entt::handle<Resource> load(const id_type id, Args &&... args) {
-        static_assert(std::is_base_of_v<loader<Loader, Resource>, Loader>, "Invalid loader type");
-        entt::handle<Resource> resource{};
+    resource_handle<Resource> load(const id_type id, Args &&... args) {
+        static_assert(std::is_base_of_v<resource_loader<Loader, Resource>, Loader>, "Invalid loader type");
+        resource_handle<Resource> resource{};
 
         if(auto it = resources.find(id); it == resources.cend()) {
             if(auto instance = Loader{}.get(std::forward<Args>(args)...); instance) {
@@ -131,7 +131,7 @@ struct cache {
      * @return A handle for the given resource.
      */
     template<typename Loader, typename... Args>
-    entt::handle<Resource> reload(const id_type id, Args &&... args) {
+    resource_handle<Resource> reload(const id_type id, Args &&... args) {
         return (discard(id), load<Loader>(id, std::forward<Args>(args)...));
     }
 
@@ -148,7 +148,7 @@ struct cache {
      * @return A handle for the given resource.
      */
     template<typename Loader, typename... Args>
-    [[nodiscard]] entt::handle<Resource> temp(Args &&... args) const {
+    [[nodiscard]] resource_handle<Resource> temp(Args &&... args) const {
         return { Loader{}.get(std::forward<Args>(args)...) };
     }
 
@@ -160,12 +160,12 @@ struct cache {
      * cache contains the resource itself. Otherwise the returned handle is
      * uninitialized and accessing it results in undefined behavior.
      *
-     * @sa handle
+     * @sa resource_handle
      *
      * @param id Unique resource identifier.
      * @return A handle for the given resource.
      */
-    [[nodiscard]] entt::handle<Resource> handle(const id_type id) const {
+    [[nodiscard]] resource_handle<Resource> handle(const id_type id) const {
         auto it = resources.find(id);
         return { it == resources.end() ? nullptr : it->second };
     }
@@ -202,9 +202,9 @@ struct cache {
      * forms:
      *
      * @code{.cpp}
-     * void(const id_type);
-     * void(handle<Resource>);
-     * void(const id_type, handle<Resource>);
+     * void(const entt::id_type);
+     * void(entt::resource_handle<Resource>);
+     * void(const entt::id_type, entt::resource_handle<Resource>);
      * @endcode
      *
      * @tparam Func Type of the function object to invoke.
@@ -220,10 +220,10 @@ struct cache {
 
             if constexpr(std::is_invocable_v<Func, id_type>) {
                 func(curr->first);
-            } else if constexpr(std::is_invocable_v<Func, entt::handle<Resource>>) {
-                func(entt::handle{ curr->second });
+            } else if constexpr(std::is_invocable_v<Func, resource_handle<Resource>>) {
+                func(resource_handle{ curr->second });
             } else {
-                func(curr->first, entt::handle{ curr->second });
+                func(curr->first, resource_handle{ curr->second });
             }
         }
     }

+ 3 - 3
src/entt/resource/fwd.hpp

@@ -7,15 +7,15 @@ namespace entt {
 
 /*! @struct cache */
 template<typename>
-struct cache;
+struct resource_cache;
 
 /*! @class handle */
 template<typename>
-class handle;
+class resource_handle;
 
 /*! @class loader */
 template<typename, typename>
-class loader;
+class resource_loader;
 
 
 }

+ 4 - 4
src/entt/resource/handle.hpp

@@ -24,17 +24,17 @@ namespace entt {
  * @tparam Resource Type of resource managed by a handle.
  */
 template<typename Resource>
-class handle {
+class resource_handle {
     /*! @brief Resource handles are friends of their caches. */
-    friend struct cache<Resource>;
+    friend struct resource_cache<Resource>;
 
-    handle(std::shared_ptr<Resource> res) ENTT_NOEXCEPT
+    resource_handle(std::shared_ptr<Resource> res) ENTT_NOEXCEPT
         : resource{std::move(res)}
     {}
 
 public:
     /*! @brief Default constructor. */
-    handle() ENTT_NOEXCEPT = default;
+    resource_handle() ENTT_NOEXCEPT = default;
 
     /**
      * @brief Gets a reference to the managed resource.

+ 3 - 3
src/entt/resource/loader.hpp

@@ -21,7 +21,7 @@ namespace entt {
  * @code{.cpp}
  * struct my_resource {};
  *
- * struct my_loader: entt::loader<my_loader, my_resource> {
+ * struct my_loader: entt::resource_loader<my_loader, my_resource> {
  *     std::shared_ptr<my_resource> load(int) const {
  *         // use the integer value somehow
  *         return std::make_shared<my_resource>();
@@ -42,9 +42,9 @@ namespace entt {
  * @tparam Resource Type of resource for which to use the loader.
  */
 template<typename Loader, typename Resource>
-class loader {
+class resource_loader {
     /*! @brief Resource loaders are friends of their caches. */
-    friend struct cache<Resource>;
+    friend struct resource_cache<Resource>;
 
     /**
      * @brief Loads the resource and returns it.

+ 18 - 18
test/entt/resource/resource.cpp

@@ -5,25 +5,25 @@
 
 struct resource { int value; };
 
-struct loader: entt::loader<loader, resource> {
+struct loader: entt::resource_loader<loader, resource> {
     std::shared_ptr<resource> load(int value) const {
         return std::shared_ptr<resource>(new resource{ value });
     }
 };
 
-struct broken_loader: entt::loader<broken_loader, resource> {
+struct broken_loader: entt::resource_loader<broken_loader, resource> {
     std::shared_ptr<resource> load(int) const {
         return nullptr;
     }
 };
 
 TEST(Resource, Functionalities) {
-    entt::cache<resource> cache;
+    entt::resource_cache<resource> cache;
 
     constexpr auto hs1 = entt::hashed_string{"res1"};
     constexpr auto hs2 = entt::hashed_string{"res2"};
 
-    ASSERT_EQ(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_EQ(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_TRUE(cache.empty());
     ASSERT_FALSE(cache.contains(hs1));
     ASSERT_FALSE(cache.contains(hs2));
@@ -31,7 +31,7 @@ TEST(Resource, Functionalities) {
     ASSERT_FALSE(cache.load<broken_loader>(hs1, 42));
     ASSERT_FALSE(cache.reload<broken_loader>(hs1, 42));
 
-    ASSERT_EQ(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_EQ(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_TRUE(cache.empty());
     ASSERT_FALSE(cache.contains(hs1));
     ASSERT_FALSE(cache.contains(hs2));
@@ -39,7 +39,7 @@ TEST(Resource, Functionalities) {
     ASSERT_TRUE(cache.load<loader>(hs1, 42));
     ASSERT_TRUE(cache.reload<loader>(hs1, 42));
 
-    ASSERT_NE(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_NE(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_FALSE(cache.empty());
     ASSERT_TRUE(cache.contains(hs1));
     ASSERT_FALSE(cache.contains(hs2));
@@ -48,7 +48,7 @@ TEST(Resource, Functionalities) {
     ASSERT_TRUE(cache.load<loader>(hs1, 42));
     ASSERT_TRUE(cache.load<loader>(hs2, 42));
 
-    ASSERT_NE(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_NE(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_FALSE(cache.empty());
     ASSERT_TRUE(cache.contains(hs1));
     ASSERT_TRUE(cache.contains(hs2));
@@ -64,14 +64,14 @@ TEST(Resource, Functionalities) {
     ASSERT_TRUE(cache.load<loader>(hs1, 42));
     ASSERT_NO_THROW(cache.clear());
 
-    ASSERT_EQ(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_EQ(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_TRUE(cache.empty());
     ASSERT_FALSE(cache.contains(hs1));
     ASSERT_FALSE(cache.contains(hs2));
 
     ASSERT_TRUE(cache.load<loader>(hs1, 42));
 
-    ASSERT_NE(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_NE(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_FALSE(cache.empty());
     ASSERT_TRUE(cache.handle(hs1));
     ASSERT_FALSE(cache.handle(hs2));
@@ -80,21 +80,21 @@ TEST(Resource, Functionalities) {
     ASSERT_EQ(&cache.handle(hs1).get(), &static_cast<const resource &>(cache.handle(hs1)));
     ASSERT_NO_THROW(cache.clear());
 
-    ASSERT_EQ(cache.size(), entt::cache<resource>::size_type{});
+    ASSERT_EQ(cache.size(), entt::resource_cache<resource>::size_type{});
     ASSERT_TRUE(cache.empty());
 
     ASSERT_TRUE(cache.temp<loader>(42));
     ASSERT_TRUE(cache.empty());
 
-    ASSERT_FALSE(entt::handle<resource>{});
-    ASSERT_TRUE(std::is_copy_constructible_v<entt::handle<resource>>);
-    ASSERT_TRUE(std::is_move_constructible_v<entt::handle<resource>>);
-    ASSERT_TRUE(std::is_copy_assignable_v<entt::handle<resource>>);
-    ASSERT_TRUE(std::is_move_assignable_v<entt::handle<resource>>);
+    ASSERT_FALSE(entt::resource_handle<resource>{});
+    ASSERT_TRUE(std::is_copy_constructible_v<entt::resource_handle<resource>>);
+    ASSERT_TRUE(std::is_move_constructible_v<entt::resource_handle<resource>>);
+    ASSERT_TRUE(std::is_copy_assignable_v<entt::resource_handle<resource>>);
+    ASSERT_TRUE(std::is_move_assignable_v<entt::resource_handle<resource>>);
 }
 
 TEST(Resource, MutableHandle) {
-    entt::cache<resource> cache;
+    entt::resource_cache<resource> cache;
 
     constexpr auto hs = entt::hashed_string{"res"};
     auto handle = cache.load<loader>(hs, 0);
@@ -110,10 +110,10 @@ TEST(Resource, MutableHandle) {
 }
 
 TEST(Resource, Each) {
-    entt::cache<resource> cache;
+    entt::resource_cache<resource> cache;
     cache.load<loader>("resource"_hs, 0);
 
-    cache.each([](entt::handle<resource> res) {
+    cache.each([](entt::resource_handle<resource> res) {
         ++res->value;
     });