-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmemhelp.h
42 lines (34 loc) · 991 Bytes
/
memhelp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// libembryo
//
// Copyright Stanley Cen 2013
// Released under the MIT License
//
#ifndef libembryo_memhelp_h
#define libembryo_memhelp_h
#include "stddef.h"
namespace embryo
{
inline void **&getvtable(void *inst, size_t offset =0)
{
return *reinterpret_cast<void ***>((size_t)inst + offset);
}
inline const void **getvtable(const void *inst, size_t offset = 0)
{
return *reinterpret_cast<const void ***>((size_t)inst + offset);
}
template<typename Fn>
inline Fn getvfunc(const void *inst, size_t index, size_t offset = 0)
{
return reinterpret_cast<Fn>(const_cast<void *>(getvtable(inst, offset)[index]));
}
template<typename T> inline T *makeptr(void *ptr, int offset)
{
return reinterpret_cast<T *>((size_t)ptr + offset);
}
template<typename T> inline T *makeptr(unsigned int ptr, int offset)
{
return reinterpret_cast<T *>((size_t)ptr + offset);
}
}
#endif