SectionPairDocument.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-15
  6. * Changed: 2024-05-25
  7. *
  8. * */
  9. #ifndef LS_STD_SECTION_PAIR_DOCUMENT_HPP
  10. #define LS_STD_SECTION_PAIR_DOCUMENT_HPP
  11. #include <ls-std/core/Class.hpp>
  12. #include <ls-std/core/interface/ISerializable.hpp>
  13. #include <ls-std/io/section-pair/SectionPairTypes.hpp>
  14. #include <ls-std/io/section-pair/type/SectionPairDocumentTypes.hpp>
  15. #include <ls-std/os/dynamic-goal.hpp>
  16. #include <memory>
  17. #include <string_view>
  18. /*
  19. * @class(name: 'SectionPairDocument', package: 'io')
  20. * */
  21. namespace ls::std::io
  22. {
  23. class LS_STD_DYNAMIC_GOAL SectionPairDocument : public ::std::enable_shared_from_this<SectionPairDocument>, public ls::std::core::Class, public ls::std::core::interface_type::ISerializable
  24. {
  25. public:
  26. SectionPairDocument();
  27. ~SectionPairDocument() noexcept override;
  28. void add(const ls::std::io::section_pair_document_section_list_element &_section);
  29. void clear();
  30. [[nodiscard]] ls::std::io::section_pair_document_section_list_element get(size_t _index) const;
  31. [[nodiscard]] ls::std::io::section_pair_document_section_list_element get(const ls::std::io::section_pair_identifier &_sectionId) const;
  32. [[nodiscard]] size_t getAmountOfSections() const;
  33. [[nodiscard]] ::std::string getHeader() const;
  34. [[nodiscard]] ls::std::io::section_pair_document_section_list getSectionList() const;
  35. [[nodiscard]] bool hasSection(const ls::std::io::section_pair_identifier &_sectionId);
  36. [[nodiscard]] ls::std::core::type::byte_field marshal() override;
  37. void reserveNewLine(::std::string_view _reservedNewLine);
  38. void unmarshal(const ls::std::core::type::byte_field &_data) override;
  39. private:
  40. const ::std::string header = "# section-pair document";
  41. ::std::string reservedNewLine{};
  42. ls::std::io::section_pair_document_section_list sections{};
  43. ::std::shared_ptr<ls::std::core::interface_type::ISerializable> serializable{};
  44. void _checkSectionExistence(const ls::std::io::section_pair_identifier &_sectionId);
  45. void _createSerializable();
  46. [[nodiscard]] ls::std::io::section_pair_document_section_list_element _get(const ls::std::io::section_pair_identifier &_sectionId) const;
  47. [[nodiscard]] bool _hasSection(const ls::std::io::section_pair_identifier &_identifier);
  48. };
  49. }
  50. #endif