Serenity Operating System
at master 46 lines 1.2 kB view raw
1/* 2 * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include "SubsectionNode.h" 8#include "PageNode.h" 9#include <AK/TypeCasts.h> 10 11namespace Manual { 12 13SubsectionNode::SubsectionNode(NonnullRefPtr<SectionNode const> parent, StringView name) 14 : SectionNode(name, name) 15 , m_parent(move(parent)) 16{ 17} 18 19Node const* SubsectionNode::parent() const { return m_parent; } 20 21PageNode const* SubsectionNode::document() const 22{ 23 auto maybe_siblings = parent()->children(); 24 if (maybe_siblings.is_error()) 25 return nullptr; 26 auto siblings = maybe_siblings.release_value(); 27 for (auto const& sibling : siblings) { 28 if (&*sibling == this) 29 continue; 30 auto sibling_name = sibling->name(); 31 if (sibling_name.is_error()) 32 continue; 33 if (sibling_name.value() == m_name && is<PageNode>(*sibling)) 34 return static_cast<PageNode const*>(&*sibling); 35 } 36 return nullptr; 37} 38 39ErrorOr<String> SubsectionNode::name() const { return m_name; } 40 41ErrorOr<String> SubsectionNode::path() const 42{ 43 return String::formatted("{}/{}", TRY(m_parent->path()), m_section); 44} 45 46}