Ver Fonte

Remove namespaces from event module class definitions

Patrick-Christopher Mattulat há 1 ano atrás
pai
commit
16fa143523

+ 20 - 12
source/ls-std/event/Event.cpp

@@ -3,21 +3,29 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2023-02-22
+ * Changed:         2023-02-23
  *
  * */
 
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
 #include <ls-std/event/Event.hpp>
 
-ls::std::event::Event::Event(const ls::std::core::type::event_id &_id) : ls::std::core::Class("Event")
+using ls::std::core::Class;
+using ls::std::core::EmptyStringArgumentEvaluator;
+using ls::std::core::type::event_id;
+using ls::std::core::type::event_parameter;
+using ls::std::core::type::event_parameter_id;
+using ls::std::core::type::event_parameter_list;
+using ls::std::event::Event;
+
+Event::Event(const event_id &_id) : Class("Event")
 {
   this->_assignId(_id);
 }
 
-ls::std::event::Event::~Event() noexcept = default;
+Event::~Event() noexcept = default;
 
-bool ls::std::event::Event::addParameter(const ls::std::core::type::event_parameter &_eventParameter)
+bool Event::addParameter(const event_parameter &_eventParameter)
 {
   bool wasAdded{};
 
@@ -29,38 +37,38 @@ bool ls::std::event::Event::addParameter(const ls::std::core::type::event_parame
   return wasAdded;
 }
 
-void ls::std::event::Event::clearParameterList()
+void Event::clearParameterList()
 {
   this->parameterList.clear();
 }
 
-ls::std::core::type::event_id ls::std::event::Event::getId()
+event_id Event::getId()
 {
   return this->id;
 }
 
-ls::std::core::type::event_parameter_list ls::std::event::Event::getParameterList()
+event_parameter_list Event::getParameterList()
 {
   return this->parameterList;
 }
 
-bool ls::std::event::Event::removeParameter(const ls::std::core::type::event_parameter_id &_id)
+bool Event::removeParameter(const event_parameter_id &_id)
 {
   return this->parameterList.erase(_id) == 1;
 }
 
-void ls::std::event::Event::setId(const ls::std::core::type::event_id &_id)
+void Event::setId(const event_id &_id)
 {
   this->_assignId(_id);
 }
 
-void ls::std::event::Event::_assignId(const ls::std::core::type::event_id &_id)
+void Event::_assignId(const event_id &_id)
 {
-  ls::std::core::EmptyStringArgumentEvaluator{_id, "event id is empty!"}.evaluate();
+  EmptyStringArgumentEvaluator{_id, "event id is empty!"}.evaluate();
   this->id = _id;
 }
 
-bool ls::std::event::Event::_hasParameter(const ls::std::core::type::event_id &_id)
+bool Event::_hasParameter(const event_id &_id)
 {
   return this->parameterList.find(_id) != this->parameterList.end();
 }

+ 11 - 6
source/ls-std/event/EventHandler.cpp

@@ -3,27 +3,32 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2023-02-22
+ * Changed:         2023-02-23
  *
  * */
 
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
 #include <ls-std/event/EventHandler.hpp>
 
-ls::std::event::EventHandler::EventHandler(const ls::std::core::type::event_id &_id) : ls::std::event::Narrator()
+using ls::std::core::EmptyStringArgumentEvaluator;
+using ls::std::core::type::event_id;
+using ls::std::event::EventHandler;
+using ls::std::event::Narrator;
+
+EventHandler::EventHandler(const event_id &_id) : Narrator()
 {
   this->_assignId(_id);
 }
 
-ls::std::event::EventHandler::~EventHandler() noexcept = default;
+EventHandler::~EventHandler() noexcept = default;
 
-ls::std::core::type::event_id ls::std::event::EventHandler::getId()
+event_id EventHandler::getId()
 {
   return this->id;
 }
 
-void ls::std::event::EventHandler::_assignId(const ls::std::core::type::event_id &_id)
+void EventHandler::_assignId(const event_id &_id)
 {
-  ls::std::core::EmptyStringArgumentEvaluator{_id, "event manager id is empty!"}.evaluate();
+  EmptyStringArgumentEvaluator{_id, "event manager id is empty!"}.evaluate();
   this->id = _id;
 }

+ 35 - 21
source/ls-std/event/EventManager.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2023-02-22
+ * Changed:         2023-02-23
  *
  * */
 
@@ -13,15 +13,29 @@
 #include <ls-std/core/exception/EventNotSubscribedException.hpp>
 #include <ls-std/event/EventManager.hpp>
 
-ls::std::event::EventManager::EventManager() : ls::std::core::Class("EventManager")
+using ls::std::core::Class;
+using ls::std::core::EmptyStringArgumentEvaluator;
+using ls::std::core::EventNotHandledException;
+using ls::std::core::EventNotSubscribedException;
+using ls::std::core::NullPointerArgumentEvaluator;
+using ls::std::core::interface_type::IListener;
+using ls::std::core::type::event_id;
+using ls::std::event::Event;
+using ls::std::event::EventHandler;
+using ls::std::event::EventManager;
+using std::make_pair;
+using std::pair;
+using std::shared_ptr;
+
+EventManager::EventManager() : Class("EventManager")
 {}
 
-ls::std::event::EventManager::~EventManager() noexcept = default;
+EventManager::~EventManager() noexcept = default;
 
-void ls::std::event::EventManager::subscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
+void EventManager::subscribe(const event_id &_id, const shared_ptr<IListener> &_listener)
 {
-  ls::std::core::EmptyStringArgumentEvaluator{_id, "event id is empty and can not be subscribed!"}.evaluate();
-  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for subscribe attempt is null!"}.evaluate();
+  EmptyStringArgumentEvaluator{_id, "event id is empty and can not be subscribed!"}.evaluate();
+  NullPointerArgumentEvaluator{_listener, "listener reference for subscribe attempt is null!"}.evaluate();
 
   if (this->_hasEventHandler(_id))
   {
@@ -29,14 +43,14 @@ void ls::std::event::EventManager::subscribe(const ls::std::core::type::event_id
   }
   else
   {
-    throw ls::std::core::EventNotSubscribedException{"id: " + _id};
+    throw EventNotSubscribedException{"id: " + _id};
   }
 }
 
-void ls::std::event::EventManager::unsubscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
+void EventManager::unsubscribe(const event_id &_id, const shared_ptr<IListener> &_listener)
 {
-  ls::std::core::EmptyStringArgumentEvaluator{_id, "event id is empty and can not be unsubscribed!"}.evaluate();
-  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for unsubscribe attempt is null!"}.evaluate();
+  EmptyStringArgumentEvaluator{_id, "event id is empty and can not be unsubscribed!"}.evaluate();
+  NullPointerArgumentEvaluator{_listener, "listener reference for unsubscribe attempt is null!"}.evaluate();
 
   if (this->_hasEventHandler(_id))
   {
@@ -44,21 +58,21 @@ void ls::std::event::EventManager::unsubscribe(const ls::std::core::type::event_
   }
 }
 
-bool ls::std::event::EventManager::addEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler)
+bool EventManager::addEventHandler(const shared_ptr<EventHandler> &_eventHandler)
 {
   bool wasAdded{};
-  ls::std::core::NullPointerArgumentEvaluator{_eventHandler, "event handler reference for add attempt is null!"}.evaluate();
+  NullPointerArgumentEvaluator{_eventHandler, "event handler reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasEventHandler(_eventHandler->getId()))
   {
-    ::std::pair<ls::std::core::type::event_id, ::std::shared_ptr<ls::std::event::EventHandler>> element = ::std::make_pair(_eventHandler->getId(), _eventHandler);
+    pair<event_id, shared_ptr<EventHandler>> element = make_pair(_eventHandler->getId(), _eventHandler);
     wasAdded = this->eventHandlers.insert(element).second;
   }
 
   return wasAdded;
 }
 
-void ls::std::event::EventManager::fire(ls::std::event::Event _event)
+void EventManager::fire(Event _event)
 {
   if (this->_hasEventHandler(_event.getId()))
   {
@@ -66,28 +80,28 @@ void ls::std::event::EventManager::fire(ls::std::event::Event _event)
   }
   else
   {
-    throw ls::std::core::EventNotHandledException{"id: " + _event.getId()};
+    throw EventNotHandledException{"id: " + _event.getId()};
   }
 }
 
-bool ls::std::event::EventManager::hasEventHandler(const ls::std::core::type::event_id &_id)
+bool EventManager::hasEventHandler(const event_id &_id)
 {
-  ls::std::core::EmptyStringArgumentEvaluator{_id, "event id is empty and can not be passed!"}.evaluate();
+  EmptyStringArgumentEvaluator{_id, "event id is empty and can not be passed!"}.evaluate();
   return this->_hasEventHandler(_id);
 }
 
-bool ls::std::event::EventManager::removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler)
+bool EventManager::removeEventHandler(const shared_ptr<EventHandler> &_eventHandler)
 {
-  ls::std::core::NullPointerArgumentEvaluator{_eventHandler, "event handler reference for remove attempt is null!"}.evaluate();
+  NullPointerArgumentEvaluator{_eventHandler, "event handler reference for remove attempt is null!"}.evaluate();
   return this->_removeEventHandler(_eventHandler);
 }
 
-bool ls::std::event::EventManager::_hasEventHandler(const ls::std::core::type::event_id &_id)
+bool EventManager::_hasEventHandler(const event_id &_id)
 {
   return this->eventHandlers.find(_id) != this->eventHandlers.end();
 }
 
-bool ls::std::event::EventManager::_removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler)
+bool EventManager::_removeEventHandler(const shared_ptr<EventHandler> &_eventHandler)
 {
   return this->eventHandlers.erase(_eventHandler->getId()) == 1;
 }

+ 20 - 12
source/ls-std/event/Narrator.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2023-02-22
+ * Changed:         2023-02-23
  *
  * */
 
@@ -11,15 +11,23 @@
 #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/event/Narrator.hpp>
 
-ls::std::event::Narrator::Narrator() : ls::std::core::Class("Narrator")
+using ls::std::core::Class;
+using ls::std::core::NullPointerArgumentEvaluator;
+using ls::std::core::interface_type::IListener;
+using ls::std::event::Narrator;
+using std::find;
+using std::list;
+using std::shared_ptr;
+
+Narrator::Narrator() : Class("Narrator")
 {}
 
-ls::std::event::Narrator::~Narrator() noexcept = default;
+Narrator::~Narrator() noexcept = default;
 
-bool ls::std::event::Narrator::addListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
+bool Narrator::addListener(const shared_ptr<IListener> &_listener)
 {
   bool wasAdded{};
-  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for add attempt is null!"}.evaluate();
+  NullPointerArgumentEvaluator{_listener, "listener reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasListener(_listener))
   {
@@ -30,20 +38,20 @@ bool ls::std::event::Narrator::addListener(const ::std::shared_ptr<ls::std::core
   return wasAdded;
 }
 
-void ls::std::event::Narrator::clear()
+void Narrator::clear()
 {
   this->listeners.clear();
 }
 
-::std::list<::std::shared_ptr<ls::std::core::interface_type::IListener>> ls::std::event::Narrator::getListeners()
+list<shared_ptr<IListener>> Narrator::getListeners()
 {
   return this->listeners;
 }
 
-bool ls::std::event::Narrator::removeListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
+bool Narrator::removeListener(const shared_ptr<IListener> &_listener)
 {
   bool wasRemoved{};
-  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for remove attempt is null!"}.evaluate();
+  NullPointerArgumentEvaluator{_listener, "listener reference for remove attempt is null!"}.evaluate();
 
   if (this->_hasListener(_listener))
   {
@@ -54,7 +62,7 @@ bool ls::std::event::Narrator::removeListener(const ::std::shared_ptr<ls::std::c
   return wasRemoved;
 }
 
-void ls::std::event::Narrator::tell(const ls::std::core::Class &_info)
+void Narrator::tell(const Class &_info)
 {
   for (const auto &listener : this->listeners)
   {
@@ -62,7 +70,7 @@ void ls::std::event::Narrator::tell(const ls::std::core::Class &_info)
   }
 }
 
-bool ls::std::event::Narrator::_hasListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
+bool Narrator::_hasListener(const shared_ptr<IListener> &_listener)
 {
-  return ::std::find(this->listeners.begin(), this->listeners.end(), _listener) != this->listeners.end();
+  return find(this->listeners.begin(), this->listeners.end(), _listener) != this->listeners.end();
 }

+ 26 - 16
source/ls-std/event/serialization/SerializableJsonEvent.cpp

@@ -3,75 +3,85 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-07
- * Changed:         2023-02-22
+ * Changed:         2023-02-23
  *
  * */
 
 #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/event/serialization/SerializableJsonEvent.hpp>
 
-ls::std::event::SerializableJsonEvent::SerializableJsonEvent(const ::std::shared_ptr<ls::std::event::Event> &_value) : ls::std::core::Class("SerializableJsonEvent")
+using ls::std::core::Class;
+using ls::std::core::NullPointerArgumentEvaluator;
+using ls::std::core::type::byte_field;
+using ls::std::core::type::event_parameter;
+using ls::std::core::type::json;
+using ls::std::event::Event;
+using ls::std::event::SerializableJsonEvent;
+using std::shared_ptr;
+using std::string;
+
+SerializableJsonEvent::SerializableJsonEvent(const shared_ptr<Event> &_value) : Class("SerializableJsonEvent")
 {
   this->_assignValue(_value);
 }
 
-ls::std::event::SerializableJsonEvent::~SerializableJsonEvent() noexcept = default;
+SerializableJsonEvent::~SerializableJsonEvent() noexcept = default;
 
-ls::std::core::type::byte_field ls::std::event::SerializableJsonEvent::marshal()
+byte_field SerializableJsonEvent::marshal()
 {
   this->_update();
   return this->jsonObject.dump();
 }
 
-void ls::std::event::SerializableJsonEvent::unmarshal(const ls::std::core::type::byte_field &_data)
+void SerializableJsonEvent::unmarshal(const byte_field &_data)
 {
-  this->jsonObject = ls::std::core::type::json::parse(_data);
+  this->jsonObject = json::parse(_data);
 
   this->value->setId(this->jsonObject["id"]);
   this->_unmarshalParameterList();
 }
 
-::std::shared_ptr<ls::std::event::Event> ls::std::event::SerializableJsonEvent::getValue()
+shared_ptr<Event> SerializableJsonEvent::getValue()
 {
   return this->value;
 }
 
-void ls::std::event::SerializableJsonEvent::setValue(const ::std::shared_ptr<ls::std::event::Event> &_value)
+void SerializableJsonEvent::setValue(const shared_ptr<Event> &_value)
 {
   this->_assignValue(_value);
 }
 
-void ls::std::event::SerializableJsonEvent::_assignValue(const ::std::shared_ptr<ls::std::event::Event> &_value)
+void SerializableJsonEvent::_assignValue(const shared_ptr<Event> &_value)
 {
-  ls::std::core::NullPointerArgumentEvaluator{_value, "event reference for serialization attempt is null!"}.evaluate();
+  NullPointerArgumentEvaluator{_value, "event reference for serialization attempt is null!"}.evaluate();
   this->value = _value;
 }
 
-void ls::std::event::SerializableJsonEvent::_unmarshalParameterList()
+void SerializableJsonEvent::_unmarshalParameterList()
 {
   this->value->clearParameterList();
 
   for (const auto &parameterJson : this->jsonObject["parameterList"])
   {
-    ls::std::core::type::event_parameter parameter = {parameterJson.at(0), parameterJson.at(1)};
+    event_parameter parameter = {parameterJson.at(0), parameterJson.at(1)};
     this->value->addParameter(parameter);
   }
 }
 
-void ls::std::event::SerializableJsonEvent::_update()
+void SerializableJsonEvent::_update()
 {
   this->jsonObject = {{"id", this->value->getId()}};
 
   this->_updateEventParameterList();
 }
 
-void ls::std::event::SerializableJsonEvent::_updateEventParameterList()
+void SerializableJsonEvent::_updateEventParameterList()
 {
-  ::std::string jsonString{};
+  string jsonString{};
 
   for (const auto &eventParameter : this->value->getParameterList())
   {
-    ls::std::core::type::json parameterJson = {eventParameter.first, eventParameter.second};
+    json parameterJson = {eventParameter.first, eventParameter.second};
     this->jsonObject["parameterList"][eventParameter.first] = parameterJson;
   }
 }