SectionPairRow.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  6. * Changed: 2023-02-13
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
  10. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  11. #include <ls-std/core/evaluator/NullPointerEvaluator.hpp>
  12. #include <ls-std/core/exception/IllegalArgumentException.hpp>
  13. #include <ls-std/io/section-pair/evaluator/SectionPairIdentifierArgumentEvaluator.hpp>
  14. #include <ls-std/io/section-pair/model/SectionPairRow.hpp>
  15. #include <ls-std/io/section-pair/model/SectionPairRowListValue.hpp>
  16. #include <ls-std/io/section-pair/model/SectionPairRowSingleValue.hpp>
  17. ls::std::io::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key, const ls::std::io::SectionPairRowEnumType &_type) : ls::std::core::Class("SectionPairRow")
  18. {
  19. this->_setKey(_key);
  20. this->_initValue(_type);
  21. }
  22. ls::std::io::SectionPairRow::~SectionPairRow() = default;
  23. ls::std::io::section_pair_row_value ls::std::io::SectionPairRow::getKey()
  24. {
  25. return this->key;
  26. }
  27. ::std::shared_ptr<ls::std::io::SectionPairRowValue> ls::std::io::SectionPairRow::getValue()
  28. {
  29. return this->value;
  30. }
  31. bool ls::std::io::SectionPairRow::isList()
  32. {
  33. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE;
  34. }
  35. bool ls::std::io::SectionPairRow::isSingleValue()
  36. {
  37. return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE;
  38. }
  39. ls::std::core::type::byte_field ls::std::io::SectionPairRow::marshal()
  40. {
  41. ::std::string message = "member \"serializable\" for marshal attempt is null!";
  42. ls::std::core::NullPointerEvaluator{::std::reinterpret_pointer_cast<void>(this->serializable), message}.evaluate();
  43. return this->serializable->marshal();
  44. }
  45. void ls::std::io::SectionPairRow::setKey(const ls::std::io::section_pair_identifier &_key)
  46. {
  47. this->_setKey(_key);
  48. }
  49. void ls::std::io::SectionPairRow::setSerializable(const ::std::shared_ptr<ls::std::core::interface_type::ISerializable> &_serializable)
  50. {
  51. ::std::string message = this->getClassName() + ": argument \"_serializable\" is null!";
  52. ls::std::core::NullPointerArgumentEvaluator{::std::reinterpret_pointer_cast<void>(_serializable), message}.evaluate();
  53. this->serializable = _serializable;
  54. }
  55. void ls::std::io::SectionPairRow::unmarshal(const ls::std::core::type::byte_field &_data)
  56. {
  57. ::std::string message = this->getClassName() + ": member \"serializable\" for unmarshal attempt is null!";
  58. ls::std::core::NullPointerEvaluator{::std::reinterpret_pointer_cast<void>(this->serializable), message}.evaluate();
  59. this->serializable->unmarshal(_data);
  60. }
  61. void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEnumType &_type)
  62. {
  63. switch (_type)
  64. {
  65. case SECTION_PAIR_ROW_NOT_IMPLEMENTED:
  66. {
  67. throw ls::std::core::IllegalArgumentException{this->getClassName() + ": default row enum type can not be set!"};
  68. }
  69. case SECTION_PAIR_ROW_LIST_VALUE:
  70. {
  71. this->value = ::std::make_shared<ls::std::io::SectionPairRowListValue>();
  72. }
  73. break;
  74. case SECTION_PAIR_ROW_SINGLE_VALUE:
  75. {
  76. this->value = ::std::make_shared<ls::std::io::SectionPairRowSingleValue>("empty");
  77. }
  78. break;
  79. }
  80. }
  81. void ls::std::io::SectionPairRow::_setKey(const ls::std::io::section_pair_identifier &_key)
  82. {
  83. ls::std::core::EmptyStringArgumentEvaluator{_key, this->getClassName() + ": passed key identifier is empty!"}.evaluate();
  84. ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, this->getClassName() + ": section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
  85. this->key = _key;
  86. }