diff --git a/headers/private/shared/BytePointer.h b/headers/private/shared/BytePointer.h new file mode 100644 index 0000000000..62038f820d --- /dev/null +++ b/headers/private/shared/BytePointer.h @@ -0,0 +1,26 @@ +/* + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ +#ifndef _BYTE_POINTER_H +#define _BYTE_POINTER_H + + +#include + + +// Behaves like a char* pointer, but -> and & return the right pointed type. +// Assumes the offsets passed to + and += maintain the alignment for the type. +template struct BytePointer { + char* address; + + BytePointer(void* base) { address = (char*)base; } + + T* operator&() { return reinterpret_cast(address); } + T* operator->() { return reinterpret_cast(address); } + void operator+=(size_t offset) { address += offset; } + char* operator+(size_t offset) const { return address + offset; } +}; + + +#endif