123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2023-02-15
- * Changed: 2023-05-18
- *
- * */
- #include "SectionPairSectionProvider.hpp"
- using ls::std::core::type::byte_field;
- using ls::std::io::SectionPairRow;
- using ls::std::io::SectionPairRowEnumType;
- using ls::std::io::SectionPairRowListValue;
- using ls::std::io::SectionPairRowSingleValue;
- using ls::std::io::SectionPairSection;
- using std::dynamic_pointer_cast;
- using std::make_shared;
- using std::shared_ptr;
- using std::string;
- using test::io::SectionPairSectionProvider;
- SectionPairSectionProvider::SectionPairSectionProvider() = default;
- SectionPairSectionProvider::~SectionPairSectionProvider() = default;
- shared_ptr<SectionPairSection> SectionPairSectionProvider::createSectionWithSandraExample()
- {
- auto generalSection = make_shared<SectionPairSection>("general");
- auto name = make_shared<SectionPairRow>("name", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
- dynamic_pointer_cast<SectionPairRowSingleValue>(name->getValue())->set("Sandra");
- generalSection->add(name);
- auto age = make_shared<SectionPairRow>("age", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
- dynamic_pointer_cast<SectionPairRowSingleValue>(age->getValue())->set("24");
- generalSection->add(age);
- auto hobbies = make_shared<SectionPairRow>("hobbies", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
- dynamic_pointer_cast<SectionPairRowListValue>(hobbies->getValue())->add("swimming");
- dynamic_pointer_cast<SectionPairRowListValue>(hobbies->getValue())->add("cycling");
- dynamic_pointer_cast<SectionPairRowListValue>(hobbies->getValue())->add("singing");
- generalSection->add(hobbies);
- return generalSection;
- }
- shared_ptr<SectionPairSection> SectionPairSectionProvider::createSectionWithTomExample()
- {
- auto section = make_shared<SectionPairSection>("general");
- auto name = make_shared<SectionPairRow>("name", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
- dynamic_pointer_cast<SectionPairRowSingleValue>(name->getValue())->set("Tom");
- section->add(name);
- auto jobs = make_shared<SectionPairRow>("jobs", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
- shared_ptr<SectionPairRowListValue> jobList = dynamic_pointer_cast<SectionPairRowListValue>(jobs->getValue());
- jobList->add("Farmer");
- jobList->add("Bounty Hunter");
- section->add(jobs);
- auto age = make_shared<SectionPairRow>("age", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
- dynamic_pointer_cast<SectionPairRowSingleValue>(age->getValue())->set("33");
- section->add(age);
- return section;
- }
- byte_field SectionPairSectionProvider::createSerializedSectionWithSandraExample(const string &_newLine)
- {
- byte_field serializedDocument{};
- serializedDocument += _newLine + "[general]" + _newLine + _newLine;
- serializedDocument += "name=Sandra" + _newLine;
- serializedDocument += "age=24" + _newLine;
- serializedDocument += "hobbies:" + _newLine;
- serializedDocument += " swimming" + _newLine;
- serializedDocument += " cycling" + _newLine;
- serializedDocument += " singing" + _newLine;
- return serializedDocument;
- }
- byte_field SectionPairSectionProvider::createSerializedSectionWithTomExample(const string &_newLine)
- {
- byte_field serializedSection = _newLine + "[general]" + _newLine + _newLine;
- byte_field serializedNameRow = "name=Tom" + _newLine;
- byte_field serializedJobsRow = "jobs:" + _newLine + " Farmer" + _newLine + " Bounty Hunter" + _newLine;
- byte_field serializedAgeRow = "age=33" + _newLine;
- return serializedSection + serializedNameRow + serializedJobsRow + serializedAgeRow;
- }
|