SectionPairRowSingleValue.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/io/NewLine.hpp>
  13. #include <ls-std/io/section-pair/evaluator/SectionPairValueArgumentEvaluator.hpp>
  14. #include <ls-std/io/section-pair/model/SectionPairRowSingleValue.hpp>
  15. #include <ls-std/io/section-pair/serialization/SerializableSectionPairRowSingleValue.hpp>
  16. using ls::standard::core::Class;
  17. using ls::standard::core::ConditionalFunctionExecutor;
  18. using ls::standard::core::EmptyStringArgumentEvaluator;
  19. using ls::standard::core::type::byte_field;
  20. using ls::standard::io::NewLine;
  21. using ls::standard::io::section_pair_row_value;
  22. using ls::standard::io::SectionPairRowEnumType;
  23. using ls::standard::io::SectionPairRowSingleValue;
  24. using ls::standard::io::SectionPairRowValue;
  25. using ls::standard::io::SectionPairValueArgumentEvaluator;
  26. using ls::standard::io::SerializableSectionPairRowSingleValue;
  27. using std::make_shared;
  28. using std::string;
  29. SectionPairRowSingleValue::SectionPairRowSingleValue(const section_pair_row_value &_value) : Class("SectionPairRowSingleValue"), SectionPairRowValue(SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE)
  30. {
  31. this->_set(_value);
  32. }
  33. SectionPairRowSingleValue::~SectionPairRowSingleValue() noexcept = default;
  34. section_pair_row_value SectionPairRowSingleValue::get() const
  35. {
  36. return this->value;
  37. }
  38. SectionPairRowEnumType SectionPairRowSingleValue::getType()
  39. {
  40. return this->_getType();
  41. }
  42. byte_field SectionPairRowSingleValue::marshal()
  43. {
  44. ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  45. return this->serializable->marshal();
  46. }
  47. void SectionPairRowSingleValue::set(const section_pair_row_value &_value)
  48. {
  49. this->_set(_value);
  50. }
  51. void SectionPairRowSingleValue::unmarshal(const byte_field &_data)
  52. {
  53. ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  54. this->serializable->unmarshal(_data);
  55. }
  56. void SectionPairRowSingleValue::_createSerializable()
  57. {
  58. SerializableSectionPairParameter parameter{};
  59. parameter.setValue(shared_from_this());
  60. if (!this->_getReservedNewLine().empty())
  61. {
  62. parameter.setNewLine(this->_getReservedNewLine());
  63. }
  64. this->serializable = make_shared<SerializableSectionPairRowSingleValue>(parameter);
  65. }
  66. void SectionPairRowSingleValue::_set(const section_pair_row_value &_value)
  67. {
  68. EmptyStringArgumentEvaluator{_value}.evaluate();
  69. SectionPairValueArgumentEvaluator(_value).evaluate();
  70. const string newLine = this->_getReservedNewLine().empty() ? NewLine::get() : this->_getReservedNewLine();
  71. this->value = _value;
  72. if (this->value.find(newLine) != string::npos)
  73. {
  74. this->value.replace(this->value.find(newLine), newLine.size(), "");
  75. }
  76. }