SectionPairRowSingleValue.cpp 2.6 KB

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