36 lines
1010 B
C++
36 lines
1010 B
C++
#pragma once
|
|
#include "type.h"
|
|
namespace refl {
|
|
class UClass;
|
|
struct Any;
|
|
template<typename T>
|
|
concept is_not_any_v = !std::is_same_v<args_type_t<T>, Any>;
|
|
struct Any {
|
|
public:
|
|
const void* ptr;
|
|
const UClass* cls;
|
|
public:
|
|
constexpr Any() noexcept: ptr(nullptr), cls(nullptr) {}
|
|
constexpr Any(const void* ptr, const UClass* cls) noexcept : ptr(ptr), cls(cls) {}
|
|
template<is_not_any_v T>
|
|
constexpr Any(T&& v) noexcept : ptr(&v), cls(&TypeInfo<args_type_t<T>>::StaticClass) {}
|
|
template<is_not_any_v T>
|
|
constexpr Any(T* v) noexcept : ptr(v), cls(&TypeInfo<args_type_t<T>>::StaticClass) {}
|
|
template<typename T>//参数 T* => T*
|
|
constexpr inline T CastTo() const {
|
|
if constexpr (std::is_pointer_v<T>) {
|
|
return (T)ptr;
|
|
}
|
|
else if constexpr (std::is_reference_v<T>) {
|
|
using RT = std::remove_reference_t<T>;
|
|
return *(RT*)ptr;
|
|
}
|
|
else {
|
|
return *(T*)ptr;
|
|
}
|
|
}
|
|
public:
|
|
operator bool()const { return cls && ptr; }
|
|
bool Check(const UClass* parent) const;
|
|
};
|
|
} |