Prechádzať zdrojové kódy

process: single allocate ::function

skypjack 8 mesiacov pred
rodič
commit
7257dd50c6

+ 1 - 13
src/entt/process/process.hpp

@@ -113,18 +113,6 @@ public:
      */
     process &operator=(process &&) noexcept = default;
 
-    /**
-     * @brief Factory method.
-     * @tparam Type Type of process to create.
-     * @tparam Args Types of arguments to use to initialize the process.
-     * @param args Parameters to use to initialize the process.
-     * @return A properly initialized process.
-     */
-    template<typename Type, typename... Args>
-    static std::shared_ptr<Type> create(Args &&...args) {
-        return std::make_shared<Type>(process_arg_t{}, std::forward<Args>(args)...);
-    }
-
     /**
      * @brief Factory method.
      * @tparam Type Type of process to create.
@@ -135,7 +123,7 @@ public:
      * @return A properly initialized process.
      */
     template<typename Type, typename Allocator, typename... Args>
-    static std::shared_ptr<Type> create_with_allocator(std::allocator_arg_t, const Allocator &alloc, Args &&...args) {
+    static std::shared_ptr<Type> allocate(const Allocator &alloc, Args &&...args) {
         return std::allocate_shared<Type>(alloc, process_arg_t{}, std::forward<Args>(args)...);
     }
 

+ 2 - 2
src/entt/process/scheduler.hpp

@@ -202,7 +202,7 @@ public:
     template<typename Proc, typename... Args>
     basic_scheduler &attach(Args &&...args) {
         static_assert(std::is_base_of_v<process<Delta>, Proc>, "Invalid process type");
-        handlers.first().emplace_back().task = process<Delta>::create_with_allocator<Proc>(std::allocator_arg, handlers.second(), std::forward<Args>(args)...);
+        handlers.first().emplace_back().task = process<Delta>::allocate<Proc>(handlers.second(), std::forward<Args>(args)...);
         return *this;
     }
 
@@ -277,7 +277,7 @@ public:
         auto *curr = &handlers.first().back();
         for(; curr->next; curr = curr->next.get()) {}
         curr->next = std::allocate_shared<handler_type>(handlers.second());
-        curr->next->task = process<Delta>::create_with_allocator<Proc>(std::allocator_arg, handlers.second(), std::forward<Args>(args)...);
+        curr->next->task = process<Delta>::allocate<Proc>(handlers.second(), std::forward<Args>(args)...);
         return *this;
     }
 

+ 11 - 10
test/entt/process/process.cpp

@@ -1,4 +1,5 @@
 #include <cstdint>
+#include <memory>
 #include <gtest/gtest.h>
 #include <entt/process/process.hpp>
 #include "../../common/empty.h"
@@ -35,7 +36,7 @@ public:
 };
 
 TEST(Process, Basics) {
-    auto process = entt::process<int>::create<test_process<int>>();
+    auto process = entt::process<int>::allocate<test_process<int>>(std::allocator<void>{});
 
     ASSERT_FALSE(process->alive());
     ASSERT_FALSE(process->finished());
@@ -90,7 +91,7 @@ TEST(Process, Basics) {
 }
 
 TEST(Process, Succeeded) {
-    auto process = entt::process<test::empty>::create<test_process<test::empty>>();
+    auto process = entt::process<test::empty>::allocate<test_process<test::empty>>(std::allocator<void>{});
 
     process->tick({});
     process->tick({});
@@ -109,7 +110,7 @@ TEST(Process, Succeeded) {
 }
 
 TEST(Process, Fail) {
-    auto process = entt::process<int>::create<test_process<int>>();
+    auto process = entt::process<int>::allocate<test_process<int>>(std::allocator<void>{});
 
     process->tick(0);
     process->tick(0);
@@ -128,7 +129,7 @@ TEST(Process, Fail) {
 }
 
 TEST(Process, Data) {
-    auto process = entt::process<test::empty>::create<test_process<test::empty>>();
+    auto process = entt::process<test::empty>::allocate<test_process<test::empty>>(std::allocator<void>{});
     int value = 0;
 
     process->tick({});
@@ -149,7 +150,7 @@ TEST(Process, Data) {
 }
 
 TEST(Process, AbortNextTick) {
-    auto process = entt::process<int>::create<test_process<int>>();
+    auto process = entt::process<int>::allocate<test_process<int>>(std::allocator<void>{});
 
     process->tick(0);
     process->abort();
@@ -167,7 +168,7 @@ TEST(Process, AbortNextTick) {
 }
 
 TEST(Process, AbortImmediately) {
-    auto process = entt::process<test::empty>::create<test_process<test::empty>>();
+    auto process = entt::process<test::empty>::allocate<test_process<test::empty>>(std::allocator<void>{});
 
     process->tick({});
     process->abort(true);
@@ -191,7 +192,7 @@ TEST(ProcessAdaptor, Resolved) {
         resolve();
     };
 
-    auto process = entt::process<std::uint64_t>::create<entt::process_adaptor<decltype(lambda), std::uint64_t>>(lambda);
+    auto process = entt::process<std::uint64_t>::allocate<entt::process_adaptor<decltype(lambda), std::uint64_t>>(std::allocator<void>{}, lambda);
 
     process->tick(0);
     process->tick(0);
@@ -208,7 +209,7 @@ TEST(ProcessAdaptor, Rejected) {
         rejected();
     };
 
-    auto process = entt::process<std::uint64_t>::create<entt::process_adaptor<decltype(lambda), std::uint64_t>>(lambda);
+    auto process = entt::process<std::uint64_t>::allocate<entt::process_adaptor<decltype(lambda), std::uint64_t>>(std::allocator<void>{}, lambda);
 
     process->tick(0);
     process->tick(0);
@@ -224,10 +225,10 @@ TEST(ProcessAdaptor, Data) {
         resolve();
     };
 
-    auto process = entt::process<std::uint64_t>::create<entt::process_adaptor<decltype(lambda), std::uint64_t>>(lambda);
+    auto process = entt::process<std::uint64_t>::allocate<entt::process_adaptor<decltype(lambda), std::uint64_t>>(std::allocator<void>{}, lambda);
 
     process->tick(0, &value);
 
     ASSERT_TRUE(process->finished());
     ASSERT_EQ(value, 2);
-}
+}