mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-27 01:45:35 -05:00
use std::enable_if for create checking
This commit is contained in:
parent
68e75eafb5
commit
4aa09c085b
2 changed files with 27 additions and 19 deletions
|
@ -112,6 +112,7 @@ class GeodeNodeMetadata;
|
|||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <variant>
|
||||
|
||||
namespace tulip::hook {
|
||||
|
@ -136,7 +137,8 @@ namespace geode {
|
|||
|
||||
namespace addresser {
|
||||
template <class Class>
|
||||
Class* friendCreate();
|
||||
Class* friendCreate(typename std::enable_if_t<
|
||||
std::is_same_v<decltype(&Class::create), Class* (*)()>>*);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +151,9 @@ namespace geode {
|
|||
friend geode::Result<tulip::hook::HandlerMetadata, std::string> \
|
||||
geode::modifier::handlerMetadataForAddress(uintptr_t address); \
|
||||
template <class Class> \
|
||||
friend Class* geode::addresser::friendCreate();
|
||||
friend Class* \
|
||||
geode::addresser::friendCreate(typename std::enable_if_t< \
|
||||
std::is_same_v<decltype(&Class::create), Class* (*)()>>*);
|
||||
|
||||
#define GEODE_ADD(...) __VA_ARGS__
|
||||
|
||||
|
@ -168,9 +172,9 @@ namespace geode {
|
|||
@param varType : the type of variable.
|
||||
@param varName : variable name.
|
||||
@param funName : "get + funName" is the name of the getter.
|
||||
@warning : The getter is a public virtual function, you should rewrite it first.
|
||||
The variables and methods declared after CC_PROPERTY_READONLY are all public.
|
||||
If you need protected or private, please declare.
|
||||
@warning : The getter is a public virtual function, you should rewrite
|
||||
it first. The variables and methods declared after CC_PROPERTY_READONLY
|
||||
are all public. If you need protected or private, please declare.
|
||||
*/
|
||||
#define CC_PROPERTY_READONLY(varType, varName, funName) \
|
||||
\
|
||||
|
@ -189,14 +193,16 @@ public: \
|
|||
virtual const varType& get##funName(void);
|
||||
|
||||
/** CC_PROPERTY is used to declare a protected variable.
|
||||
We can use getter to read the variable, and use the setter to change the variable.
|
||||
We can use getter to read the variable, and use the setter to change
|
||||
the variable.
|
||||
@param varType : the type of variable.
|
||||
@param varName : variable name.
|
||||
@param funName : "get + funName" is the name of the getter.
|
||||
"set + funName" is the name of the setter.
|
||||
@warning : The getter and setter are public virtual functions, you should rewrite them first.
|
||||
The variables and methods declared after CC_PROPERTY are all public.
|
||||
If you need protected or private, please declare.
|
||||
@warning : The getter and setter are public virtual functions, you
|
||||
should rewrite them first. The variables and methods declared after
|
||||
CC_PROPERTY are all public. If you need protected or private, please
|
||||
declare.
|
||||
*/
|
||||
#define CC_PROPERTY(varType, varName, funName) \
|
||||
\
|
||||
|
@ -226,8 +232,8 @@ public: \
|
|||
@param varName : variable name.
|
||||
@param funName : "get + funName" is the name of the getter.
|
||||
@warning : The getter is a public inline function.
|
||||
The variables and methods declared after CC_SYNTHESIZE_READONLY are all public.
|
||||
If you need protected or private, please declare.
|
||||
The variables and methods declared after CC_SYNTHESIZE_READONLY are all
|
||||
public. If you need protected or private, please declare.
|
||||
*/
|
||||
#define CC_SYNTHESIZE_READONLY(varType, varName, funName) \
|
||||
\
|
||||
|
|
|
@ -28,12 +28,14 @@ namespace geode::addresser {
|
|||
inline F rthunkAdjust(T func, F self);
|
||||
|
||||
template <class Class>
|
||||
Class* friendCreate() {
|
||||
Class* friendCreate(typename std::enable_if_t<std::is_same_v<decltype(&Class::create), Class* (*)()>>*) {
|
||||
return Class::create();
|
||||
}
|
||||
|
||||
template <class Class>
|
||||
concept HasCreate = requires() { friendCreate<Class>(); };
|
||||
concept HasCreate = requires() {
|
||||
{ friendCreate<Class>(nullptr) } -> std::same_as<Class*>;
|
||||
};
|
||||
|
||||
class GEODE_DLL Addresser final {
|
||||
template <char C>
|
||||
|
@ -74,7 +76,7 @@ namespace geode::addresser {
|
|||
// I gave up
|
||||
template <HasCreate Class>
|
||||
static Class* generateInstance() {
|
||||
return friendCreate<Class>();
|
||||
return friendCreate<Class>(nullptr);
|
||||
}
|
||||
|
||||
template <class Class>
|
||||
|
|
Loading…
Reference in a new issue