SectionPairRowSingleValue.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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-15
  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/SectionPairRowValueArgumentEvaluator.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. this->serializable = ::std::make_shared<ls::std::io::SerializableSectionPairRowSingleValue>(shared_from_this());
  45. }
  46. void ls::std::io::SectionPairRowSingleValue::_set(const ls::std::io::section_pair_row_value &_value)
  47. {
  48. ls::std::core::EmptyStringArgumentEvaluator{_value}.evaluate();
  49. ls::std::io::SectionPairRowValueArgumentEvaluator(_value, this->getClassName() + ": section pair single value \"" + _value + "\" contains invalid characters!").evaluate();
  50. ::std::string newLine = ls::std::io::NewLine::get();
  51. this->value = _value;
  52. if (this->value.find(newLine) != ::std::string::npos)
  53. {
  54. this->value.replace(this->value.find(newLine), newLine.size(), "");
  55. }
  56. }