aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/kstd/asm_ptr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/kstd/asm_ptr.hpp')
-rw-r--r--libs/kstd/kstd/asm_ptr.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/libs/kstd/kstd/asm_ptr.hpp b/libs/kstd/kstd/asm_ptr.hpp
new file mode 100644
index 00000000..c06a8b52
--- /dev/null
+++ b/libs/kstd/kstd/asm_ptr.hpp
@@ -0,0 +1,78 @@
+#ifndef KSTD_ASM_POINTER_HPP
+#define KSTD_ASM_POINTER_HPP
+
+#include <bit>
+#include <cstddef>
+
+namespace kstd
+{
+
+ /**
+ * @brief A pointer that is defined in some assembly source file.
+ *
+ * @tparam Type The type of the pointer
+ */
+ template<typename Type>
+ struct asm_ptr
+ {
+ using value_type = Type;
+ using pointer = value_type *;
+ using const_pointer = value_type const *;
+ using reference = value_type &;
+ using const_reference = value_type const &;
+
+ asm_ptr() = delete;
+ asm_ptr(asm_ptr const &) = delete;
+ asm_ptr(asm_ptr &&) = delete;
+ ~asm_ptr() = delete;
+
+ constexpr auto operator=(asm_ptr const &) = delete;
+ constexpr auto operator=(asm_ptr &&) = delete;
+
+ auto get() const noexcept -> pointer
+ {
+ return m_ptr;
+ }
+
+ constexpr auto operator+(std::ptrdiff_t offset) const noexcept -> pointer
+ {
+ return std::bit_cast<pointer>(m_ptr) + offset;
+ }
+
+ constexpr auto operator*() noexcept -> reference
+ {
+ return *(std::bit_cast<pointer>(m_ptr));
+ }
+
+ constexpr auto operator*() const noexcept -> const_reference
+ {
+ return *(std::bit_cast<const_pointer>(m_ptr));
+ }
+
+ constexpr auto operator[](std::ptrdiff_t offset) noexcept -> reference
+ {
+ return *(*this + offset);
+ }
+
+ constexpr auto operator[](std::ptrdiff_t offset) const noexcept -> const_reference
+ {
+ return *(*this + offset);
+ }
+
+ constexpr auto operator->() noexcept -> pointer
+ {
+ return m_ptr;
+ }
+
+ constexpr auto operator->() const noexcept -> const_pointer
+ {
+ return m_ptr;
+ }
+
+ private:
+ pointer m_ptr;
+ };
+
+} // namespace kstd
+
+#endif \ No newline at end of file