GossipNewsAgency.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "GossipNewsAgency.hpp"
  10. ls_std_test::GossipNewsAgency::GossipNewsAgency() : ls_std_test::NewsAgency("GossipNewsAgency")
  11. {}
  12. void ls_std_test::GossipNewsAgency::clear()
  13. {
  14. this->news.clear();
  15. }
  16. std::string ls_std_test::GossipNewsAgency::getNews()
  17. {
  18. return this->news;
  19. }
  20. void ls_std_test::GossipNewsAgency::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. if(event.getId() == "GossipNewsEvent") {
  27. this->news = this->getName() + ": " + event.getParameterList().at("news");
  28. }
  29. }
  30. void ls_std_test::GossipNewsAgency::subscribe(const ls_std::event_id &_id)
  31. {
  32. // TODO: check event handler existence
  33. this->eventHandlers.at(_id)->addListener(this->shared_from_this());
  34. }
  35. void ls_std_test::GossipNewsAgency::unsubscribe(const ls_std::event_id &_id)
  36. {
  37. // TODO: check event handler existence
  38. this->eventHandlers.at(_id)->removeListener(this->shared_from_this());
  39. }
  40. void ls_std_test::GossipNewsAgency::addEventHandler(const std::shared_ptr<ls_std::EventHandler> &_eventHandler)
  41. {
  42. // TODO: check event handler existence
  43. std::pair<ls_std::event_id, std::shared_ptr<ls_std::EventHandler>> entry = std::make_pair(_eventHandler->getId(), _eventHandler);
  44. this->eventHandlers.insert(entry);
  45. }