diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-08-18 13:51:55 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-08-18 13:51:55 +0200 |
| commit | cd665ec172dadd049e7c1830b070f15b58fb9011 (patch) | |
| tree | 42c2eb8ecb984d179263f68cab1c6c2667e8dd2c /libs | |
| parent | 5754a8591252da5d5eeb4281064f0b82bfdc03a8 (diff) | |
| download | kernel-cd665ec172dadd049e7c1830b070f15b58fb9011.tar.xz kernel-cd665ec172dadd049e7c1830b070f15b58fb9011.zip | |
kstd: flatten units namespace
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/acpi/acpi/common/table_header.cpp | 4 | ||||
| -rw-r--r-- | libs/acpi/acpi/common/table_header.hpp | 2 | ||||
| -rw-r--r-- | libs/acpi/acpi/pointers.cpp | 4 | ||||
| -rw-r--r-- | libs/acpi/acpi/pointers.hpp | 2 | ||||
| -rw-r--r-- | libs/kstd/kstd/units.hpp | 113 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/information.hpp | 8 | ||||
| -rw-r--r-- | libs/multiboot2/multiboot2/information/data.hpp | 20 |
7 files changed, 79 insertions, 74 deletions
diff --git a/libs/acpi/acpi/common/table_header.cpp b/libs/acpi/acpi/common/table_header.cpp index ebceca1d..cf2e7c23 100644 --- a/libs/acpi/acpi/common/table_header.cpp +++ b/libs/acpi/acpi/common/table_header.cpp @@ -52,7 +52,7 @@ namespace acpi return std::string_view{base + offset, size}; } - auto table_header::length() const noexcept -> kstd::units::bytes + auto table_header::length() const noexcept -> kstd::bytes { using type = decltype(common_table_header_data::length); @@ -64,7 +64,7 @@ namespace acpi kstd::libc::memcpy(&raw_value, data.data(), size); - return kstd::units::bytes{raw_value}; + return kstd::bytes{raw_value}; } auto table_header::oem_id() const noexcept -> std::string_view diff --git a/libs/acpi/acpi/common/table_header.hpp b/libs/acpi/acpi/common/table_header.hpp index 8e1d7c59..18e1dfdf 100644 --- a/libs/acpi/acpi/common/table_header.hpp +++ b/libs/acpi/acpi/common/table_header.hpp @@ -30,7 +30,7 @@ namespace acpi [[nodiscard]] auto creator_id() const noexcept -> std::string_view; //! Get the length of the entire table, including this header. - [[nodiscard]] auto length() const noexcept -> kstd::units::bytes; + [[nodiscard]] auto length() const noexcept -> kstd::bytes; //! Get the ID of the OEM. [[nodiscard]] auto oem_id() const noexcept -> std::string_view; diff --git a/libs/acpi/acpi/pointers.cpp b/libs/acpi/acpi/pointers.cpp index 0393292c..85329bf2 100644 --- a/libs/acpi/acpi/pointers.cpp +++ b/libs/acpi/acpi/pointers.cpp @@ -38,9 +38,9 @@ namespace acpi return signature() == "RSD PTR " && validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(rsdp)}); } - auto xsdp::length() const noexcept -> kstd::units::bytes + auto xsdp::length() const noexcept -> kstd::bytes { - return kstd::units::bytes{m_length}; + return kstd::bytes{m_length}; } auto xsdp::table_address() const noexcept -> std::uintptr_t diff --git a/libs/acpi/acpi/pointers.hpp b/libs/acpi/acpi/pointers.hpp index 310447f5..761d8748 100644 --- a/libs/acpi/acpi/pointers.hpp +++ b/libs/acpi/acpi/pointers.hpp @@ -50,7 +50,7 @@ namespace acpi struct [[gnu::packed]] xsdp : rsdp { //! Get the length of the data contained in this pointer. - [[nodiscard]] auto length() const noexcept -> kstd::units::bytes; + [[nodiscard]] auto length() const noexcept -> kstd::bytes; //! Get the physical address of the pointed-to Extended System Description Table. [[nodiscard]] auto table_address() const noexcept -> std::uintptr_t; diff --git a/libs/kstd/kstd/units.hpp b/libs/kstd/kstd/units.hpp index cb33af21..e3868aa7 100644 --- a/libs/kstd/kstd/units.hpp +++ b/libs/kstd/kstd/units.hpp @@ -9,71 +9,76 @@ namespace kstd { - namespace units - { - - using bytes = basic_unit<std::size_t, struct bytes_tag>; - - // NOLINTNEXTLINE(readability-identifier-naming) - constexpr auto KiB(std::unsigned_integral auto value) noexcept -> bytes - { - return bytes{static_cast<bytes::value_type>(value) * 1024}; - } + using bytes = basic_unit<std::size_t, struct bytes_tag>; - // NOLINTNEXTLINE(readability-identifier-naming) - constexpr auto MiB(std::unsigned_integral auto value) noexcept -> bytes - { - return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024}; - } - - // NOLINTNEXTLINE(readability-identifier-naming) - constexpr auto GiB(std::unsigned_integral auto value) noexcept -> bytes - { - return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024 * 1024}; - } - - template<typename ValueType> - constexpr auto operator+(ValueType * pointer, bytes offset) -> ValueType * - { - return pointer + offset.value; - } - - } // namespace units + // NOLINTNEXTLINE(readability-identifier-naming) + constexpr auto KiB(std::unsigned_integral auto value) noexcept -> bytes + { + return bytes{static_cast<bytes::value_type>(value) * 1024}; + } - namespace units_literals + // NOLINTNEXTLINE(readability-identifier-naming) + constexpr auto MiB(std::unsigned_integral auto value) noexcept -> bytes { - constexpr auto operator""_B(unsigned long long value) noexcept -> units::bytes - { - return units::bytes{value}; - } + return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024}; + } - constexpr auto operator""_KiB(unsigned long long value) noexcept -> units::bytes - { - return units::KiB(value); - } + // NOLINTNEXTLINE(readability-identifier-naming) + constexpr auto GiB(std::unsigned_integral auto value) noexcept -> bytes + { + return bytes{static_cast<bytes::value_type>(value) * 1024 * 1024 * 1024}; + } - constexpr auto operator""_MiB(unsigned long long value) noexcept -> units::bytes - { - return units::MiB(value); - } + template<typename ValueType> + constexpr auto operator+(ValueType * pointer, bytes offset) -> ValueType * + { + return pointer + offset.value; + } - constexpr auto operator""_GiB(unsigned long long value) noexcept -> units::bytes + inline namespace literals + { + inline namespace units_literals { - return units::GiB(value); - } - - } // namespace units_literals - - template<typename ValueType> - consteval auto size_of(ValueType const &) noexcept -> units::bytes + constexpr auto operator""_B(unsigned long long value) noexcept -> bytes + { + return bytes{value}; + } + + constexpr auto operator""_KiB(unsigned long long value) noexcept -> bytes + { + return KiB(value); + } + + constexpr auto operator""_MiB(unsigned long long value) noexcept -> bytes + { + return MiB(value); + } + + constexpr auto operator""_GiB(unsigned long long value) noexcept -> bytes + { + return GiB(value); + } + + } // namespace units_literals + } // namespace literals + + //! Calculate the size of a given object. + //! + //! @param object The object to calculate the size for. + //! @return the size, in bytes, of the given object. + consteval auto size_of(auto const & object) noexcept -> bytes { - return units::bytes{sizeof(ValueType)}; + return bytes{sizeof(object)}; } - template<typename ValueType> - consteval auto size_of() noexcept -> units::bytes + //! Calculate the size of a given type. + //! + //! @tparam Type The type to calculate the size for. + //! @return the size, in bytes, of the given type. + template<typename Type> + consteval auto size_of() noexcept -> bytes { - return units::bytes{sizeof(ValueType)}; + return bytes{sizeof(Type)}; } } // namespace kstd diff --git a/libs/multiboot2/multiboot2/information.hpp b/libs/multiboot2/multiboot2/information.hpp index f12969e8..709d64a8 100644 --- a/libs/multiboot2/multiboot2/information.hpp +++ b/libs/multiboot2/multiboot2/information.hpp @@ -124,9 +124,9 @@ namespace multiboot2 return {data(), vla_tag::size()}; } - [[nodiscard]] constexpr auto size() const noexcept -> kstd::units::bytes + [[nodiscard]] constexpr auto size() const noexcept -> kstd::bytes { - return kstd::units::bytes{end_address - start_address}; + return kstd::bytes{end_address - start_address}; } }; @@ -157,9 +157,9 @@ namespace multiboot2 using pointer = iterator::pointer; using reference = iterator::reference; - [[nodiscard]] auto size() const noexcept -> kstd::units::bytes + [[nodiscard]] auto size() const noexcept -> kstd::bytes { - return kstd::units::bytes{m_size}; + return kstd::bytes{m_size}; } // Range access diff --git a/libs/multiboot2/multiboot2/information/data.hpp b/libs/multiboot2/multiboot2/information/data.hpp index 734bbc6f..59d82b9e 100644 --- a/libs/multiboot2/multiboot2/information/data.hpp +++ b/libs/multiboot2/multiboot2/information/data.hpp @@ -29,14 +29,14 @@ namespace multiboot2 //! loader. struct basic_memory : tag_data<information_id::basic_memory_information> { - [[nodiscard]] constexpr auto lower() const noexcept -> kstd::units::bytes + [[nodiscard]] constexpr auto lower() const noexcept -> kstd::bytes { - return kstd::units::bytes{lower_KiB * 1024}; + return kstd::bytes{lower_KiB * 1024}; } - [[nodiscard]] constexpr auto upper() const noexcept -> kstd::units::bytes + [[nodiscard]] constexpr auto upper() const noexcept -> kstd::bytes { - return kstd::units::bytes{upper_KiB * 1024}; + return kstd::bytes{upper_KiB * 1024}; } //! The amount of lower memory available to the system. @@ -84,9 +84,9 @@ namespace multiboot2 //! time. The array begins after the last member of this structure. struct elf_symbols : tag_data<information_id::elf_sections> { - [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::units::bytes + [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::bytes { - return kstd::units::bytes{entry_size_in_B}; + return kstd::bytes{entry_size_in_B}; } //! The number of section header table entries. @@ -119,9 +119,9 @@ namespace multiboot2 return type == memory_type::available; } - [[nodiscard]] constexpr auto size() const noexcept -> kstd::units::bytes + [[nodiscard]] constexpr auto size() const noexcept -> kstd::bytes { - return kstd::units::bytes{size_in_B}; + return kstd::bytes{size_in_B}; } //! The physical start address of this region @@ -139,9 +139,9 @@ namespace multiboot2 std::uint32_t : 0; }; - [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::units::bytes + [[nodiscard]] constexpr auto entry_size() const noexcept -> kstd::bytes { - return kstd::units::bytes{entry_size_in_B}; + return kstd::bytes{entry_size_in_B}; } //! The size of each entry present in the map. |
