SectionPairRowSingleValue.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-05-22
  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. using ls::std::core::Class;
  16. using ls::std::core::ConditionalFunctionExecutor;
  17. using ls::std::core::EmptyStringArgumentEvaluator;
  18. using ls::std::core::type::byte_field;
  19. using ls::std::io::NewLine;
  20. using ls::std::io::section_pair_row_value;
  21. using ls::std::io::SectionPairRowEnumType;
  22. using ls::std::io::SectionPairRowSingleValue;
  23. using ls::std::io::SectionPairRowValue;
  24. using ls::std::io::SectionPairValueArgumentEvaluator;
  25. using ls::std::io::SerializableSectionPairRowSingleValue;
  26. using std::make_shared;
  27. using std::string;
  28. SectionPairRowSingleValue::SectionPairRowSingleValue(const section_pair_row_value &_value) : Class("SectionPairRowSingleValue"), SectionPairRowValue(SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE)
  29. {
  30. this->_set(_value);
  31. }
  32. SectionPairRowSingleValue::~SectionPairRowSingleValue() noexcept = default;
  33. section_pair_row_value SectionPairRowSingleValue::get() const
  34. {
  35. return this->value;
  36. }
  37. SectionPairRowEnumType SectionPairRowSingleValue::getType()
  38. {
  39. return this->_getType();
  40. }
  41. byte_field SectionPairRowSingleValue::marshal()
  42. {
  43. ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  44. return this->serializable->marshal();
  45. }
  46. void SectionPairRowSingleValue::set(const section_pair_row_value &_value)
  47. {
  48. this->_set(_value);
  49. }
  50. void SectionPairRowSingleValue::unmarshal(const byte_field &_data)
  51. {
  52. ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
  53. this->serializable->unmarshal(_data);
  54. }
  55. void SectionPairRowSingleValue::_createSerializable()
  56. {
  57. SerializableSectionPairParameter parameter{};
  58. parameter.setValue(shared_from_this());
  59. if (!this->_getReservedNewLine().empty())
  60. {
  61. parameter.setNewLine(this->_getReservedNewLine());
  62. }
  63. this->serializable = make_shared<SerializableSectionPairRowSingleValue>(parameter);
  64. }
  65. void SectionPairRowSingleValue::_set(const section_pair_row_value &_value)
  66. {
  67. EmptyStringArgumentEvaluator{_value}.evaluate();
  68. SectionPairValueArgumentEvaluator(_value).evaluate();
  69. string newLine = this->_getReservedNewLine().empty() ? NewLine::get() : this->_getReservedNewLine();
  70. this->value = _value;
  71. if (this->value.find(newLine) != string::npos)
  72. {
  73. this->value.replace(this->value.find(newLine), newLine.size(), "");
  74. }
  75. }