SectionPairSectionProvider.cpp 3.8 KB

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