Narrator.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-14
  6. * Changed: 2020-11-28
  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. this->listeners.push_back(_listener);
  17. }
  18. }
  19. void ls_std::Narrator::clear()
  20. {
  21. this->listeners.clear();
  22. }
  23. std::list<std::shared_ptr<ls_std::IListener>> ls_std::Narrator::getListeners()
  24. {
  25. return this->listeners;
  26. }
  27. void ls_std::Narrator::removeListener(const std::shared_ptr<ls_std::IListener>& _listener)
  28. {
  29. if(ls_std::STLUtils::contains(this->listeners, _listener)) {
  30. this->listeners.remove(_listener);
  31. }
  32. }
  33. void ls_std::Narrator::tell(const ls_std::Class &_info)
  34. {
  35. for(const auto& listener : this->listeners) {
  36. listener->listen(_info);
  37. }
  38. }