mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-14 01:59:34 +01:00
Make PSPPointer behave more like a pointer.
This commit is contained in:
1 parent
af940df872
commit
bc149a27a1
1 file changed
+104
-3
+104
-3
@@ -269,17 +269,82 @@ struct PSPPointer
|
||||
{
|
||||
u32 ptr;
|
||||
|
||||
T &operator*() const
|
||||
inline T &operator*() const
|
||||
{
|
||||
return *(T *)(Memory::base + ptr);
|
||||
}
|
||||
|
||||
T &operator[](int i) const
|
||||
inline T &operator[](int i) const
|
||||
{
|
||||
return *((T *)(Memory::base + ptr) + i);
|
||||
}
|
||||
|
||||
T *operator->() const
|
||||
inline T *operator->() const
|
||||
{
|
||||
return (T *)(Memory::base + ptr);
|
||||
}
|
||||
|
||||
inline PSPPointer<T> operator+(int i) const
|
||||
{
|
||||
PSPPointer other;
|
||||
other.ptr = ptr + i * sizeof(T);
|
||||
return other;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> &operator=(u32 p)
|
||||
{
|
||||
ptr = p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> &operator+=(int i)
|
||||
{
|
||||
ptr = ptr + i * sizeof(T);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> operator-(int i) const
|
||||
{
|
||||
PSPPointer other;
|
||||
other.ptr = ptr - i * sizeof(T);
|
||||
return other;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> &operator-=(int i)
|
||||
{
|
||||
ptr = ptr - i * sizeof(T);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> &operator++()
|
||||
{
|
||||
ptr += sizeof(T);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> operator++(int i)
|
||||
{
|
||||
PSPPointer<T> other;
|
||||
other.ptr = ptr;
|
||||
ptr += sizeof(T);
|
||||
return other;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> &operator--()
|
||||
{
|
||||
ptr -= sizeof(T);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline PSPPointer<T> operator--(int i)
|
||||
{
|
||||
PSPPointer<T> other;
|
||||
other.ptr = ptr;
|
||||
ptr -= sizeof(T);
|
||||
return other;
|
||||
}
|
||||
|
||||
inline operator T*()
|
||||
{
|
||||
return (T *)(Memory::base + ptr);
|
||||
}
|
||||
@@ -290,5 +355,41 @@ struct PSPPointer
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const PSPPointer<T> &lhs, const PSPPointer<T> &rhs)
|
||||
{
|
||||
return lhs.ptr == rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(const PSPPointer<T> &lhs, const PSPPointer<T> &rhs)
|
||||
{
|
||||
return lhs.ptr != rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<(const PSPPointer<T> &lhs, const PSPPointer<T> &rhs)
|
||||
{
|
||||
return lhs.ptr < rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator>(const PSPPointer<T> &lhs, const PSPPointer<T> &rhs)
|
||||
{
|
||||
return lhs.ptr > rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<=(const PSPPointer<T> &lhs, const PSPPointer<T> &rhs)
|
||||
{
|
||||
return lhs.ptr <= rhs.ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator>=(const PSPPointer<T> &lhs, const PSPPointer<T> &rhs)
|
||||
{
|
||||
return lhs.ptr >= rhs.ptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user