aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-08-26 19:24:11 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-08-26 19:24:11 +0200
commita08dbf62d8dedd6501743598f5a3c4bfc464208d (patch)
tree9f905b30e5a9918f92a6ff37d7c3a5b6d8f32752 /libs
parent0cf5196eff081d4eab4cfb9fc9eb7390f45696e5 (diff)
parent8f027bb373673374641c93d443bdce829ea1ca75 (diff)
downloadkernel-a08dbf62d8dedd6501743598f5a3c4bfc464208d.tar.xz
kernel-a08dbf62d8dedd6501743598f5a3c4bfc464208d.zip
Merge branch 'fmorgner/stateless-fs-drivers' into 'develop'
kernel/fs: rework filesystem subsystem to use stateless drivers See merge request teachos/kernel!56
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/kstd/span.hpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/libs/kstd/kstd/span.hpp b/libs/kstd/kstd/span.hpp
new file mode 100644
index 00000000..6be2eea2
--- /dev/null
+++ b/libs/kstd/kstd/span.hpp
@@ -0,0 +1,57 @@
+#ifndef KSTD_SPAN_HPP
+#define KSTD_SPAN_HPP
+
+#include <cstddef>
+#include <ranges>
+#include <span> // IWYU pragma: export
+
+namespace kstd
+{
+
+ //! Get a read-only span of bytes, that maps to a given object
+ //!
+ //! @param object The object to obtain the byte span for.
+ //! @return A span over the raw bytes of the object representation of the given object.
+ template<typename ObjectType>
+ requires(!std::ranges::range<ObjectType>)
+ constexpr auto raw_bytes(ObjectType const & object) -> std::span<std::byte const, sizeof(ObjectType)>
+ {
+ return std::as_bytes(std::span<ObjectType const, 1>{std::addressof(object), 1});
+ }
+
+ //! Get a read-write span of bytes, that maps to a given object
+ //!
+ //! @param object The object to obtain the byte span for.
+ //! @return A span over the raw bytes of the object representation of the given object.
+ template<typename ObjectType>
+ requires(!std::ranges::range<ObjectType>)
+ constexpr auto raw_bytes(ObjectType & object) -> std::span<std::byte, sizeof(ObjectType)>
+ {
+ return std::as_writable_bytes(std::span<ObjectType, 1>{std::addressof(object), 1});
+ }
+
+ //! Get a read-only span of bytes, that maps to a given range object
+ //!
+ //! @param range The range of objects to obtain the byte span for.
+ //! @return A span over the raw bytes of the object representation of the given object.
+ template<typename ObjectType>
+ requires(std::ranges::range<ObjectType>)
+ constexpr auto raw_bytes(ObjectType const & range) -> std::span<std::byte const>
+ {
+ return std::as_bytes(std::span{range});
+ }
+
+ //! Get a read-write span of bytes, that maps to a given range object
+ //!
+ //! @param range The range of objects to obtain the byte span for.
+ //! @return A span over the raw bytes of the object representation of the given object.
+ template<typename ObjectType>
+ requires(std::ranges::range<ObjectType>)
+ constexpr auto raw_bytes(ObjectType & range) -> std::span<std::byte>
+ {
+ return std::as_writable_bytes(std::span{range});
+ }
+
+} // namespace kstd
+
+#endif \ No newline at end of file