SectionPairDocumentProvider.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-16
  6. * Changed: 2023-05-16
  7. *
  8. * */
  9. #include "SectionPairDocumentProvider.hpp"
  10. #include <classes/io/section-pair/SectionPairSectionProvider.hpp>
  11. #include <ls-std/ls-std-io.hpp>
  12. using ls::std::core::type::byte_field;
  13. using ls::std::io::SectionPairDocument;
  14. using ls::std::io::SectionPairRow;
  15. using ls::std::io::SectionPairRowEnumType;
  16. using ls::std::io::SectionPairRowSingleValue;
  17. using ls::std::io::SectionPairSection;
  18. using std::dynamic_pointer_cast;
  19. using std::make_shared;
  20. using std::shared_ptr;
  21. using std::string;
  22. using test::io::SectionPairDocumentProvider;
  23. using test::io::SectionPairSectionProvider;
  24. SectionPairDocumentProvider::SectionPairDocumentProvider() = default;
  25. SectionPairDocumentProvider::~SectionPairDocumentProvider() = default;
  26. shared_ptr<SectionPairDocument> SectionPairDocumentProvider::createDocument()
  27. {
  28. auto document = make_shared<SectionPairDocument>();
  29. // general section
  30. shared_ptr<SectionPairSection> generalSection = SectionPairSectionProvider::createSectionWithSandraExample();
  31. document->add(generalSection);
  32. // physical
  33. auto physicalSection = make_shared<SectionPairSection>("physical");
  34. auto eyeColor = make_shared<SectionPairRow>("eye-color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  35. dynamic_pointer_cast<SectionPairRowSingleValue>(eyeColor->getValue())->set("blue");
  36. physicalSection->add(eyeColor);
  37. auto hairColor = make_shared<SectionPairRow>("hair-color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  38. dynamic_pointer_cast<SectionPairRowSingleValue>(hairColor->getValue())->set("red");
  39. physicalSection->add(hairColor);
  40. auto height = make_shared<SectionPairRow>("height", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  41. dynamic_pointer_cast<SectionPairRowSingleValue>(height->getValue())->set("167");
  42. physicalSection->add(height);
  43. document->add(physicalSection);
  44. return document;
  45. }
  46. byte_field SectionPairDocumentProvider::createSerializedDocument(const string &_newLine)
  47. {
  48. byte_field serializedDocument = "# section-pair document" + _newLine;
  49. // general section
  50. serializedDocument += SectionPairSectionProvider::createSerializedSectionWithSandraExample(_newLine);
  51. // physical
  52. serializedDocument += _newLine + "[physical]" + _newLine + _newLine;
  53. serializedDocument += "eye-color=blue" + _newLine;
  54. serializedDocument += "hair-color=red" + _newLine;
  55. serializedDocument += "height=167" + _newLine;
  56. return serializedDocument;
  57. }
  58. byte_field SectionPairDocumentProvider::createSerializedDocumentComputerExample(const string &_newLine)
  59. {
  60. byte_field serializedDocument = "# section-pair document" + _newLine;
  61. serializedDocument += _newLine + "[model]" + _newLine + _newLine;
  62. serializedDocument += "graphics-card=GTX 720" + _newLine;
  63. serializedDocument += "ram-size=4096" + _newLine;
  64. serializedDocument += "graphics-ram-size=4096" + _newLine;
  65. serializedDocument += "cpu=Intel i7" + _newLine;
  66. serializedDocument += _newLine + "[requirements]" + _newLine + _newLine;
  67. serializedDocument += "graphics-ram-size=2048" + _newLine;
  68. serializedDocument += "io-devices:" + _newLine;
  69. serializedDocument += " mouse" + _newLine;
  70. serializedDocument += " keyboard" + _newLine;
  71. serializedDocument += " screen" + _newLine;
  72. serializedDocument += " headset" + _newLine;
  73. return serializedDocument;
  74. }