From: Amelia Coutard Date: Thu, 12 May 2022 11:20:38 +0000 (+0200) Subject: Refactored phys_ptr and fixed little errors X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=a30e3c6bebd08254c7ef869561f9d6d20cdea2c0;p=voyage-au-centre-des-fichiers.git Refactored phys_ptr and fixed little errors --- diff --git a/src/phys_ptr.hpp b/src/phys_ptr.hpp index 1e5cb35..5fe43be 100644 --- a/src/phys_ptr.hpp +++ b/src/phys_ptr.hpp @@ -23,33 +23,28 @@ public: } constexpr phys_ptr& operator++() { - phys_addr += sizeof(T); + return *this += 1; } - constexpr phys_ptr& operator++(int) { + constexpr phys_ptr operator++(int) { const auto old = *this; operator++(); return old; } constexpr phys_ptr& operator--() { - phys_addr -= sizeof(T); + return *this -= 1; } - constexpr phys_ptr& operator--(int) { + constexpr phys_ptr operator--(int) { const auto old = *this; operator--(); return old; } constexpr phys_ptr& operator+=(std::ptrdiff_t offset) { - phys_addr += offset * sizeof(T); - return *this; + return *this = *this + offset; } constexpr phys_ptr& operator-=(std::ptrdiff_t offset) { - phys_addr -= offset * sizeof(T); - return *this; + return *this = *this - offset; } - friend constexpr auto operator<=>(phys_ptr a, phys_ptr b) { return a.phys_addr <=> b.phys_addr; } - friend constexpr auto operator== (phys_ptr a, phys_ptr b) { return a.phys_addr == b.phys_addr; } - friend constexpr phys_ptr operator+(phys_ptr ptr, std::ptrdiff_t offset) { return phys_ptr{ptr.phys_addr + offset * sizeof(T)}; } @@ -67,6 +62,8 @@ public: return phys_addr; } + friend constexpr auto operator<=>(phys_ptr a, phys_ptr b) = default; + private: T* get_virt_addr() const { return reinterpret_cast(phys_addr + 0xFFFF800000000000);