DailyNewsAgency.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-27
  6. * Changed: 2020-11-28
  7. *
  8. * */
  9. #include "DailyNewsAgency.hpp"
  10. ls_std_test::DailyNewsAgency::DailyNewsAgency() : ls_std_test::NewsAgency("DailyNewsAgency")
  11. {}
  12. void ls_std_test::DailyNewsAgency::clear()
  13. {
  14. this->news.clear();
  15. }
  16. std::string ls_std_test::DailyNewsAgency::getNews()
  17. {
  18. return this->news;
  19. }
  20. void ls_std_test::DailyNewsAgency::listen(const ls_std::Class &_info)
  21. {
  22. ls_std::Event event = dynamic_cast<const ls_std::Event&>(_info);
  23. if(event.getId() == "SeriousNewsEvent") {
  24. this->news = this->getName() + ": " + event.getParameterList().at("news");
  25. }
  26. }
  27. void ls_std_test::DailyNewsAgency::subscribe(const ls_std::event_id &_id)
  28. {
  29. // TODO: check event handler existence
  30. // std::shared_ptr<ls_std_test::DailyNewsAgency> listener = this->shared_from_this();
  31. this->eventHandlers.at(_id)->addListener(this->shared_from_this());
  32. }
  33. void ls_std_test::DailyNewsAgency::unsubscribe(const ls_std::event_id &_id)
  34. {
  35. // TODO: check event handler existence
  36. this->eventHandlers.at(_id)->removeListener(this->shared_from_this());
  37. }
  38. void ls_std_test::DailyNewsAgency::addEventHandler(const std::shared_ptr<ls_std::EventHandler> &_eventHandler)
  39. {
  40. // TODO: check event handler existence
  41. std::pair<ls_std::event_id, std::shared_ptr<ls_std::EventHandler>> entry = std::make_pair(_eventHandler->getId(), _eventHandler);
  42. this->eventHandlers.insert(entry);
  43. }