LibManual: Fix const-correctness issues

This commit is contained in:
Andreas Kling 2023-02-20 18:59:53 +01:00
parent f11899f885
commit dbcf2f2dd4
Notes: sideshowbarker 2024-07-17 22:55:25 +09:00
8 changed files with 18 additions and 18 deletions

View file

@ -17,7 +17,7 @@
namespace Manual {
ErrorOr<NonnullRefPtr<PageNode>> Node::try_create_from_query(Vector<StringView, 2> const& query_parameters)
ErrorOr<NonnullRefPtr<PageNode const>> Node::try_create_from_query(Vector<StringView, 2> const& query_parameters)
{
if (query_parameters.size() > 2)
return Error::from_string_literal("Queries longer than 2 strings are not supported yet");
@ -66,7 +66,7 @@ ErrorOr<NonnullRefPtr<PageNode>> Node::try_create_from_query(Vector<StringView,
return Error::from_string_literal("Page doesn't exist in section");
}
ErrorOr<NonnullRefPtr<Node>> Node::try_find_from_help_url(URL const& url)
ErrorOr<NonnullRefPtr<Node const>> Node::try_find_from_help_url(URL const& url)
{
if (url.host() != "man")
return Error::from_string_view("Bad help operation"sv);
@ -82,7 +82,7 @@ ErrorOr<NonnullRefPtr<Node>> Node::try_find_from_help_url(URL const& url)
if (section_number > number_of_sections)
return Error::from_string_view("Section number out of bounds"sv);
NonnullRefPtr<Node> current_node = sections[section_number - 1];
NonnullRefPtr<Node const> current_node = sections[section_number - 1];
while (!paths.is_empty()) {
auto next_path_segment = TRY(String::from_deprecated_string(paths.take_first()));

View file

@ -20,7 +20,7 @@ class Node : public RefCounted<Node> {
public:
virtual ~Node() = default;
virtual ErrorOr<Span<NonnullRefPtr<Node>>> children() const = 0;
virtual ErrorOr<Span<NonnullRefPtr<Node const>>> children() const = 0;
virtual Node const* parent() const = 0;
virtual ErrorOr<String> name() const = 0;
virtual bool is_page() const { return false; }
@ -33,11 +33,11 @@ public:
// [page] (no second argument) - will find first section with that page
// [section] [page]
// Help can also (externally) handle search queries, which is not possible (yet) in man.
static ErrorOr<NonnullRefPtr<PageNode>> try_create_from_query(Vector<StringView, 2> const& query_parameters);
static ErrorOr<NonnullRefPtr<PageNode const>> try_create_from_query(Vector<StringView, 2> const& query_parameters);
// Finds a page via the help://man/<number>/<subsections...>/page URLs.
// This will automatically start discovering pages by inspecting the filesystem.
static ErrorOr<NonnullRefPtr<Node>> try_find_from_help_url(URL const&);
static ErrorOr<NonnullRefPtr<Node const>> try_find_from_help_url(URL const&);
};
}

View file

@ -16,9 +16,9 @@ Node const* PageNode::parent() const
return m_section.ptr();
}
ErrorOr<Span<NonnullRefPtr<Node>>> PageNode::children() const
ErrorOr<Span<NonnullRefPtr<Node const>>> PageNode::children() const
{
static NonnullRefPtrVector<Node> empty_vector;
static NonnullRefPtrVector<Node const> empty_vector;
return empty_vector.span();
}

View file

@ -17,13 +17,13 @@ class PageNode : public Node {
public:
virtual ~PageNode() override = default;
PageNode(NonnullRefPtr<SectionNode> section, String page)
PageNode(NonnullRefPtr<SectionNode const> section, String page)
: m_section(move(section))
, m_page(move(page))
{
}
virtual ErrorOr<Span<NonnullRefPtr<Node>>> children() const override;
virtual ErrorOr<Span<NonnullRefPtr<Node const>>> children() const override;
virtual Node const* parent() const override;
virtual ErrorOr<String> name() const override { return m_page; };
virtual bool is_page() const override { return true; }
@ -34,7 +34,7 @@ public:
static ErrorOr<NonnullRefPtr<PageNode>> help_index_page();
private:
NonnullRefPtr<SectionNode> m_section;
NonnullRefPtr<SectionNode const> m_section;
String m_page;
};

View file

@ -46,7 +46,7 @@ ErrorOr<void> SectionNode::reify_if_needed() const
Core::DirIterator dir_iter { own_path.to_deprecated_string(), Core::DirIterator::Flags::SkipDots };
struct Child {
NonnullRefPtr<Node> node;
NonnullRefPtr<Node const> node;
String name_for_sorting;
};
Vector<Child> children;

View file

@ -23,7 +23,7 @@ public:
{
}
virtual ErrorOr<Span<NonnullRefPtr<Node>>> children() const override
virtual ErrorOr<Span<NonnullRefPtr<Node const>>> children() const override
{
TRY(reify_if_needed());
return m_children.span();
@ -48,7 +48,7 @@ protected:
private:
ErrorOr<void> reify_if_needed() const;
mutable NonnullRefPtrVector<Node> m_children;
mutable NonnullRefPtrVector<Node const> m_children;
mutable bool m_reified { false };
bool m_open { false };
};

View file

@ -10,7 +10,7 @@
namespace Manual {
SubsectionNode::SubsectionNode(NonnullRefPtr<SectionNode> parent, StringView name)
SubsectionNode::SubsectionNode(NonnullRefPtr<SectionNode const> parent, StringView name)
: SectionNode(name, name)
, m_parent(move(parent))
{
@ -31,7 +31,7 @@ PageNode const* SubsectionNode::document() const
if (sibling_name.is_error())
continue;
if (sibling_name.value() == m_name && is<PageNode>(*sibling))
return static_cast<PageNode*>(&*sibling);
return static_cast<PageNode const*>(&*sibling);
}
return nullptr;
}

View file

@ -13,7 +13,7 @@ namespace Manual {
// A non-toplevel (i.e. not numbered) manual section.
class SubsectionNode : public SectionNode {
public:
SubsectionNode(NonnullRefPtr<SectionNode> parent, StringView name);
SubsectionNode(NonnullRefPtr<SectionNode const> parent, StringView name);
virtual ~SubsectionNode() = default;
virtual Node const* parent() const override;
@ -22,7 +22,7 @@ public:
virtual PageNode const* document() const override;
protected:
NonnullRefPtr<SectionNode> m_parent;
NonnullRefPtr<SectionNode const> m_parent;
};
}