]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Refactored phys_ptr and fixed little errors
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Thu, 12 May 2022 11:20:38 +0000 (13:20 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Thu, 12 May 2022 11:20:38 +0000 (13:20 +0200)
src/phys_ptr.hpp

index 1e5cb35fd73176bb507e91125b165dfdc9ebe273..5fe43be5c50f463a48a00f2c9ea1243fa72e99b1 100644 (file)
@@ -23,33 +23,28 @@ public:
        }
 
        constexpr phys_ptr<T>& operator++() {
-               phys_addr += sizeof(T);
+               return *this += 1;
        }
-       constexpr phys_ptr<T>& operator++(int) {
+       constexpr phys_ptr<T> operator++(int) {
                const auto old = *this;
                operator++();
                return old;
        }
        constexpr phys_ptr<T>& operator--() {
-               phys_addr -= sizeof(T);
+               return *this -= 1;
        }
-       constexpr phys_ptr<T>& operator--(int) {
+       constexpr phys_ptr<T> operator--(int) {
                const auto old = *this;
                operator--();
                return old;
        }
        constexpr phys_ptr<T>& operator+=(std::ptrdiff_t offset) {
-               phys_addr += offset * sizeof(T);
-               return *this;
+               return *this = *this + offset;
        }
        constexpr phys_ptr<T>& operator-=(std::ptrdiff_t offset) {
-               phys_addr -= offset * sizeof(T);
-               return *this;
+               return *this = *this - offset;
        }
 
-       friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) { return    a.phys_addr <=> b.phys_addr;    }
-       friend constexpr auto operator== (phys_ptr<T> a, phys_ptr<T> b) { return    a.phys_addr ==  b.phys_addr;    }
-
        friend constexpr phys_ptr<T> operator+(phys_ptr<T> ptr, std::ptrdiff_t offset) {
                return phys_ptr<T>{ptr.phys_addr + offset * sizeof(T)};
        }
@@ -67,6 +62,8 @@ public:
                return phys_addr;
        }
 
+       friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) = default;
+
 private:
        T* get_virt_addr() const {
                return reinterpret_cast<T*>(phys_addr + 0xFFFF800000000000);