SerializableSectionPairRowSingleValue.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-11
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
  10. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  11. #include <ls-std/io/section-pair/model/SectionPairRowSingleValue.hpp>
  12. #include <ls-std/io/section-pair/serialization/SerializableSectionPairRowSingleValue.hpp>
  13. using ls::std::core::Class;
  14. using ls::std::core::EmptyStringArgumentEvaluator;
  15. using ls::std::core::NullPointerArgumentEvaluator;
  16. using ls::std::core::type::byte_field;
  17. using ls::std::io::SectionPairRowSingleValue;
  18. using ls::std::io::SerializableSectionPairParameter;
  19. using ls::std::io::SerializableSectionPairRowSingleValue;
  20. using std::dynamic_pointer_cast;
  21. using std::shared_ptr;
  22. using std::string;
  23. SerializableSectionPairRowSingleValue::SerializableSectionPairRowSingleValue(const SerializableSectionPairParameter &_parameter) : Class("SerializableSectionPairRowSingleValue")
  24. {
  25. string message = this->getClassName() + ": model reference is null!";
  26. NullPointerArgumentEvaluator{_parameter.getValue(), message}.evaluate();
  27. this->parameter = _parameter;
  28. }
  29. SerializableSectionPairRowSingleValue::~SerializableSectionPairRowSingleValue() noexcept = default;
  30. shared_ptr<Class> SerializableSectionPairRowSingleValue::getValue()
  31. {
  32. return this->parameter.getValue();
  33. }
  34. byte_field SerializableSectionPairRowSingleValue::marshal()
  35. {
  36. return dynamic_pointer_cast<SectionPairRowSingleValue>(this->parameter.getValue())->get() + this->parameter.getNewLine();
  37. }
  38. void SerializableSectionPairRowSingleValue::unmarshal(const byte_field &_data)
  39. {
  40. EmptyStringArgumentEvaluator{_data}.evaluate();
  41. dynamic_pointer_cast<SectionPairRowSingleValue>(this->parameter.getValue())->set(_data);
  42. }