SectionPairSectionProvider.cpp 4.2 KB

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