Narrator.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-14
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #include <ls_std/utils/STLUtils.hpp>
  10. #include "../../../include/ls_std/logic/Narrator.hpp"
  11. ls_std::Narrator::Narrator() : ls_std::Class("Narrator")
  12. {}
  13. void ls_std::Narrator::addListener(const std::shared_ptr<ls_std::IListener> &_listener)
  14. {
  15. if (!ls_std::STLUtils::contains(this->listeners, _listener))
  16. {
  17. this->listeners.push_back(_listener);
  18. }
  19. }
  20. void ls_std::Narrator::clear()
  21. {
  22. this->listeners.clear();
  23. }
  24. std::list<std::shared_ptr<ls_std::IListener>> ls_std::Narrator::getListeners()
  25. {
  26. return this->listeners;
  27. }
  28. void ls_std::Narrator::removeListener(const std::shared_ptr<ls_std::IListener> &_listener)
  29. {
  30. if (ls_std::STLUtils::contains(this->listeners, _listener))
  31. {
  32. this->listeners.remove(_listener);
  33. }
  34. }
  35. void ls_std::Narrator::tell(const ls_std::Class &_info)
  36. {
  37. for (const auto &listener : this->listeners)
  38. {
  39. listener->listen(_info);
  40. }
  41. }