2022-07-30 12:24:03 -04:00
|
|
|
#pragma once
|
2022-09-28 17:49:59 -04:00
|
|
|
#include "../utils/addresser.hpp"
|
2022-10-30 14:59:20 -04:00
|
|
|
#include "Traits.hpp"
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
#define GEODE_WRAPPER_FOR_IDENTIFIER(identifier) \
|
|
|
|
/* Default - function Return Class::identifier(Parameters...) does not exist */ \
|
|
|
|
template <class Class, class FunctionType, class = void> \
|
|
|
|
struct identifier { \
|
|
|
|
public: \
|
|
|
|
constexpr static inline auto value = nullptr; \
|
|
|
|
constexpr static inline auto uuid = nullptr; \
|
|
|
|
}; \
|
|
|
|
/* Specialization - function Return Class::identifier(Parameters...) is a member function */ \
|
|
|
|
template <class Class, class Return, class... Parameters> \
|
|
|
|
struct identifier< \
|
|
|
|
Class, Return(Parameters...), \
|
|
|
|
std::enable_if_t<std::is_member_function_pointer_v< \
|
|
|
|
decltype(substitute<Return(Parameters...)>(&Class::identifier))>>> { \
|
|
|
|
private: \
|
|
|
|
static Return wrapperImpl(Class* self, Parameters... ps) { \
|
|
|
|
self = addresser::rthunkAdjust( \
|
|
|
|
substitute<Return(Parameters...)>(&Class::identifier), self \
|
|
|
|
); \
|
|
|
|
return self->Class::identifier(ps...); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
constexpr static inline auto value = &wrapperImpl; \
|
|
|
|
constexpr static inline auto uuid = \
|
2022-12-12 10:42:56 -05:00
|
|
|
FunctionUUID<substitute<Return(Parameters...)>(&Class::identifier)>::value; \
|
2022-10-30 14:59:20 -04:00
|
|
|
}; \
|
|
|
|
/* Specialization - function Return Class::identifier(Parameters...) is a static function */ \
|
|
|
|
template <class Class, class Return, class... Parameters> \
|
|
|
|
struct identifier< \
|
|
|
|
Class, Return(Parameters...), \
|
|
|
|
std::enable_if_t< \
|
|
|
|
std::is_pointer_v<decltype(substitute<Return(Parameters...)>(&Class::identifier))>>> { \
|
|
|
|
private: \
|
|
|
|
static Return wrapperImpl(Parameters... ps) { \
|
|
|
|
return Class::identifier(ps...); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
constexpr static inline auto value = &wrapperImpl; \
|
|
|
|
constexpr static inline auto uuid = \
|
2022-12-12 10:42:56 -05:00
|
|
|
FunctionUUID<substitute<Return(Parameters...)>(&Class::identifier)>::value; \
|
2022-10-30 14:59:20 -04:00
|
|
|
};
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
namespace geode::modifier {
|
2022-10-30 14:59:20 -04:00
|
|
|
namespace wrap {
|
|
|
|
GEODE_WRAPPER_FOR_IDENTIFIER(constructor)
|
|
|
|
GEODE_WRAPPER_FOR_IDENTIFIER(destructor)
|
|
|
|
};
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
// template <template<class, class, class=void> class Identifier, class Base, class Derived,
|
|
|
|
// class ...Types> struct PotentiallyWrongIdentifier {
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
// template <typename D>
|
|
|
|
// static std::true_type existsImpl(...);
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
// template <typename D, typename = std::enable_if_t<
|
|
|
|
// (... && (
|
|
|
|
// Identifier<D, Types>::uuid == nullptr ||
|
|
|
|
// Identifier<Base, Types>::uuid == Identifier<D, Types>::uuid
|
|
|
|
// ))
|
|
|
|
// >>
|
|
|
|
// static std::false_type existsImpl(char);
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
// template <typename D, typename = std::enable_if_t<
|
|
|
|
// (... || (
|
|
|
|
// Identifier<D, Types>::uuid != nullptr &&
|
|
|
|
// Identifier<Base, Types>::uuid == Identifier<D, Types>::uuid
|
|
|
|
// ))
|
|
|
|
// >>
|
|
|
|
// static std::false_type existsImpl(int);
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
// static constexpr bool value = decltype(existsImpl<Derived>(0))::value;
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2022-10-30 14:59:20 -04:00
|
|
|
// };
|
2022-07-30 12:24:03 -04:00
|
|
|
|
|
|
|
}
|