SectionPairDocument.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-15
  6. * Changed: 2024-09-13
  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. * @doc: class(name: 'SectionPairDocument', package: 'io')
  20. * @doc: io.SectionPairDocument.description('This class represents a whole Section Pair document.')
  21. * */
  22. namespace ls::std::io
  23. {
  24. 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
  25. {
  26. public:
  27. SectionPairDocument();
  28. ~SectionPairDocument() noexcept override;
  29. void add(const ls::std::io::section_pair_document_section_list_element &_section);
  30. void clear();
  31. [[nodiscard]] ls::std::io::section_pair_document_section_list_element get(size_t _index) const;
  32. [[nodiscard]] ls::std::io::section_pair_document_section_list_element get(const ls::std::io::section_pair_identifier &_sectionId) const;
  33. [[nodiscard]] size_t getAmountOfSections() const;
  34. [[nodiscard]] ::std::string getHeader() const;
  35. [[nodiscard]] ls::std::io::section_pair_document_section_list getSectionList() const;
  36. [[nodiscard]] bool hasSection(const ls::std::io::section_pair_identifier &_sectionId);
  37. [[nodiscard]] ls::std::core::type::byte_field marshal() override;
  38. void reserveNewLine(::std::string_view _reservedNewLine);
  39. void unmarshal(const ls::std::core::type::byte_field &_data) override;
  40. private:
  41. const ::std::string header = "# section-pair document";
  42. ::std::string reservedNewLine{};
  43. ls::std::io::section_pair_document_section_list sections{};
  44. ::std::shared_ptr<ls::std::core::interface_type::ISerializable> serializable{};
  45. void _checkSectionExistence(const ls::std::io::section_pair_identifier &_sectionId);
  46. void _createSerializable();
  47. [[nodiscard]] ls::std::io::section_pair_document_section_list_element _get(const ls::std::io::section_pair_identifier &_sectionId) const;
  48. [[nodiscard]] bool _hasSection(const ls::std::io::section_pair_identifier &_identifier);
  49. };
  50. }
  51. #endif