SectionPairRowListValue.cpp 3.1 KB

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