SectionPairRowListValue.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-05-22
  7. *
  8. * */
  9. #include <ls-std/core/ConditionalFunctionExecutor.hpp>
  10. #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
  11. #include <ls-std/core/evaluator/IndexOutOfBoundsEvaluator.hpp>
  12. #include <ls-std/io/section-pair/evaluator/SectionPairValueArgumentEvaluator.hpp>
  13. #include <ls-std/io/section-pair/model/SectionPairRowListValue.hpp>
  14. #include <ls-std/io/section-pair/serialization/SerializableSectionPairRowListValue.hpp>
  15. using ls::std::core::Class;
  16. using ls::std::core::ConditionalFunctionExecutor;
  17. using ls::std::core::EmptyStringArgumentEvaluator;
  18. using ls::std::core::IndexOutOfBoundsEvaluator;
  19. using ls::std::core::type::byte_field;
  20. using ls::std::io::section_pair_row_value;
  21. using ls::std::io::SectionPairRowEnumType;
  22. using ls::std::io::SectionPairRowListValue;
  23. using ls::std::io::SectionPairRowValue;
  24. using ls::std::io::SectionPairValueArgumentEvaluator;
  25. using ls::std::io::SerializableSectionPairParameter;
  26. using ls::std::io::SerializableSectionPairRowListValue;
  27. using std::list;
  28. using std::make_shared;
  29. SectionPairRowListValue::SectionPairRowListValue() : Class("SectionPairRowListValue"), SectionPairRowValue(SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE)
  30. {}
  31. SectionPairRowListValue::~SectionPairRowListValue() noexcept = default;
  32. void SectionPairRowListValue::add(const section_pair_row_value &_value)
  33. {
  34. EmptyStringArgumentEvaluator{_value}.evaluate();
  35. SectionPairValueArgumentEvaluator{_value}.evaluate();
  36. this->values.push_back(_value);
  37. }
  38. void SectionPairRowListValue::clear()
  39. {
  40. this->values.clear();
  41. }
  42. section_pair_row_value SectionPairRowListValue::get(size_t _index) const
  43. {
  44. IndexOutOfBoundsEvaluator(_index, this->values.size()).evaluate();
  45. section_pair_row_value value{};
  46. size_t index{};
  47. for (const auto &_value : this->values)
  48. {
  49. if (index == _index)
  50. {
  51. value = _value;
  52. break;
  53. }
  54. ++index;
  55. }
  56. return value;
  57. }
  58. list<section_pair_row_value> SectionPairRowListValue::getList() const
  59. {
  60. return this->values;
  61. }
  62. size_t SectionPairRowListValue::getSize() const
  63. {
  64. return this->values.size();
  65. }
  66. SectionPairRowEnumType SectionPairRowListValue::getType()
  67. {
  68. return this->_getType();
  69. }
  70. byte_field SectionPairRowListValue::marshal()
  71. {
  72. ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  73. return this->serializable->marshal();
  74. }
  75. void SectionPairRowListValue::unmarshal(const byte_field &_data)
  76. {
  77. ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  78. this->serializable->unmarshal(_data);
  79. }
  80. void SectionPairRowListValue::_createSerializable()
  81. {
  82. SerializableSectionPairParameter parameter{};
  83. parameter.setValue(shared_from_this());
  84. if (!this->_getReservedNewLine().empty())
  85. {
  86. parameter.setNewLine(this->_getReservedNewLine());
  87. }
  88. this->serializable = make_shared<SerializableSectionPairRowListValue>(parameter);
  89. }