Skip to content

Commit

Permalink
GeneralUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Giganticus committed Sep 27, 2024
1 parent 902b3b8 commit 68d92c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions PTD/PTUtils/include/GeneralUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "syati.h"

namespace pt {
template<typename R>
R* accessMember(void* ptr, size_t offset);
void* accessMember(void* ptr, size_t offset);
template<typename R>
const R* accessMember(const void* ptr, size_t offset);
const void* accessMember(const void* ptr, size_t offset);
};
26 changes: 26 additions & 0 deletions PTD/PTUtils/source/GeneralUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "GeneralUtil.h"

/*
* Authors: Lord-Giganticus
*/

namespace pt {
template<typename R>
R* accessMember(void* ptr, size_t offset) {
u8* p = static_cast<u8*>(ptr);
return static_cast<R*>(&p[offset]);
}
void* accessMember(void* ptr, size_t offset) {
u8* p = static_cast<u8*>(ptr);
return static_cast<void*>(&p[offset]);
}
template <typename R>
const R* accessMember(const void* ptr, size_t offset) {
const u8* p = static_cast<const u8*>(ptr);
return static_cast<const R*>(&p[offset]);
}
const void* accessMember(const void* ptr, size_t offset) {
const u8* p = static_cast<const u8*>(ptr);
return static_cast<const void*>(&p[offset]);
}
};

0 comments on commit 68d92c0

Please sign in to comment.