SectionPairRowListValue.cpp 2.8 KB

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