zengine-old/engine/3rdparty/zlib/include/refl/detail/field.h

98 lines
2.4 KiB
C
Raw Normal View History

2024-04-03 17:58:02 +08:00
#pragma once
#include "UTemplate/Type.hpp"
#include <variant>
#include <functional>
using Ubpa::Name;
using Ubpa::type_name;
namespace refl {
class UClass;
2024-04-09 16:31:09 +08:00
class ArgsView;
2024-04-06 23:50:17 +08:00
using Offset = uint32_t;
2024-04-13 17:47:44 +08:00
using Method = void*;
2024-04-09 16:31:09 +08:00
using DefaultMember = const ArgsView (*)();
using DefaultMethod = std::pair<ArgsView*, int>(*)();
2024-04-05 16:03:58 +08:00
enum FieldFlag:uint32_t {
2024-04-09 16:31:09 +08:00
FIELD_NONE_FLAG = 0,
FIELD_MEMBER_FLAG = 1 << 0,
FIELD_ATTRIBUTE_FLAG = 1 << 1,
FIELD_METHOD_FLAG = 1 << 2,
FIELD_METHOD_VALUE_FLAG = 1 << 3
2024-04-05 16:03:58 +08:00
};
2024-04-03 17:58:02 +08:00
struct FieldPtr {
2024-04-09 16:31:09 +08:00
union Data
{
Offset offset;
Method method;
2024-04-13 17:47:44 +08:00
constexpr Data() : method(nullptr) {}
constexpr Data(Offset& offset) : offset(offset) {}
constexpr Data(Method& method) : method(method) {}
constexpr Data(const Method& method) : method(method) {}
2024-04-09 16:31:09 +08:00
};
union Default {
DefaultMember member;
DefaultMethod method;
2024-04-13 17:47:44 +08:00
constexpr Default(): method(nullptr) {}
constexpr Default(DefaultMember& member) : member(member) {}
constexpr Default(DefaultMethod& method) : method(method) {}
2024-04-09 16:31:09 +08:00
};
2024-04-03 17:58:02 +08:00
Name name;
2024-04-13 17:47:44 +08:00
const UClass* type{};
Data data{};
Default value{};
uint32_t flag{};
2024-04-11 10:13:15 +08:00
//safe
bool Invoke(std::vector<ArgsView>& ArgsList)const;
//unsafe
bool Invoke(const std::vector<ArgsView>& ArgsList)const;
std::vector<const UClass*> GetParams() const;
2024-04-03 17:58:02 +08:00
};
2024-04-13 17:47:44 +08:00
/*
template<typename T, typename V>
consteval V* fetch_member_v(V T::*) {
return nullptr;
}
template<typename R, typename T, typename ...Args>
consteval auto fetch_method_v(R (T::* ptr)(Args...)) {
using MethodType = R(*)(T*, Args...);
return MethodType{nullptr};
}
template<typename R, typename ...Args>
consteval auto fetch_method_v(R(*ptr)(Args...)) {
return ptr;
}
template<typename... Args>
consteval auto FetchMembers(const std::tuple<Args...>&) {
return std::make_tuple(fetch_member_v(Args{nullptr})...);
}
template<typename... Args>
consteval auto FetchMethods(const std::tuple<Args...>&) {
return std::make_tuple(fetch_method_v(Args{ nullptr })...);
}
template<typename ...Args>
class FieldMembers{
public:
constexpr FieldMembers() {}
FieldMembers(const std::tuple<Args*...>&) {
2024-04-09 16:31:09 +08:00
2024-04-13 17:47:44 +08:00
}
constexpr static int GetSize() {
return sizeof...(Args);
}
};
template<typename ...Args>
class FieldMethods{
public:
constexpr FieldMethods() {}
FieldMethods(const std::tuple<Args*...>&) {
}
constexpr static int GetSize() {
return sizeof...(Args);
}
};*/
2024-04-03 17:58:02 +08:00
}