1/*
2 * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _BYTE_POINTER_H
6#define _BYTE_POINTER_H
7
8
9#include <stdlib.h>
10
11
12// Behaves like a char* pointer, but -> and & return the right pointed type.
13// Assumes the offsets passed to + and += maintain the alignment for the type.
14template<class T> struct BytePointer {
15	char* address;
16
17	BytePointer(void* base) { address = (char*)base; }
18
19	T* operator&() { return reinterpret_cast<T*>(address); }
20	T* operator->() { return reinterpret_cast<T*>(address); }
21	void operator+=(size_t offset) { address += offset; }
22	char* operator+(size_t offset) const { return address + offset; }
23};
24
25
26#endif
27