SerializableSectionPairRowProvider.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-17
  6. * Changed: 2023-05-18
  7. *
  8. * */
  9. #include "SerializableSectionPairRowProvider.hpp"
  10. using ls::std::io::SectionPairRow;
  11. using ls::std::io::SectionPairRowEnumType;
  12. using ls::std::io::SectionPairRowListValue;
  13. using ls::std::io::SectionPairRowSingleValue;
  14. using ls::std::io::SerializableSectionPairParameter;
  15. using ls::std::io::SerializableSectionPairRow;
  16. using std::dynamic_pointer_cast;
  17. using std::make_shared;
  18. using std::shared_ptr;
  19. using std::string;
  20. using test::io::SerializableSectionPairRowProvider;
  21. SerializableSectionPairRowProvider::SerializableSectionPairRowProvider() = default;
  22. SerializableSectionPairRowProvider::~SerializableSectionPairRowProvider() = default;
  23. shared_ptr<SerializableSectionPairRow> SerializableSectionPairRowProvider::createListValueForMarshal(const string &_newLine)
  24. {
  25. SerializableSectionPairParameter parameter{};
  26. parameter.setNewLine(_newLine);
  27. auto row = make_shared<SectionPairRow>("favourite-colors", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
  28. parameter.setValue(row);
  29. shared_ptr<SectionPairRowListValue> listValue = dynamic_pointer_cast<SectionPairRowListValue>(row->getValue());
  30. listValue->add("blue");
  31. listValue->add("red");
  32. listValue->add("purple");
  33. return make_shared<SerializableSectionPairRow>(parameter);
  34. }
  35. shared_ptr<SerializableSectionPairRow> SerializableSectionPairRowProvider::createListValueForUnmarshal(const string &_newLine)
  36. {
  37. SerializableSectionPairParameter parameter{};
  38. parameter.setNewLine(_newLine);
  39. auto row = make_shared<SectionPairRow>("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
  40. parameter.setValue(row);
  41. return make_shared<SerializableSectionPairRow>(parameter);
  42. }
  43. shared_ptr<SerializableSectionPairRow> SerializableSectionPairRowProvider::createSingleValueForMarshal(const string &_newLine)
  44. {
  45. SerializableSectionPairParameter parameter{};
  46. parameter.setNewLine(_newLine);
  47. auto row = make_shared<SectionPairRow>("favourite-color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  48. parameter.setValue(row);
  49. shared_ptr<SectionPairRowSingleValue> singleValue = dynamic_pointer_cast<SectionPairRowSingleValue>(row->getValue());
  50. singleValue->set("blue");
  51. return make_shared<SerializableSectionPairRow>(parameter);
  52. }
  53. shared_ptr<SerializableSectionPairRow> SerializableSectionPairRowProvider::createSingleValueForUnmarshal(const string &_newLine)
  54. {
  55. SerializableSectionPairParameter parameter{};
  56. parameter.setNewLine(_newLine);
  57. auto row = make_shared<SectionPairRow>("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  58. parameter.setValue(row);
  59. return make_shared<SerializableSectionPairRow>(parameter);
  60. }