1#ifndef COASTLINE_PTR32_H
2#define COASTLINE_PTR32_H
13#if defined(TGR_PLATFORM) && TGR_PLATFORM == TGR_PLATFORM_SDL && defined(__cplusplus)
24extern const unsigned char g_abPtr32Anchor[];
37inline std::uint32_t EncodePtr32(
const volatile void *address) {
38 if (address ==
nullptr) {
41 return static_cast<std::uint32_t
>(
42 static_cast<std::int32_t
>(
reinterpret_cast<std::intptr_t
>(address) -
43 reinterpret_cast<std::intptr_t
>(g_abPtr32Anchor)));
52inline void *DecodePtr32(std::uint32_t offset) {
56 return reinterpret_cast<void *
>(
reinterpret_cast<std::uintptr_t
>(g_abPtr32Anchor) +
57 static_cast<std::int32_t
>(offset));
71 Ptr32 &operator=(T *pointer) {
72 m_offset = EncodePtr32(pointer);
78 Ptr32 &operator=(std::nullptr_t) {
84 operator T *()
const {
85 return static_cast<T *
>(DecodePtr32(m_offset));
88 T *operator->()
const {
92 template <
typename U = T>
94 U &
operator*()
const {
95 return *
static_cast<T *
>(*this);
101 template <
typename U = T>
103 U &
operator[](std::ptrdiff_t index)
const {
104 return static_cast<T *
>(*this)[index];
109 Ptr32 &operator++() {
110 *
this =
static_cast<T *
>(*this) + 1;
116 Ptr32 operator++(
int) {
125 Ptr32 &operator+=(std::ptrdiff_t count) {
126 *
this =
static_cast<T *
>(*this) +
count;
131 std::uint32_t Raw()
const {
136 void SetRaw(std::uint32_t offset) {
140 std::uint32_t m_offset;
147#define TGR_PTR(T) coastline::Ptr32<T>
152#define TGR_PTR(T) T *
Definition assetimport.h:11