Event.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-26
  6. * Changed: 2020-12-23
  7. *
  8. * */
  9. #include <ls_std/event/Event.hpp>
  10. #include <ls_std/exception/IllegalArgumentException.hpp>
  11. ls_std::Event::Event(const ls_std::event_id& _id) : ls_std::Class("Event")
  12. {
  13. this->_assignId(_id);
  14. }
  15. ls_std::byte_field ls_std::Event::marshal()
  16. {
  17. ls_std::byte_field data {};
  18. if(this->serializable != nullptr) {
  19. data = this->serializable->marshal();
  20. }
  21. return data;
  22. }
  23. void ls_std::Event::unmarshal(const ls_std::byte_field &_data)
  24. {
  25. if(this->serializable != nullptr) {
  26. this->serializable->unmarshal(_data);
  27. }
  28. }
  29. void ls_std::Event::addParameter(const ls_std::event_parameter &_eventParameter)
  30. {
  31. if(!this->_hasParameter(_eventParameter.first)) {
  32. this->parameterList.insert(_eventParameter);
  33. }
  34. }
  35. void ls_std::Event::clearParameterList()
  36. {
  37. this->parameterList.clear();
  38. }
  39. ls_std::event_id ls_std::Event::getId()
  40. {
  41. return this->id;
  42. }
  43. ls_std::event_parameter_list ls_std::Event::getParameterList()
  44. {
  45. return this->parameterList;
  46. }
  47. void ls_std::Event::removeParameter(const ls_std::event_parameter_id &_id)
  48. {
  49. if(this->_hasParameter(_id)) {
  50. this->parameterList.erase(_id);
  51. }
  52. }
  53. void ls_std::Event::setId(const ls_std::event_id& _id)
  54. {
  55. this->_assignId(_id);
  56. }
  57. void ls_std::Event::_assignId(const ls_std::event_id& _id)
  58. {
  59. if(_id.empty()) {
  60. throw ls_std::IllegalArgumentException {};
  61. }
  62. this->id = _id;
  63. }
  64. bool ls_std::Event::_hasParameter(const ls_std::event_id &_id)
  65. {
  66. return this->parameterList.find(_id) != this->parameterList.end();
  67. }
  68. void ls_std::Event::setSerializable(std::shared_ptr<ISerializable> _serializable)
  69. {
  70. this->serializable = std::move(_serializable);
  71. }