123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-11-14
- * Changed: 2023-02-04
- *
- * */
- #include <ls-std/core/exception/IllegalArgumentException.hpp>
- #include <ls-std/core/utils/StlUtils.hpp>
- #include <ls-std/event/Narrator.hpp>
- ls::std::event::Narrator::Narrator() : ls::std::core::Class("Narrator")
- {}
- ls::std::event::Narrator::~Narrator() = default;
- bool ls::std::event::Narrator::addListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
- {
- bool wasAdded{};
- if (_listener == nullptr)
- {
- throw ls::std::core::IllegalArgumentException{};
- }
- else
- {
- if (!ls::std::core::StlUtils::contains(this->listeners, _listener))
- {
- this->listeners.push_back(_listener);
- wasAdded = true;
- }
- }
- return wasAdded;
- }
- void ls::std::event::Narrator::clear()
- {
- this->listeners.clear();
- }
- ::std::list<::std::shared_ptr<ls::std::core::interface_type::IListener>> ls::std::event::Narrator::getListeners()
- {
- return this->listeners;
- }
- bool ls::std::event::Narrator::removeListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
- {
- bool wasRemoved{};
- if (_listener == nullptr)
- {
- throw ls::std::core::IllegalArgumentException{};
- }
- else
- {
- if (ls::std::core::StlUtils::contains(this->listeners, _listener))
- {
- this->listeners.remove(_listener);
- wasRemoved = true;
- }
- }
- return wasRemoved;
- }
- void ls::std::event::Narrator::tell(const ls::std::core::Class &_info)
- {
- for (const auto &listener : this->listeners)
- {
- listener->listen(_info);
- }
- }
|