SectionPairSectionProvider.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-15
  6. * Changed: 2023-05-18
  7. *
  8. * */
  9. #include "SectionPairSectionProvider.hpp"
  10. using ls::std::core::type::byte_field;
  11. using ls::std::io::SectionPairRow;
  12. using ls::std::io::SectionPairRowEnumType;
  13. using ls::std::io::SectionPairRowListValue;
  14. using ls::std::io::SectionPairRowSingleValue;
  15. using ls::std::io::SectionPairSection;
  16. using std::dynamic_pointer_cast;
  17. using std::make_shared;
  18. using std::shared_ptr;
  19. using std::string;
  20. using test::io::SectionPairSectionProvider;
  21. SectionPairSectionProvider::SectionPairSectionProvider() = default;
  22. SectionPairSectionProvider::~SectionPairSectionProvider() = default;
  23. shared_ptr<SectionPairSection> SectionPairSectionProvider::createSectionWithSandraExample()
  24. {
  25. auto generalSection = make_shared<SectionPairSection>("general");
  26. auto name = make_shared<SectionPairRow>("name", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  27. dynamic_pointer_cast<SectionPairRowSingleValue>(name->getValue())->set("Sandra");
  28. generalSection->add(name);
  29. auto age = make_shared<SectionPairRow>("age", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  30. dynamic_pointer_cast<SectionPairRowSingleValue>(age->getValue())->set("24");
  31. generalSection->add(age);
  32. auto hobbies = make_shared<SectionPairRow>("hobbies", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
  33. dynamic_pointer_cast<SectionPairRowListValue>(hobbies->getValue())->add("swimming");
  34. dynamic_pointer_cast<SectionPairRowListValue>(hobbies->getValue())->add("cycling");
  35. dynamic_pointer_cast<SectionPairRowListValue>(hobbies->getValue())->add("singing");
  36. generalSection->add(hobbies);
  37. return generalSection;
  38. }
  39. shared_ptr<SectionPairSection> SectionPairSectionProvider::createSectionWithTomExample()
  40. {
  41. auto section = make_shared<SectionPairSection>("general");
  42. auto name = make_shared<SectionPairRow>("name", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  43. dynamic_pointer_cast<SectionPairRowSingleValue>(name->getValue())->set("Tom");
  44. section->add(name);
  45. auto jobs = make_shared<SectionPairRow>("jobs", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
  46. shared_ptr<SectionPairRowListValue> jobList = dynamic_pointer_cast<SectionPairRowListValue>(jobs->getValue());
  47. jobList->add("Farmer");
  48. jobList->add("Bounty Hunter");
  49. section->add(jobs);
  50. auto age = make_shared<SectionPairRow>("age", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  51. dynamic_pointer_cast<SectionPairRowSingleValue>(age->getValue())->set("33");
  52. section->add(age);
  53. return section;
  54. }
  55. byte_field SectionPairSectionProvider::createSerializedSectionWithSandraExample(const string &_newLine)
  56. {
  57. byte_field serializedDocument{};
  58. serializedDocument += _newLine + "[general]" + _newLine + _newLine;
  59. serializedDocument += "name=Sandra" + _newLine;
  60. serializedDocument += "age=24" + _newLine;
  61. serializedDocument += "hobbies:" + _newLine;
  62. serializedDocument += " swimming" + _newLine;
  63. serializedDocument += " cycling" + _newLine;
  64. serializedDocument += " singing" + _newLine;
  65. return serializedDocument;
  66. }
  67. byte_field SectionPairSectionProvider::createSerializedSectionWithTomExample(const string &_newLine)
  68. {
  69. byte_field serializedSection = _newLine + "[general]" + _newLine + _newLine;
  70. byte_field serializedNameRow = "name=Tom" + _newLine;
  71. byte_field serializedJobsRow = "jobs:" + _newLine + " Farmer" + _newLine + " Bounty Hunter" + _newLine;
  72. byte_field serializedAgeRow = "age=33" + _newLine;
  73. return serializedSection + serializedNameRow + serializedJobsRow + serializedAgeRow;
  74. }