Event.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-26
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
  10. #include <ls-std/event/Event.hpp>
  11. using ls::std::core::Class;
  12. using ls::std::core::EmptyStringArgumentEvaluator;
  13. using ls::std::core::type::event_id;
  14. using ls::std::core::type::event_parameter;
  15. using ls::std::core::type::event_parameter_id;
  16. using ls::std::core::type::event_parameter_list;
  17. using ls::std::event::Event;
  18. Event::Event(const event_id &_id) : Class("Event")
  19. {
  20. this->_assignId(_id);
  21. }
  22. Event::~Event() noexcept = default;
  23. bool Event::addParameter(const event_parameter &_eventParameter)
  24. {
  25. bool wasAdded{};
  26. if (!this->_hasParameter(_eventParameter.first))
  27. {
  28. wasAdded = this->parameterList.insert(_eventParameter).second;
  29. }
  30. return wasAdded;
  31. }
  32. void Event::clearParameterList()
  33. {
  34. this->parameterList.clear();
  35. }
  36. event_id Event::getId()
  37. {
  38. return this->id;
  39. }
  40. event_parameter_list Event::getParameterList()
  41. {
  42. return this->parameterList;
  43. }
  44. bool Event::removeParameter(const event_parameter_id &_id)
  45. {
  46. return this->parameterList.erase(_id) == 1;
  47. }
  48. void Event::setId(const event_id &_id)
  49. {
  50. this->_assignId(_id);
  51. }
  52. void Event::_assignId(const event_id &_id)
  53. {
  54. EmptyStringArgumentEvaluator{_id, "event id is empty!"}.evaluate();
  55. this->id = _id;
  56. }
  57. bool Event::_hasParameter(const event_id &_id)
  58. {
  59. return this->parameterList.find(_id) != this->parameterList.end();
  60. }