Explorar el Código

Rename Event class method

Patrick-Christopher Mattulat hace 5 meses
padre
commit
71f3a1d5b3

+ 2 - 2
include/ls-std/event/Event.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2024-05-16
-* Changed:         2024-05-17
+* Changed:         2024-05-30
 *
 * */
 
@@ -25,8 +25,8 @@ namespace ls::std::event
       ~Event() noexcept override;
 
       [[nodiscard]] ::std::shared_ptr<ls::std::core::Class> getManager() const;
-      [[nodiscard]] ls::std::event::Event of(const ::std::shared_ptr<ls::std::core::Class> &_manager) const;
       void setManager(const ::std::shared_ptr<ls::std::core::Class> &_manager);
+      [[nodiscard]] ls::std::event::Event supervisedBy(const ::std::shared_ptr<ls::std::core::Class> &_manager) const;
 
     private:
 

+ 8 - 8
source/ls-std/event/Event.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2024-05-16
-* Changed:         2024-05-17
+* Changed:         2024-05-30
 *
 * */
 
@@ -26,17 +26,17 @@ shared_ptr<Class> Event::getManager() const
   return this->manager;
 }
 
-Event Event::of(const shared_ptr<Class> &_manager) const
+void Event::setManager(const shared_ptr<Class> &_manager)
 {
   NullPointerArgumentEvaluator(_manager).evaluate();
-  auto event = Event(this->getClassName());
-  event.setManager(_manager);
-
-  return event;
+  this->manager = _manager;
 }
 
-void Event::setManager(const shared_ptr<Class> &_manager)
+Event Event::supervisedBy(const shared_ptr<Class> &_manager) const
 {
   NullPointerArgumentEvaluator(_manager).evaluate();
-  this->manager = _manager;
+  auto event = Event(this->getClassName());
+  event.setManager(_manager);
+
+  return event;
 }

+ 9 - 9
test/cases/event/EventListenerTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2024-05-16
-* Changed:         2024-05-17
+* Changed:         2024-05-30
 *
 * */
 
@@ -76,7 +76,7 @@ namespace
   TEST_F(EventListenerTest, subscribe)
   {
     auto myButton = make_shared<Button>();
-    ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(make_shared<EventManager>()), [myButton]() mutable { myButton->onClickEvent(); }));
+    ASSERT_TRUE(myButton->subscribe(OnClickEvent().supervisedBy(make_shared<EventManager>()), [myButton]() mutable { myButton->onClickEvent(); }));
   }
 
   TEST_F(EventListenerTest, subscribe_second_time)
@@ -84,8 +84,8 @@ namespace
     auto myButton = make_shared<Button>();
     auto eventManager = make_shared<EventManager>();
 
-    ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
-    ASSERT_FALSE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
+    ASSERT_TRUE(myButton->subscribe(OnClickEvent().supervisedBy(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
+    ASSERT_FALSE(myButton->subscribe(OnClickEvent().supervisedBy(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
   }
 
   TEST_F(EventListenerTest, unsubscribe_with_missing_event_manager)
@@ -115,8 +115,8 @@ namespace
     auto myButton = make_shared<Button>();
     auto eventManager = make_shared<EventManager>();
 
-    ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
-    ASSERT_TRUE(myButton->unsubscribe(OnClickEvent().of(eventManager)));
+    ASSERT_TRUE(myButton->subscribe(OnClickEvent().supervisedBy(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
+    ASSERT_TRUE(myButton->unsubscribe(OnClickEvent().supervisedBy(eventManager)));
   }
 
   TEST_F(EventListenerTest, unsubscribe_second_time)
@@ -124,8 +124,8 @@ namespace
     auto myButton = make_shared<Button>();
     auto eventManager = make_shared<EventManager>();
 
-    ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
-    ASSERT_TRUE(myButton->unsubscribe(OnClickEvent().of(eventManager)));
-    ASSERT_FALSE(myButton->unsubscribe(OnClickEvent().of(eventManager)));
+    ASSERT_TRUE(myButton->subscribe(OnClickEvent().supervisedBy(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
+    ASSERT_TRUE(myButton->unsubscribe(OnClickEvent().supervisedBy(eventManager)));
+    ASSERT_FALSE(myButton->unsubscribe(OnClickEvent().supervisedBy(eventManager)));
   }
 }

+ 3 - 3
test/cases/event/EventManagerTest.cpp

@@ -56,11 +56,11 @@ namespace
     auto eventManager = make_shared<EventManager>();
 
     auto myBlueButton = make_shared<Button>();
-    myBlueButton->subscribe(OnClickEvent().of(eventManager), [myBlueButton]() mutable { myBlueButton->onClickEvent(); });
-    myBlueButton->subscribe(ChangeColorEvent().of(eventManager), [myBlueButton]() mutable { myBlueButton->onChangeColorEvent(); });
+    myBlueButton->subscribe(OnClickEvent().supervisedBy(eventManager), [myBlueButton]() mutable { myBlueButton->onClickEvent(); });
+    myBlueButton->subscribe(ChangeColorEvent().supervisedBy(eventManager), [myBlueButton]() mutable { myBlueButton->onChangeColorEvent(); });
     auto myRedButton = make_shared<Button>();
     auto myGreenButton = make_shared<Button>();
-    myGreenButton->subscribe(ChangeColorEvent().of(eventManager), [myGreenButton]() mutable { myGreenButton->onChangeColorEvent(); });
+    myGreenButton->subscribe(ChangeColorEvent().supervisedBy(eventManager), [myGreenButton]() mutable { myGreenButton->onChangeColorEvent(); });
 
     // status without any event invoked
 

+ 3 - 3
test/cases/event/EventTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2024-05-16
-* Changed:         2024-05-17
+* Changed:         2024-05-30
 *
 * */
 
@@ -39,7 +39,7 @@ namespace
 
   TEST_F(EventTest, of)
   {
-    auto event = Event("TmpEvent").of(make_shared<EventManager>());
+    auto event = Event("TmpEvent").supervisedBy(make_shared<EventManager>());
 
     ASSERT_STREQ("TmpEvent", event.getClassName().c_str());
     ASSERT_TRUE(event.getManager() != nullptr);
@@ -51,7 +51,7 @@ namespace
         {
           try
           {
-            auto event = Event("TmpEvent").of(nullptr);
+            auto event = Event("TmpEvent").supervisedBy(nullptr);
           }
           catch (const IllegalArgumentException &_exception)
           {