SectionNode.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Error.h>
  9. #include <AK/String.h>
  10. #include <LibManual/Node.h>
  11. namespace Manual {
  12. class SectionNode : public Node {
  13. public:
  14. virtual ~SectionNode() override = default;
  15. SectionNode(StringView section, StringView name)
  16. : m_section(MUST(String::from_utf8(section)))
  17. , m_name(MUST(String::from_utf8(name)))
  18. {
  19. }
  20. virtual ErrorOr<Span<NonnullRefPtr<Node>>> children() const override
  21. {
  22. TRY(reify_if_needed());
  23. return m_children.span();
  24. }
  25. virtual Node const* parent() const override { return nullptr; }
  26. virtual ErrorOr<String> name() const override;
  27. String const& section_name() const { return m_section; }
  28. ErrorOr<String> path() const;
  29. virtual bool is_open() const override { return m_open; }
  30. void set_open(bool open);
  31. static ErrorOr<NonnullRefPtr<SectionNode>> try_create_from_number(StringView section_number);
  32. protected:
  33. String m_section;
  34. String m_name;
  35. private:
  36. ErrorOr<void> reify_if_needed() const;
  37. mutable NonnullRefPtrVector<Node> m_children;
  38. mutable bool m_reified { false };
  39. bool m_open { false };
  40. };
  41. constexpr size_t number_of_sections = 8;
  42. extern Array<NonnullRefPtr<SectionNode>, number_of_sections> const sections;
  43. constexpr Array<StringView, number_of_sections> const section_numbers = {
  44. "1"sv,
  45. "2"sv,
  46. "3"sv,
  47. "4"sv,
  48. "5"sv,
  49. "6"sv,
  50. "7"sv,
  51. "8"sv,
  52. };
  53. }