From deb8f19936ead3e995d418d2c87ea030d7fe434d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 11 Nov 2026 17:52:12 +0100 Subject: libs/acpi: improve common documentation --- libs/acpi/acpi/common/basic_table.hpp | 9 ++ libs/acpi/acpi/common/table_signature.hpp | 6 + libs/acpi/acpi/common/table_type.hpp | 7 ++ libs/acpi/acpi/common/vla_table.hpp | 184 ++++++++++++++++++++++++++---- 4 files changed, 183 insertions(+), 23 deletions(-) (limited to 'libs/acpi') diff --git a/libs/acpi/acpi/common/basic_table.hpp b/libs/acpi/acpi/common/basic_table.hpp index f5b5b271..e005b90d 100644 --- a/libs/acpi/acpi/common/basic_table.hpp +++ b/libs/acpi/acpi/common/basic_table.hpp @@ -14,16 +14,25 @@ namespace acpi template struct basic_table : table_header { + //! Validate the checksum of this table. + //! + //! @return @p true iff. the checksum of this table is valid, @p false otherwise. [[nodiscard]] auto validate_checksum() const noexcept -> bool { return acpi::validate_checksum(as_span()); } + //! Get a read-only span representing the raw bytes of this table. + //! + //! @return A span of bytes covering the entire table. [[nodiscard]] auto as_span() const noexcept -> std::span { return {reinterpret_cast(this), length().value}; } + //! Validate the integrity of this table. + //! + //! @return @p true iff. the table has a valid signature and checksum, @p false otherwise. [[nodiscard]] auto validate() const noexcept -> bool { return signature() == table_signature_v && validate_checksum(); diff --git a/libs/acpi/acpi/common/table_signature.hpp b/libs/acpi/acpi/common/table_signature.hpp index f0c2d7a3..103b96a8 100644 --- a/libs/acpi/acpi/common/table_signature.hpp +++ b/libs/acpi/acpi/common/table_signature.hpp @@ -6,9 +6,15 @@ namespace acpi { + //! The base template for table signatures. + //! + //! A developer may choose to specialize this template for each ACPI table type to provide its signature. template struct table_signature; + //! The signature for a given ACPI table type. + //! + //! @tparam TableType The ACPI table type. template constexpr auto table_signature_v = table_signature::value; diff --git a/libs/acpi/acpi/common/table_type.hpp b/libs/acpi/acpi/common/table_type.hpp index bc427c7b..ea66d461 100644 --- a/libs/acpi/acpi/common/table_type.hpp +++ b/libs/acpi/acpi/common/table_type.hpp @@ -6,9 +6,16 @@ namespace acpi { + //! The base template for table types. + //! + //! A developer may choose to specialize this template for each ACPI table signature to provide its corresponding + //! table type. template struct table_type; + //! The table type corresponding to a given ACPI table signature. + //! + //! @tparam Signature The ACPI table signature. template using table_type_t = typename table_type::type; diff --git a/libs/acpi/acpi/common/vla_table.hpp b/libs/acpi/acpi/common/vla_table.hpp index e003c4ca..e236c58b 100644 --- a/libs/acpi/acpi/common/vla_table.hpp +++ b/libs/acpi/acpi/common/vla_table.hpp @@ -23,6 +23,9 @@ namespace acpi using reference = value_type &; using difference_type = std::ptrdiff_t; + //! Advance the iterator to the next entry in the VLA table. + //! + //! @return A copy of the iterator before it was advanced. constexpr auto operator++(int) noexcept -> IteratorType { auto self = static_cast(this); @@ -31,6 +34,11 @@ namespace acpi return copy; } + //! Move the iterator to the previous entry in the VLA table. + //! + //! @note This operation requires that the iterator supports the pre-decrement operator. + //! + //! @return A copy of the iterator before it was moved backward. constexpr auto operator--(int) noexcept -> IteratorType requires requires { --*static_cast(this); } { @@ -40,16 +48,27 @@ namespace acpi return copy; } + //! Access the entry at the current iterator position. + //! + //! @return A reference to the entry at the current iterator position. constexpr auto operator*() const noexcept -> reference { return *this->m_entry; } + //! Access a member of the entry at the current iterator position. + //! + //! @return A pointer to the entry at the current iterator position. constexpr auto operator->() const noexcept -> pointer { return this->m_entry; } + //! Compare two iterators for equality. + //! + //! @param lhs The left-hand side iterator. + //! @param rhs The right-hand side iterator. + //! @return @p true iff. the iterators are equal, @p false otherwise. constexpr auto friend operator==(common_vla_table_iterator_base const & lhs, common_vla_table_iterator_base const & rhs) noexcept -> bool { @@ -59,24 +78,35 @@ namespace acpi private: friend IteratorType; + //! Construct a sentinel iterator. constexpr common_vla_table_iterator_base() noexcept = default; + //! Construct an iterator pointing to a specific entry in the VLA table. + //! + //! @param entry A pointer to the entry to start the iterator at. + //! @param limit A pointer to the end of the VLA table. constexpr common_vla_table_iterator_base(pointer entry, pointer limit) noexcept : m_entry{entry} , m_limit{limit} {} + //! Check if the iterator has reached the end of the VLA table. + //! + //! @return @p true if the iterator is at the end, @p false otherwise. [[nodiscard]] constexpr auto is_end() const noexcept -> bool { return m_entry == m_limit || m_entry == nullptr; } + //! The current entry the iterator is pointing to. pointer m_entry{}; + //! The end of the VLA table. pointer m_limit{}; }; } // namespace detail + //! An iterator for variable-length array (VLA) tables with variable-sized entries. template struct vla_table_iterator : detail::common_vla_table_iterator_base> @@ -92,12 +122,20 @@ namespace acpi using super::operator++; + //! Construct a sentinel iterator for the end of the VLA table. constexpr vla_table_iterator() noexcept = default; + //! Construct an iterator pointing to a specific entry in the VLA table. + //! + //! @param entry A pointer to the entry to start the iterator at. + //! @param limit A pointer to the end of the VLA table. constexpr vla_table_iterator(pointer entry, pointer limit) noexcept : super{entry, limit} {} + //! Advance the iterator to the next entry in the VLA table. + //! + //! @return A reference to the updated iterator. auto operator++() noexcept -> vla_table_iterator & { auto decayed = std::bit_cast(this->m_entry); @@ -107,6 +145,7 @@ namespace acpi } }; + //! An iterator for variable-length array (VLA) tables with fixed-sized entries. template struct vla_table_iterator : detail::common_vla_table_iterator_base> @@ -123,75 +162,135 @@ namespace acpi using super::operator++; using super::operator--; + //! Construct a sentinel iterator for the end of the VLA table. constexpr vla_table_iterator() noexcept = default; + //! Construct an iterator pointing to a specific entry in the VLA table. + //! + //! @param entry A pointer to the entry to start the iterator at. + //! @param limit A pointer to the end of the VLA table. constexpr vla_table_iterator(pointer entry, pointer limit) noexcept : super{entry, limit} {} - constexpr auto operator<=>(vla_table_iterator const & other) const noexcept -> std::strong_ordering + //! Compare two VLA table iterators for ordering. + //! + //! @param lhs The left-hand side iterator. + //! @param rhs The right-hand side iterator. + //! @return A strong ordering indicating the relative order of the iterators. + constexpr auto friend operator<=>(vla_table_iterator const & lhs, vla_table_iterator const & rhs) noexcept + -> std::strong_ordering { - return this->m_entry <=> other.m_entry; + return lhs.m_entry <=> rhs.m_entry; } - constexpr auto operator==(vla_table_iterator const & other) const noexcept -> bool + //! Compare two VLA table iterators for equality. + //! + //! @param lhs The left-hand side iterator. + //! @param rhs The right-hand side iterator. + //! @return @p true iff. the iterators are equal, @p false otherwise. + constexpr auto friend operator==(vla_table_iterator const & lhs, vla_table_iterator const & rhs) noexcept -> bool { - return this->m_entry == other.m_entry; + return lhs.m_entry == rhs.m_entry; } - constexpr auto operator==(std::default_sentinel_t) const noexcept -> bool + //! Compare the iterator with a sentinel for equality. + //! + //! @param it The iterator to compare. + //! @param sent The sentinel to compare with. + //! @return @p true iff. the iterator has reached the end, @p false otherwise. + constexpr auto friend operator==(vla_table_iterator const & it, std::default_sentinel_t) noexcept -> bool { - return this->m_entry == nullptr || this->m_entry == this->m_limit; + return it.m_entry == nullptr || it.m_entry == it.m_limit; } + //! Advance the iterator to the next entry. + //! + //! @return A reference to the updated iterator. constexpr auto operator++() noexcept -> vla_table_iterator & { ++this->m_entry; return *this; } + //! Move the iterator to the previous entry. + //! + //! @return A reference to the updated iterator. constexpr auto operator--() noexcept -> vla_table_iterator & { --this->m_entry; return *this; } - constexpr auto operator-(vla_table_iterator const & other) const noexcept -> difference_type + //! Compute the distance between two iterators. + //! + //! @param lhs The left-hand side iterator. + //! @param rhs The right-hand side iterator. + //! @return The number of entries between this iterator and the other iterator. + constexpr auto friend operator-(vla_table_iterator const & lhs, vla_table_iterator const & rhs) noexcept + -> difference_type { - return this->m_entry - other.m_entry; + return lhs.m_entry - rhs.m_entry; } - constexpr auto operator+=(difference_type n) noexcept -> vla_table_iterator & + //! Advance the iterator by a given number of entries. + //! + //! @param lhs The iterator to advance. + //! @param n The number of entries to advance. + //! @return A reference to the updated iterator. + constexpr auto friend operator+=(vla_table_iterator & lhs, difference_type n) noexcept -> vla_table_iterator & { - this->m_entry += n; - return *this; + lhs.m_entry += n; + return lhs; } - constexpr auto operator+(difference_type n) const noexcept -> vla_table_iterator + //! Compute a new iterator by adding a given number of entries to an existing iterator. + //! + //! @param it The iterator to add to. + //! @param n The number of entries to add. + //! @return A new iterator advanced by the given number of entries. + constexpr auto friend operator+(vla_table_iterator it, difference_type n) noexcept -> vla_table_iterator { - auto copy = *this; - copy += n; - return copy; + it += n; + return it; } - constexpr auto friend operator+(difference_type n, vla_table_iterator const & it) noexcept -> vla_table_iterator + //! Compute a new iterator by adding a given number of entries to an existing iterator. + //! + //! @param n The number of entries to add. + //! @param it The iterator to add to. + //! @return A new iterator advanced by the given number of entries. + constexpr auto friend operator+(difference_type n, vla_table_iterator it) noexcept -> vla_table_iterator { return it + n; } - constexpr auto operator-=(difference_type n) noexcept -> vla_table_iterator & + //! Move the iterator backward by a given number of entries. + //! + //! @param it The iterator to move backward. + //! @param n The number of entries to move backward. + //! @return A reference to the updated iterator. + constexpr auto friend operator-=(vla_table_iterator & it, difference_type n) noexcept -> vla_table_iterator & { - this->m_entry -= n; - return *this; + it.m_entry -= n; + return it; } - constexpr auto operator-(difference_type n) const noexcept -> vla_table_iterator + //! Compute a new iterator by subtracting a given number of entries from an existing iterator. + //! + //! @param it The iterator to subtract from. + //! @param n The number of entries to subtract. + //! @return A new iterator moved backward by the given number of entries. + constexpr auto friend operator-(vla_table_iterator it, difference_type n) noexcept -> vla_table_iterator { - auto copy = *this; - copy -= n; - return copy; + it -= n; + return it; } + //! Access an entry at a given offset from the current iterator. + //! + //! @param n The offset from the current iterator. + //! @return A reference to the entry at the given offset. constexpr auto operator[](difference_type n) const noexcept -> reference { return *(*this + n); @@ -207,26 +306,41 @@ namespace acpi using reference = entry_type &; using const_reference = entry_type const &; + //! Get an iterator to the beginning of the entries of this table. + //! + //! @return An iterator pointing to the first entry. [[nodiscard]] auto begin() noexcept -> iterator { return cbegin(); } + //! Get an iterator to the end of the entries of this table. + //! + //! @return An iterator pointing past the last entry. [[nodiscard]] auto end() noexcept -> iterator { return cend(); } + //! Get a read-only iterator to the beginning of the entries of this table. + //! + //! @return An iterator pointing to the first entry. [[nodiscard]] auto begin() const noexcept -> const_iterator { return cbegin(); } + //! Get a read-only iterator to the end of the entries of this table. + //! + //! @return An iterator pointing past the last entry. [[nodiscard]] auto end() const noexcept -> const_iterator { return cend(); } + //! Get a read-only iterator to the beginning of the entries of this table. + //! + //! @return An iterator pointing to the first entry. [[nodiscard]] auto cbegin() const noexcept -> const_iterator { auto base = std::bit_cast(this); @@ -236,6 +350,9 @@ namespace acpi return const_iterator{std::bit_cast(base), std::bit_cast(limit)}; } + //! Get a read-only iterator to the end of the entries of this table. + //! + //! @return An iterator pointing past the last entry. [[nodiscard]] auto cend() const noexcept -> const_iterator { auto limit = std::bit_cast(this); @@ -243,16 +360,33 @@ namespace acpi return const_iterator{std::bit_cast(limit), std::bit_cast(limit)}; } + //! Get the number of entries in this table. + //! + //! @note For tables with variable-sized entries, this function will compute the number of entries in linear time. + //! + //! @return The number of entries. [[nodiscard]] auto size() const noexcept -> std::size_t { return std::ranges::distance(cbegin(), cend()); } + //! Access an entry by its index. + //! + //! @warning This function does not perform bounds checking. Use `at()` for bounds-checked access. + //! + //! @param index The index of the entry. + //! @return A reference to the entry at the specified index. [[nodiscard]] auto operator[](std::size_t index) const noexcept -> const_reference { return *(std::next(cbegin(), index)); } + //! Access an entry by its index with bounds checking. + //! + //! @warning This function will panic if the index is out-of-bounds for this table. + //! + //! @param index The index of the entry. + //! @return A reference to the entry at the specified index. [[nodiscard]] auto at(std::size_t index) const -> const_reference { if (index >= size()) @@ -265,8 +399,12 @@ namespace acpi private: friend TableType; + //! Construct a VLA table. constexpr vla_table() noexcept = default; + //! Get a pointer to the base of the variable-length array entries. + //! + //! @return A pointer to the first entry in the variable-length array. [[nodiscard]] auto vla_base() const noexcept -> entry_type * { auto base = std::bit_cast(this); -- cgit v1.2.3