geode/loader/test/members/Common.hpp

42 lines
1.7 KiB
C++
Raw Normal View History

2022-12-30 14:13:45 -05:00
#pragma once
#include <Geode/Bindings.hpp>
2023-12-20 10:43:48 -05:00
template <auto V1, auto V2, auto V3, class... Types>
2022-12-30 14:13:45 -05:00
struct False {
static constexpr auto value = false;
};
template<int Difference, int Expected, int Current, class Class, class Member, bool Predicate>
2022-12-30 14:13:45 -05:00
struct MemberIsOffsetBy {
2023-12-20 10:43:48 -05:00
static_assert(False<Difference, Expected, Current, Class, Member>::value, "Member is offset by this value (Difference, Expected, Current, Class, Member)");
2022-12-30 14:13:45 -05:00
};
template<int Difference, int Expected, int Current, class Class, bool Predicate>
struct SizeIsOffsetBy {
2023-12-20 10:43:48 -05:00
static_assert(False<Difference, Expected, Current, Class>::value, "Size is offset by this value (Difference, Expected, Current, Class)");
};
template<int Difference, int Expected, int Current, class Class, class Member>
2023-12-20 10:43:48 -05:00
struct MemberIsOffsetBy<Difference, Expected, Current, Class, Member, true> {
2022-12-30 14:13:45 -05:00
};
template<int Difference, int Expected, int Current, class Class>
2023-12-20 10:43:48 -05:00
struct SizeIsOffsetBy<Difference, Expected, Current, Class, true> {
};
2022-12-30 14:13:45 -05:00
template <class Member, class Class, int Offset, int Expected>
struct SingleMemberChecker {
using IsOffsetBy = MemberIsOffsetBy<Offset - Expected, Expected, Offset, Class, Member, Expected == Offset>;
};
template <class Class, int Offset, int Expected>
struct SingleSizeChecker {
2023-12-20 10:43:48 -05:00
using IsOffsetBy = SizeIsOffsetBy<Offset - Expected, Expected, Offset, Class, Expected == Offset>;
2022-12-30 14:13:45 -05:00
};
#define GEODE_MEMBER_CHECK(Class_, Member_, Offset_) class Member_; SingleMemberChecker<Member_, Class_, offsetof(Class_, Member_), Offset_>::IsOffsetBy GEODE_CONCAT(OffsetBy, __LINE__)
2023-12-20 10:43:48 -05:00
#define GEODE_SIZE_CHECK(Class_, Offset_) SingleSizeChecker<Class_, sizeof(Class_), Offset_>::IsOffsetBy GEODE_CONCAT(OffsetBy, __LINE__)