Serenity Operating System
at master 71 lines 1.8 kB view raw
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 8#pragma once 9 10#include <AK/Error.h> 11#include <AK/String.h> 12#include <LibManual/Node.h> 13 14namespace Manual { 15 16class SectionNode : public Node { 17public: 18 virtual ~SectionNode() override = default; 19 20 SectionNode(StringView section, StringView name) 21 : m_section(MUST(String::from_utf8(section))) 22 , m_name(MUST(String::from_utf8(name))) 23 { 24 } 25 26 virtual ErrorOr<Span<NonnullRefPtr<Node const>>> children() const override 27 { 28 TRY(reify_if_needed()); 29 return m_children.span(); 30 } 31 32 virtual Node const* parent() const override { return nullptr; } 33 virtual ErrorOr<String> name() const override; 34 String const& section_name() const { return m_section; } 35 virtual ErrorOr<String> path() const override; 36 virtual PageNode const* document() const override { return nullptr; } 37 38 virtual bool is_open() const override { return m_open; } 39 void set_open(bool open); 40 41 static ErrorOr<NonnullRefPtr<SectionNode>> try_create_from_number(StringView section_number); 42 43protected: 44 // In this class, the section is a number, but in lower sections it might be the same as the name. 45 String m_section; 46 String m_name; 47 48private: 49 ErrorOr<void> reify_if_needed() const; 50 51 mutable Vector<NonnullRefPtr<Node const>> m_children; 52 mutable bool m_reified { false }; 53 bool m_open { false }; 54}; 55 56constexpr size_t number_of_sections = 8; 57 58extern Array<NonnullRefPtr<SectionNode>, number_of_sections> const sections; 59 60constexpr Array<StringView, number_of_sections> const section_numbers = { 61 "1"sv, 62 "2"sv, 63 "3"sv, 64 "4"sv, 65 "5"sv, 66 "6"sv, 67 "7"sv, 68 "8"sv, 69}; 70 71}