SectionPairRowListValue.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-02-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. ls::std::io::SectionPairRowListValue::SectionPairRowListValue() : ls::std::core::Class("SectionPairRowListValue"), ls::std::io::SectionPairRowValue(ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE)
  16. {}
  17. ls::std::io::SectionPairRowListValue::~SectionPairRowListValue() = default;
  18. void ls::std::io::SectionPairRowListValue::add(const ls::std::io::section_pair_row_value &_value)
  19. {
  20. ls::std::core::EmptyStringArgumentEvaluator{_value}.evaluate();
  21. ls::std::io::SectionPairValueArgumentEvaluator{_value}.evaluate();
  22. this->values.push_back(_value);
  23. }
  24. void ls::std::io::SectionPairRowListValue::clear()
  25. {
  26. this->values.clear();
  27. }
  28. ls::std::io::section_pair_row_value ls::std::io::SectionPairRowListValue::get(size_t _index)
  29. {
  30. ls::std::core::IndexOutOfBoundsEvaluator(_index, this->values.size()).evaluate();
  31. ls::std::io::section_pair_row_value value{};
  32. size_t index{};
  33. for (const auto &_value : this->values)
  34. {
  35. if (index == _index)
  36. {
  37. value = _value;
  38. break;
  39. }
  40. ++index;
  41. }
  42. return value;
  43. }
  44. ::std::list<ls::std::io::section_pair_row_value> ls::std::io::SectionPairRowListValue::getList()
  45. {
  46. return this->values;
  47. }
  48. size_t ls::std::io::SectionPairRowListValue::getSize()
  49. {
  50. return this->values.size();
  51. }
  52. ls::std::io::SectionPairRowEnumType ls::std::io::SectionPairRowListValue::getType()
  53. {
  54. return this->type;
  55. }
  56. ls::std::core::type::byte_field ls::std::io::SectionPairRowListValue::marshal()
  57. {
  58. ls::std::core::ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  59. return this->serializable->marshal();
  60. }
  61. void ls::std::io::SectionPairRowListValue::unmarshal(const ls::std::core::type::byte_field &_data)
  62. {
  63. ls::std::core::ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  64. this->serializable->unmarshal(_data);
  65. }
  66. void ls::std::io::SectionPairRowListValue::_createSerializable()
  67. {
  68. ls::std::io::SerializableSectionPairParameter parameter{};
  69. parameter.setValue(shared_from_this());
  70. if (!this->reservedNewLine.empty())
  71. {
  72. parameter.setNewLine(this->reservedNewLine);
  73. }
  74. this->serializable = ::std::make_shared<ls::std::io::SerializableSectionPairRowListValue>(parameter);
  75. }