Browse Source

Improve method naming in Narrator class

Patrick-Christopher Mattulat 3 years ago
parent
commit
ca7c3315d9

+ 3 - 3
include/ls_std/logic/Narrator.hpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2020-11-14
+ * Changed:         2020-11-28
  *
  * */
 
 #ifndef LS_STD_NARRATOR_HPP
 #define LS_STD_NARRATOR_HPP
 
-#include "../base/Class.hpp"
+#include <ls_std/base/Class.hpp>
 #include "IListener.hpp"
 #include <list>
 #include <memory>
@@ -25,8 +25,8 @@ namespace ls_std {
       void addListener(const std::shared_ptr<ls_std::IListener>& _listener);
       void clear();
       std::list<std::shared_ptr<ls_std::IListener>> getListeners();
-      void notifyListeners(const ls_std::Class& _info);
       void removeListener(const std::shared_ptr<ls_std::IListener>& _listener);
+      void tell(const ls_std::Class& _info);
 
     private:
 

+ 7 - 7
source/ls_std/logic/Narrator.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2020-11-26
+ * Changed:         2020-11-28
  *
  * */
 
@@ -30,16 +30,16 @@ std::list<std::shared_ptr<ls_std::IListener>> ls_std::Narrator::getListeners()
   return this->listeners;
 }
 
-void ls_std::Narrator::notifyListeners(const ls_std::Class &_info)
+void ls_std::Narrator::removeListener(const std::shared_ptr<ls_std::IListener>& _listener)
 {
-  for(const auto& listener : this->listeners) {
-    listener->listen(_info);
+  if(ls_std::STLUtils::contains(this->listeners, _listener)) {
+    this->listeners.remove(_listener);
   }
 }
 
-void ls_std::Narrator::removeListener(const std::shared_ptr<ls_std::IListener>& _listener)
+void ls_std::Narrator::tell(const ls_std::Class &_info)
 {
-  if(ls_std::STLUtils::contains(this->listeners, _listener)) {
-    this->listeners.remove(_listener);
+  for(const auto& listener : this->listeners) {
+    listener->listen(_info);
   }
 }

+ 21 - 21
test/cases/logic/NarratorTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2020-11-14
+ * Changed:         2020-11-28
  *
  * */
 
@@ -68,26 +68,6 @@ namespace {
     ASSERT_TRUE(narrator.getListeners().empty());
   }
 
-  TEST_F(NarratorTest, notifyListeners)
-  {
-    this->createCars();
-    ls_std::Narrator paintingMachine {};
-    paintingMachine.addListener(std::dynamic_pointer_cast<ls_std::IListener>(this->mercedes1));
-    paintingMachine.addListener(std::dynamic_pointer_cast<ls_std::IListener>(this->mercedes2));
-    paintingMachine.addListener(std::dynamic_pointer_cast<ls_std::IListener>(this->mercedes3));
-
-    ASSERT_STREQ("pink", this->mercedes1->getColor().c_str());
-    ASSERT_STREQ("blue", this->mercedes2->getColor().c_str());
-    ASSERT_STREQ("red", this->mercedes3->getColor().c_str());
-
-    ls_std::String newColor {"black"};
-    paintingMachine.notifyListeners(static_cast<const ls_std::Class&>(newColor));
-
-    ASSERT_STREQ("black", this->mercedes1->getColor().c_str());
-    ASSERT_STREQ("black", this->mercedes2->getColor().c_str());
-    ASSERT_STREQ("black", this->mercedes3->getColor().c_str());
-  }
-
   TEST_F(NarratorTest, removeListener)
   {
     this->createCars();
@@ -109,4 +89,24 @@ namespace {
     ASSERT_EQ(0, paintingMachine.getListeners().size());
     ASSERT_TRUE(paintingMachine.getListeners().empty());
   }
+
+  TEST_F(NarratorTest, tell)
+  {
+    this->createCars();
+    ls_std::Narrator paintingMachine {};
+    paintingMachine.addListener(std::dynamic_pointer_cast<ls_std::IListener>(this->mercedes1));
+    paintingMachine.addListener(std::dynamic_pointer_cast<ls_std::IListener>(this->mercedes2));
+    paintingMachine.addListener(std::dynamic_pointer_cast<ls_std::IListener>(this->mercedes3));
+
+    ASSERT_STREQ("pink", this->mercedes1->getColor().c_str());
+    ASSERT_STREQ("blue", this->mercedes2->getColor().c_str());
+    ASSERT_STREQ("red", this->mercedes3->getColor().c_str());
+
+    ls_std::String newColor {"black"};
+    paintingMachine.tell(static_cast<const ls_std::Class &>(newColor));
+
+    ASSERT_STREQ("black", this->mercedes1->getColor().c_str());
+    ASSERT_STREQ("black", this->mercedes2->getColor().c_str());
+    ASSERT_STREQ("black", this->mercedes3->getColor().c_str());
+  }
 }