yaml try support vector map
This commit is contained in:
parent
74ccd12aa4
commit
ead02af962
2
engine/3rdparty/zlib/include/meta/tuple.h
vendored
2
engine/3rdparty/zlib/include/meta/tuple.h
vendored
@ -30,7 +30,7 @@ namespace meta
|
|||||||
return Index; // 找到匹配的类型,返回当前索引
|
return Index; // 找到匹配的类型,返回当前索引
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return index_in_tuple<T, Tuple, Index + 1>(); // 递归检8查下一个索引
|
return index_in_tuple<T, Tuple, Index + 1>(); // 递归检查下一个索引
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#include "type.h"
|
#include "type.h"
|
||||||
namespace refl {
|
namespace refl {
|
||||||
class UClass;
|
class UClass;
|
||||||
|
class Container;
|
||||||
class FieldPtr;
|
class FieldPtr;
|
||||||
//生命周期短,适用于传参,不建议保存数据
|
//生命周期短,适用于传参,不建议保存数据
|
||||||
//只能指向指针,引用=>指针,指针=>指针,T => T*,T的类型丢失
|
//只能指向指针,引用=>指针,指针=>指针,T => T*,T的类型丢失
|
||||||
@ -53,9 +54,14 @@ namespace refl {
|
|||||||
}
|
}
|
||||||
Any Member(const FieldPtr& field)const;
|
Any Member(const FieldPtr& field)const;
|
||||||
Any Member(int i)const;
|
Any Member(int i)const;
|
||||||
|
Container ToContainer()const;
|
||||||
int ArraySize()const;
|
int ArraySize()const;
|
||||||
bool IsArray()const;
|
bool IsArray()const;
|
||||||
bool IsObject()const;
|
bool IsObject()const;
|
||||||
|
bool IsContainer()const;
|
||||||
|
bool IsSequence()const;
|
||||||
|
bool IsMap()const;
|
||||||
bool Construct(const zstd::sarray<Any>& ArgsList)const;
|
bool Construct(const zstd::sarray<Any>& ArgsList)const;
|
||||||
|
void Destruct()const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
79
engine/3rdparty/zlib/include/refl/detail/container.inl
vendored
Normal file
79
engine/3rdparty/zlib/include/refl/detail/container.inl
vendored
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "refl/detail/uclass.inl"
|
||||||
|
#include <iostream>
|
||||||
|
namespace refl {
|
||||||
|
class Container {
|
||||||
|
const void* ptr;
|
||||||
|
const UClass_Container* cls;
|
||||||
|
friend class Any;
|
||||||
|
Container(const void* ptr, const UClass_Container* cls) :ptr(ptr), cls(cls) {}
|
||||||
|
public:
|
||||||
|
void construct() {
|
||||||
|
cls->Construct((void*)ptr);
|
||||||
|
}
|
||||||
|
void destruct() {
|
||||||
|
cls->Destruct((void*)ptr);
|
||||||
|
}
|
||||||
|
Any malloc_any() {
|
||||||
|
void* ptr = malloc(cls->parent->size);
|
||||||
|
return { ptr, cls->parent };
|
||||||
|
}
|
||||||
|
void insert(const Any& any) {
|
||||||
|
if(any.cls == cls->parent)
|
||||||
|
cls->vinsert(ptr, any.ptr);
|
||||||
|
}
|
||||||
|
int size() {
|
||||||
|
return cls->vsize(ptr);
|
||||||
|
}
|
||||||
|
auto begin() {
|
||||||
|
auto it = cls->vbegin(ptr);
|
||||||
|
return iterator(it, cls);
|
||||||
|
}
|
||||||
|
auto end() {
|
||||||
|
auto it = cls->vend(ptr);
|
||||||
|
return iterator(it, cls);
|
||||||
|
}
|
||||||
|
// Iterator class
|
||||||
|
class iterator : public UClass_Container::iterator{
|
||||||
|
private:
|
||||||
|
const UClass_Container* cls;
|
||||||
|
public:
|
||||||
|
iterator(UClass_Container::iterator it,const UClass_Container* cls)
|
||||||
|
: UClass_Container::iterator(it), cls(cls) {}
|
||||||
|
iterator& operator++() noexcept {
|
||||||
|
cls->viterator_add(this);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator++(int) noexcept {
|
||||||
|
iterator tmp = *this;
|
||||||
|
cls->viterator_add(this);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
iterator& operator--() noexcept {
|
||||||
|
cls->viterator_sub(this);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
iterator operator--(int) noexcept {
|
||||||
|
iterator tmp = *this;
|
||||||
|
cls->viterator_sub(this);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
Any operator->() noexcept {
|
||||||
|
return { val , cls->parent };
|
||||||
|
}
|
||||||
|
Any operator*() noexcept {
|
||||||
|
return { val , cls->parent };
|
||||||
|
}
|
||||||
|
constexpr bool operator!=(const iterator& other) const noexcept {
|
||||||
|
return cls != other.cls || ptr != other.ptr;
|
||||||
|
}
|
||||||
|
constexpr bool operator==(const iterator& other) const noexcept {
|
||||||
|
return ptr == other.ptr && cls == other.cls;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
inline Container refl::Any::ToContainer() const
|
||||||
|
{
|
||||||
|
return Container{ptr, (const UClass_Container*)cls};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,7 +28,7 @@ namespace refl {
|
|||||||
}
|
}
|
||||||
inline bool Convert::Construct(Any& dst, const Any& src)
|
inline bool Convert::Construct(Any& dst, const Any& src)
|
||||||
{
|
{
|
||||||
if (dst.cls->CtorObject((void*)dst.ptr, src)) {
|
if (dst.cls->Construct((void*)dst.ptr, src)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto it = ClassMap.find(dst.cls);
|
auto it = ClassMap.find(dst.cls);
|
||||||
|
|||||||
25
engine/3rdparty/zlib/include/refl/detail/type.h
vendored
25
engine/3rdparty/zlib/include/refl/detail/type.h
vendored
@ -24,11 +24,14 @@ namespace refl {
|
|||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
struct is_array<T[N]> : std::true_type {
|
struct is_array<T[N]> : std::true_type {
|
||||||
using type = T;
|
using type = T;
|
||||||
consteval static size_t Size() {
|
consteval static size_t Size() {return N;}
|
||||||
return N;
|
};
|
||||||
}
|
// 部分特化用于匹配 std::array
|
||||||
|
template<typename T, size_t N>
|
||||||
|
struct is_array<std::array<T, N>> : std::true_type {
|
||||||
|
using type = T;
|
||||||
|
consteval static size_t Size() { return N; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// 定义一个模板结构体用于检测是否为 std::pair
|
// 定义一个模板结构体用于检测是否为 std::pair
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_pair : std::false_type {};
|
struct is_pair : std::false_type {};
|
||||||
@ -39,8 +42,18 @@ namespace refl {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept is_pair_v = is_pair<T>::value;
|
concept is_pair_v = is_pair<T>::value;
|
||||||
|
|
||||||
|
// 定义一个模板结构体用于检测是否为 std::pair
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept is_container_v = requires(T a) {
|
struct is_tuple : std::false_type {};
|
||||||
|
|
||||||
|
template<typename... Types>
|
||||||
|
struct is_tuple<std::tuple<Types...>> : std::true_type {};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept is_tuple_v = is_tuple<T>::value;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept is_container_v = !is_array<T>::value && !std::is_same_v<T, std::string> && requires(T a) {
|
||||||
{ a.begin() } -> std::input_iterator;
|
{ a.begin() } -> std::input_iterator;
|
||||||
{ a.end() } -> std::input_iterator;
|
{ a.end() } -> std::input_iterator;
|
||||||
};
|
};
|
||||||
@ -94,8 +107,6 @@ namespace refl {
|
|||||||
concept _ReflCheck_Ctor = requires { T(); };
|
concept _ReflCheck_Ctor = requires { T(); };
|
||||||
template <class T>
|
template <class T>
|
||||||
concept _ReflCheck_UClass = requires { typename MetaImpl<T>::MyMeta; };
|
concept _ReflCheck_UClass = requires { typename MetaImpl<T>::MyMeta; };
|
||||||
template <class T>
|
|
||||||
concept _ReflCheck_Ctor_NoUClass = _ReflCheck_Ctor<T> && !_ReflCheck_UClass<T>;
|
|
||||||
|
|
||||||
//类型接口
|
//类型接口
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@ -5,10 +5,13 @@
|
|||||||
#include "convert.h"
|
#include "convert.h"
|
||||||
namespace refl {
|
namespace refl {
|
||||||
enum ClassFlag :uint32_t {
|
enum ClassFlag :uint32_t {
|
||||||
CLASS_NONE_FLAG = 0,
|
CLASS_NONE_FLAG = 0,
|
||||||
CLASS_TRIVIAL_FLAG = 1 << 0,
|
CLASS_TRIVIAL_FLAG = 1 << 0,
|
||||||
CLASS_POINTER_FLAG = 1 << 1,
|
CLASS_POINTER_FLAG = 1 << 1,
|
||||||
CLASS_ARRAY_FLAG = 1 << 2,
|
CLASS_ARRAY_FLAG = 1 << 2,
|
||||||
|
CLASS_CONTAINER_FLAG = 1 << 3,
|
||||||
|
CLASS_SEQUENCE_FLAG = 1 << 4,
|
||||||
|
CLASS_MAP_FLAG = 1 << 5,
|
||||||
};
|
};
|
||||||
using enum ClassFlag;
|
using enum ClassFlag;
|
||||||
enum EFieldFind :uint32_t {
|
enum EFieldFind :uint32_t {
|
||||||
@ -32,8 +35,8 @@ namespace refl {
|
|||||||
//meta
|
//meta
|
||||||
const UClass* (*GetMeta)(const Name&);
|
const UClass* (*GetMeta)(const Name&);
|
||||||
//object
|
//object
|
||||||
bool (*CtorObject)(void* ptr,const UClass* cls, const sarray<Any>& ArgsList);
|
bool (*Construct)(void* ptr,const UClass* cls, const sarray<Any>& ArgsList);
|
||||||
bool (*DestObject)(void*);
|
void (*Destruct)(void*);
|
||||||
};
|
};
|
||||||
class UClass{
|
class UClass{
|
||||||
public:
|
public:
|
||||||
@ -48,7 +51,7 @@ namespace refl {
|
|||||||
AnyView New(void* ptr = nullptr, const sarray<Any>& ArgsList = {}) const {
|
AnyView New(void* ptr = nullptr, const sarray<Any>& ArgsList = {}) const {
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
ptr = malloc(size);
|
ptr = malloc(size);
|
||||||
CtorObject(ptr, ArgsList);
|
Construct(ptr, ArgsList);
|
||||||
}
|
}
|
||||||
return { ptr , this };
|
return { ptr , this };
|
||||||
}
|
}
|
||||||
@ -61,7 +64,7 @@ namespace refl {
|
|||||||
ptr = (T*)malloc(size);
|
ptr = (T*)malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
CtorObject(ptr, ArgsList);
|
Construct(ptr, ArgsList);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
bool IsChildOf(const UClass* cls, bool bthis = false) const {
|
bool IsChildOf(const UClass* cls, bool bthis = false) const {
|
||||||
@ -85,15 +88,15 @@ namespace refl {
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
bool CtorObject(void* ptr, const sarray<Any>& ArgsList = {})const;
|
bool Construct(void* ptr, const sarray<Any>& ArgsList = {})const;
|
||||||
void DestObject(void* ptr)const {
|
void Destruct(void* ptr)const {
|
||||||
if (vtable.DestObject) {
|
if (vtable.Destruct) {
|
||||||
vtable.DestObject(ptr);
|
vtable.Destruct(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static bool CtorObject(void* ptr, const UClass* cls, const sarray<Any>& ArgsList = {}) {
|
static bool Construct(void* ptr, const UClass* cls, const sarray<Any>& ArgsList = {}) {
|
||||||
int argsSize = ArgsList.size();
|
int argsSize = ArgsList.size();
|
||||||
if (argsSize == 0) {
|
if (argsSize == 0) {
|
||||||
if constexpr (std::is_trivially_constructible_v<T>) {
|
if constexpr (std::is_trivially_constructible_v<T>) {
|
||||||
|
|||||||
170
engine/3rdparty/zlib/include/refl/detail/uclass.inl
vendored
170
engine/3rdparty/zlib/include/refl/detail/uclass.inl
vendored
@ -1,11 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "uclass.h"
|
#include "uclass.h"
|
||||||
|
#include <iostream>
|
||||||
namespace refl {
|
namespace refl {
|
||||||
template <class T>
|
template <class T>
|
||||||
concept _ReflCheck_Metas = requires(const Name & name) { MetaImpl<T>::MyMetas::GetMeta(name); };
|
concept _ReflCheck_Metas = requires(const Name & name) { MetaImpl<T>::MyMetas::GetMeta(name); };
|
||||||
|
|
||||||
template<_ReflCheck_Ctor T>
|
template<typename T>
|
||||||
class UClass_Auto : public UClass {
|
class UClass_Auto : public UClass {
|
||||||
public:
|
public:
|
||||||
using UClass::UClass;
|
using UClass::UClass;
|
||||||
@ -29,7 +30,7 @@ namespace refl {
|
|||||||
cls.parent = &TypeInfo<RT>::StaticClass;
|
cls.parent = &TypeInfo<RT>::StaticClass;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cls.vtable.CtorObject = &MyUClass::CtorObject<T>;
|
cls.vtable.Construct = &MyUClass::Construct<T>;
|
||||||
}
|
}
|
||||||
if constexpr (_ReflCheck_Metas<T>) {
|
if constexpr (_ReflCheck_Metas<T>) {
|
||||||
cls.vtable.GetMeta = &MetaImpl<T>::MyMetas::GetMeta;
|
cls.vtable.GetMeta = &MetaImpl<T>::MyMetas::GetMeta;
|
||||||
@ -106,16 +107,129 @@ namespace refl {
|
|||||||
return cls;
|
return cls;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<is_container_v T, typename value_type>
|
template<typename... Types>
|
||||||
class UClass_Container : public UClass {
|
class UClass_Tuple : public UClass {
|
||||||
using MyUClass = UClass_Container<T, value_type>;
|
using UClass::UClass;
|
||||||
using MyMeta = refl_impl::_ContainerMeta<T>;
|
using MyUClass = UClass_Tuple<Types...>;
|
||||||
using FieldsType = decltype(MyMeta::__MakeFields());
|
using MyTuple = std::tuple<Types...>;
|
||||||
FieldsType Fields{ MyMeta::__MakeFields() };
|
|
||||||
public:
|
public:
|
||||||
consteval static MyUClass BuildClass() {
|
constexpr static std::array<std::string_view, 16> IndexNames = {
|
||||||
return MyMeta::__BuildClass();
|
"1", "2", "3", "4", "5", "6", "7", "8",
|
||||||
|
"9", "10", "11", "12", "13", "14", "15", "16"
|
||||||
|
};
|
||||||
|
std::array<FieldPtr, sizeof...(Types)> Fields;
|
||||||
|
static bool construct(void* ptr, const UClass* cls, const sarray<Any>& ArgsList) {
|
||||||
|
new(ptr)MyTuple();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
static void destruct(void* ptr) {
|
||||||
|
((MyTuple*)ptr)->~MyTuple();
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
static FieldPtr field_in_tuple() {
|
||||||
|
MemberData member;
|
||||||
|
constexpr uint32_t flag = FIELD_MEMBER_FLAG | FIELD_ATTRIBUTE_FLAG;
|
||||||
|
return { FName(""), &TypeInfo<T>::StaticClass, member, flag};
|
||||||
|
}
|
||||||
|
const sarray<const FieldPtr> GetFields(EFieldFind find, const Name& name) const {
|
||||||
|
return sarray<const FieldPtr>(&Fields[0], sizeof...(Types));
|
||||||
|
}
|
||||||
|
static const sarray<const FieldPtr> GetFields(const UClass* _cls, EFieldFind find, const Name& name) {
|
||||||
|
auto cls = static_cast<const MyUClass*>(_cls);
|
||||||
|
return cls->GetFields(find, name);
|
||||||
|
}
|
||||||
|
UClass_Tuple():UClass(type_name<MyTuple>().View(), sizeof(MyTuple)) {
|
||||||
|
vtable.Construct = &MyUClass::construct;
|
||||||
|
vtable.Destruct = &MyUClass::destruct;
|
||||||
|
vtable.GetFields = &MyUClass::GetFields;
|
||||||
|
auto ptr = &Fields[0];
|
||||||
|
(..., (*ptr = field_in_tuple<Types>(), ptr++));
|
||||||
|
Offset offset = 0;
|
||||||
|
constexpr int N = sizeof...(Types);
|
||||||
|
assert(N < IndexNames.size());
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
Fields[i].name = IndexNames[i];
|
||||||
|
Fields[i].data.member.offset = offset;
|
||||||
|
offset += Fields[i].type->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
class UClass_Container : public UClass {
|
||||||
|
public:
|
||||||
|
using UClass::UClass;
|
||||||
|
struct iterator {
|
||||||
|
void* ptr;
|
||||||
|
void* val;
|
||||||
|
};
|
||||||
|
//container
|
||||||
|
using size_impl = size_t(*)(const void*);
|
||||||
|
using to_iterator_impl = iterator(*)(const void*);
|
||||||
|
using insert_impl = void (*)(const void*, const void*);
|
||||||
|
//iterator
|
||||||
|
using iterator_impl = void* (*)(const void*);
|
||||||
|
public:
|
||||||
|
size_impl vsize;
|
||||||
|
to_iterator_impl vbegin;
|
||||||
|
to_iterator_impl vend;
|
||||||
|
insert_impl vinsert;
|
||||||
|
iterator_impl viterator_add;
|
||||||
|
iterator_impl viterator_sub;
|
||||||
|
template<typename T>
|
||||||
|
static void insert(const void* ptr, const void* obj) {
|
||||||
|
using value_type = typename T::value_type;
|
||||||
|
if constexpr (is_sequence_v<T>) {
|
||||||
|
((T*)ptr)->push_back(*(value_type*)obj);
|
||||||
|
}
|
||||||
|
else if constexpr (is_map_v<T>) {
|
||||||
|
((T*)ptr)->insert(*(value_type*)obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<is_container_v T, typename value_type>
|
||||||
|
class UClass_Container_impl : public UClass_Container {
|
||||||
|
using UClass_Container::UClass_Container;
|
||||||
|
using MyUClass = UClass_Container_impl<T, value_type>;
|
||||||
|
using ToIteratorFunc = T::iterator(T::*)();
|
||||||
|
using IteratorFunc = T::iterator& (T::iterator::*)();
|
||||||
|
public:
|
||||||
|
static bool construct(void* ptr, const UClass* cls, const sarray<Any>& ArgsList) {
|
||||||
|
new(ptr)T();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
static void destruct(void* ptr) {
|
||||||
|
((T*)ptr)->~T();
|
||||||
|
}
|
||||||
|
static iterator begin(const void* ptr) {
|
||||||
|
auto it = ((T*)ptr)->begin();
|
||||||
|
return iterator{ *(void**)&it, &*it};
|
||||||
|
}
|
||||||
|
static iterator end(const void* ptr) {
|
||||||
|
auto it = ((T*)ptr)->end();
|
||||||
|
return iterator{ *(void**)&it, &*it };
|
||||||
|
}
|
||||||
|
UClass_Container_impl() : UClass_Container(type_name<T>().View(), sizeof(T)) {
|
||||||
|
parent = &TypeInfo<value_type>::StaticClass;
|
||||||
|
flag = CLASS_CONTAINER_FLAG;
|
||||||
|
vtable.Construct = &MyUClass::construct;
|
||||||
|
vtable.Destruct = &MyUClass::destruct;
|
||||||
|
if constexpr (is_sequence_v<T>) {
|
||||||
|
flag |= CLASS_SEQUENCE_FLAG;
|
||||||
|
}
|
||||||
|
else if constexpr (is_map_v<T>)
|
||||||
|
{
|
||||||
|
flag |= CLASS_MAP_FLAG;
|
||||||
|
}
|
||||||
|
auto __size = &T::size;
|
||||||
|
vsize = *(size_impl*)&__size;
|
||||||
|
vbegin = &MyUClass::begin;
|
||||||
|
vend = &MyUClass::end;
|
||||||
|
vinsert = &MyUClass::insert<T>;
|
||||||
|
|
||||||
|
IteratorFunc __it_add = &T::iterator::operator++;
|
||||||
|
viterator_add = *(iterator_impl*)&__it_add;
|
||||||
|
IteratorFunc __it_sub = &T::iterator::operator++;
|
||||||
|
viterator_sub = *(iterator_impl*)&__it_sub;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
template<typename T, typename MyMeta>
|
template<typename T, typename MyMeta>
|
||||||
class UClass_Meta : public UClass {
|
class UClass_Meta : public UClass {
|
||||||
@ -133,7 +247,7 @@ namespace refl {
|
|||||||
vtable.GetMeta = &MetaImpl<T>::MyMetas::GetMeta;
|
vtable.GetMeta = &MetaImpl<T>::MyMetas::GetMeta;
|
||||||
}
|
}
|
||||||
vtable.GetFields = &UClass_Meta::GetFields;
|
vtable.GetFields = &UClass_Meta::GetFields;
|
||||||
vtable.CtorObject = &UClass::CtorObject<T>;
|
vtable.Construct = &UClass::Construct<T>;
|
||||||
}
|
}
|
||||||
const FieldPtr* GetField(int index) const {
|
const FieldPtr* GetField(int index) const {
|
||||||
return &Fields[index];
|
return &Fields[index];
|
||||||
@ -197,7 +311,11 @@ namespace refl {
|
|||||||
return cls->GetFields(find, name);
|
return cls->GetFields(find, name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
template<typename T>
|
||||||
|
struct TypeInfoImpl {
|
||||||
|
using MyUClass = UClass_Auto<T>;
|
||||||
|
inline constexpr static MyUClass StaticClass = MyUClass::BuildClass();
|
||||||
|
};
|
||||||
template<>
|
template<>
|
||||||
struct TypeInfoImpl<void> {
|
struct TypeInfoImpl<void> {
|
||||||
inline constexpr static UClass StaticClass = { type_name<void>().View(), 0 };
|
inline constexpr static UClass StaticClass = { type_name<void>().View(), 0 };
|
||||||
@ -207,21 +325,25 @@ namespace refl {
|
|||||||
using MyUClass = UClass_Meta<T, typename MetaImpl<T>::MyMeta>;
|
using MyUClass = UClass_Meta<T, typename MetaImpl<T>::MyMeta>;
|
||||||
inline static MyUClass StaticClass = MyUClass();
|
inline static MyUClass StaticClass = MyUClass();
|
||||||
};
|
};
|
||||||
// 函数指针类型的偏特化
|
template<typename... Types>
|
||||||
template<typename R, typename... Args>
|
struct TypeInfoImpl<std::tuple<Types...>> {
|
||||||
struct TypeInfoImpl<R(*)(Args...)> {
|
using MyUClass = UClass_Tuple<Types...>;
|
||||||
using UClass = UMethod_Auto<R, Args...>;
|
inline static MyUClass StaticClass = MyUClass();
|
||||||
inline constexpr static UClass StaticClass = UClass::BuildClass();
|
};
|
||||||
|
template<typename... Types>
|
||||||
|
struct TypeInfoImpl<std::pair<Types...>> {
|
||||||
|
using MyUClass = UClass_Tuple<Types...>;
|
||||||
|
inline static MyUClass StaticClass = MyUClass();
|
||||||
};
|
};
|
||||||
template<is_container_v T>
|
template<is_container_v T>
|
||||||
struct TypeInfoImpl<T> {
|
struct TypeInfoImpl<T> {
|
||||||
using UClass = UClass_Container<T, typename T::value_type>;
|
using MyUClass = UClass_Container_impl<T, typename T::value_type>;
|
||||||
inline constexpr static UClass StaticClass = UClass::BuildClass();
|
inline static MyUClass StaticClass = MyUClass();
|
||||||
};
|
};
|
||||||
//基础类型的偏特化
|
// 函数指针类型的偏特化
|
||||||
template<_ReflCheck_Ctor_NoUClass T>
|
template<typename R, typename... Args>
|
||||||
struct TypeInfoImpl<T> {
|
struct TypeInfoImpl<R(*)(Args...)> {
|
||||||
using UClass = UClass_Auto<T>;
|
using MyUClass = UMethod_Auto<R, Args...>;
|
||||||
inline constexpr static UClass StaticClass = UClass::BuildClass();
|
inline constexpr static MyUClass StaticClass = MyUClass::BuildClass();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -52,9 +52,25 @@ namespace refl {
|
|||||||
{
|
{
|
||||||
return !(cls->flag & CLASS_ARRAY_FLAG) && !(cls->flag & CLASS_POINTER_FLAG);
|
return !(cls->flag & CLASS_ARRAY_FLAG) && !(cls->flag & CLASS_POINTER_FLAG);
|
||||||
}
|
}
|
||||||
|
inline bool Any::IsContainer() const
|
||||||
|
{
|
||||||
|
return cls->flag & CLASS_CONTAINER_FLAG;
|
||||||
|
}
|
||||||
|
inline bool Any::IsSequence() const
|
||||||
|
{
|
||||||
|
return cls->flag & CLASS_SEQUENCE_FLAG;
|
||||||
|
}
|
||||||
|
inline bool Any::IsMap() const
|
||||||
|
{
|
||||||
|
return cls->flag & CLASS_MAP_FLAG;
|
||||||
|
}
|
||||||
inline bool Any::Construct(const sarray<Any>& ArgsList) const
|
inline bool Any::Construct(const sarray<Any>& ArgsList) const
|
||||||
{
|
{
|
||||||
return cls->CtorObject((void*)ptr, ArgsList);
|
return cls->Construct((void*)ptr, ArgsList);
|
||||||
|
}
|
||||||
|
inline void Any::Destruct() const
|
||||||
|
{
|
||||||
|
cls->Destruct((void*)ptr);
|
||||||
}
|
}
|
||||||
inline AnyArgs::AnyArgs(const sarray<Any>& args, const sarray<const UClass*>& params, void* memory)
|
inline AnyArgs::AnyArgs(const sarray<Any>& args, const sarray<const UClass*>& params, void* memory)
|
||||||
: data(memory), num(args.size()), size(GetArgsSize(args, params))
|
: data(memory), num(args.size()), size(GetArgsSize(args, params))
|
||||||
@ -84,7 +100,7 @@ namespace refl {
|
|||||||
if (isMemoryOwner) {
|
if (isMemoryOwner) {
|
||||||
Any* any = (Any*)data;
|
Any* any = (Any*)data;
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
any->cls->DestObject((void*)any->ptr);
|
any->cls->Destruct((void*)any->ptr);
|
||||||
any++;
|
any++;
|
||||||
}
|
}
|
||||||
free(data);
|
free(data);
|
||||||
@ -213,10 +229,10 @@ namespace refl {
|
|||||||
inline AnyView AnyView::Parent() {
|
inline AnyView AnyView::Parent() {
|
||||||
return { ptr, cls ? cls->parent : nullptr };
|
return { ptr, cls ? cls->parent : nullptr };
|
||||||
}
|
}
|
||||||
inline bool UClass::CtorObject(void* ptr, const sarray<Any>& ArgsList) const
|
inline bool UClass::Construct(void* ptr, const sarray<Any>& ArgsList) const
|
||||||
{
|
{
|
||||||
if (vtable.CtorObject) {
|
if (vtable.Construct) {
|
||||||
if (vtable.CtorObject(ptr, this, ArgsList)) {
|
if (vtable.Construct(ptr, this, ArgsList)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto& fieldList = GetFields(EFieldFind::FIND_CTOR, FName("Ctor"));
|
auto& fieldList = GetFields(EFieldFind::FIND_CTOR, FName("Ctor"));
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "refl/detail/uclass.h"
|
|
||||||
namespace refl::impl {
|
|
||||||
template<typename T>
|
|
||||||
struct _ContainerMeta {
|
|
||||||
auto __MakeFields() {
|
|
||||||
return std::array{
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
auto __BuildClass() {
|
|
||||||
return cls;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
1
engine/3rdparty/zlib/include/refl/refl.h
vendored
1
engine/3rdparty/zlib/include/refl/refl.h
vendored
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "detail/uclass.inl"
|
#include "detail/uclass.inl"
|
||||||
|
#include "detail/container.inl"
|
||||||
#include "detail/view.inl"
|
#include "detail/view.inl"
|
||||||
#include "detail/field.inl"
|
#include "detail/field.inl"
|
||||||
#include "detail/convert.inl"
|
#include "detail/convert.inl"
|
||||||
|
|||||||
@ -31,7 +31,7 @@ namespace refl {
|
|||||||
~parray() {
|
~parray() {
|
||||||
if (!m_count || !m_cls)
|
if (!m_count || !m_cls)
|
||||||
return;
|
return;
|
||||||
auto dest = m_cls->vtable.DestObject;
|
auto dest = m_cls->vtable.Destruct;
|
||||||
if (dest) {
|
if (dest) {
|
||||||
for (int i = 0; i < m_count; i++) {
|
for (int i = 0; i < m_count; i++) {
|
||||||
dest((char*)m_ptr + (i * m_cls->size));
|
dest((char*)m_ptr + (i * m_cls->size));
|
||||||
|
|||||||
@ -58,6 +58,13 @@ namespace YAML
|
|||||||
return Node{ it->second.first(any)};
|
return Node{ it->second.first(any)};
|
||||||
}
|
}
|
||||||
Node result;
|
Node result;
|
||||||
|
if (any.IsContainer()) {
|
||||||
|
auto docker = any.ToContainer();
|
||||||
|
for (auto obj : docker) {
|
||||||
|
result.push_back(Serialize(obj));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
if (any.IsArray()) {
|
if (any.IsArray()) {
|
||||||
int n = any.ArraySize();
|
int n = any.ArraySize();
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@ -74,13 +81,29 @@ namespace YAML
|
|||||||
}
|
}
|
||||||
inline bool TextArchive::Unserialize(const Node& res, const Any& any)
|
inline bool TextArchive::Unserialize(const Node& res, const Any& any)
|
||||||
{
|
{
|
||||||
if (!any.IsValid() || res.IsNull()) {
|
if (!any.IsValid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (res.IsNull()) {
|
||||||
|
const string& str = "";
|
||||||
|
return any.Construct(Any{ &str, &TypeInfo<string>::StaticClass });
|
||||||
|
}
|
||||||
auto it = FuncMap.find(any.cls);
|
auto it = FuncMap.find(any.cls);
|
||||||
if (it != FuncMap.end()) {
|
if (it != FuncMap.end()) {
|
||||||
return it->second.second(res.as<string>(),any);
|
return it->second.second(res.as<string>(),any);
|
||||||
}
|
}
|
||||||
|
if (res.IsSequence() && any.IsContainer()) {
|
||||||
|
auto docker = any.ToContainer();
|
||||||
|
docker.construct();
|
||||||
|
Any any = docker.malloc_any();
|
||||||
|
for (std::size_t i = 0; i < res.size(); i++) {
|
||||||
|
Unserialize(res[i], any);
|
||||||
|
docker.insert(any);
|
||||||
|
any.Destruct();
|
||||||
|
}
|
||||||
|
free((void*)any.ptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (res.IsSequence() && any.IsArray()) {
|
if (res.IsSequence() && any.IsArray()) {
|
||||||
for (std::size_t i = 0; i < res.size(); i++) {
|
for (std::size_t i = 0; i < res.size(); i++) {
|
||||||
Unserialize(res[i], any.Member(i));
|
Unserialize(res[i], any.Member(i));
|
||||||
|
|||||||
4
engine/3rdparty/zlib/test/yaml/guid.h
vendored
4
engine/3rdparty/zlib/test/yaml/guid.h
vendored
@ -59,7 +59,9 @@ struct Guid
|
|||||||
return std::string{ guid_cstr };
|
return std::string{ guid_cstr };
|
||||||
}
|
}
|
||||||
UFUNCTION({})
|
UFUNCTION({})
|
||||||
bool test(int a, float* b, char** c){}
|
bool test(int a, float* b, char** c){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
static Guid Make()
|
static Guid Make()
|
||||||
{
|
{
|
||||||
Guid guid;
|
Guid guid;
|
||||||
|
|||||||
48
engine/3rdparty/zlib/test/yaml/main.cpp
vendored
48
engine/3rdparty/zlib/test/yaml/main.cpp
vendored
@ -20,16 +20,60 @@ void testMeta() {
|
|||||||
mb1.metadatas.push_back({ Guid::Make() , "hello3" });
|
mb1.metadatas.push_back({ Guid::Make() , "hello3" });
|
||||||
mb1.metadatas.push_back({ Guid::Make() , "hello4" });
|
mb1.metadatas.push_back({ Guid::Make() , "hello4" });
|
||||||
string rmb1 = YAML::Text_Serialize(mb1);
|
string rmb1 = YAML::Text_Serialize(mb1);
|
||||||
|
std::cout << rmb1 << std::endl;
|
||||||
auto rmb2 = YAML::Text_Unserialize<MetaBundle>(rmb1);
|
auto rmb2 = YAML::Text_Unserialize<MetaBundle>(rmb1);
|
||||||
if (rmb2) {
|
if (rmb2) {
|
||||||
MetaBundle aa = rmb2.value();
|
MetaBundle aa = rmb2.value();
|
||||||
|
std::cout << "success!" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void testTuple() {
|
||||||
|
std::map<int, string> table;
|
||||||
|
table.insert(std::make_pair(111,"hello"));
|
||||||
|
table.insert(std::make_pair(222, "world"));
|
||||||
|
using T = std::map<int, string>;
|
||||||
|
using to_iterator_func = T::iterator(T::*)();
|
||||||
|
struct myiterator {
|
||||||
|
void* ptr;
|
||||||
|
};
|
||||||
|
using to_iterator_impl1 = myiterator*(*)(void *);
|
||||||
|
using to_iterator_impl2 = myiterator(*)(void*);
|
||||||
|
using to_iterator_impl3 = void*(*)(void*);
|
||||||
|
using to_iterator_impl4 = T::iterator(*)(T*);
|
||||||
|
auto it = table.begin();
|
||||||
|
auto t = &*it;
|
||||||
|
to_iterator_func func = &T::begin;
|
||||||
|
to_iterator_impl1 impl1 = *(to_iterator_impl1*) & func;
|
||||||
|
to_iterator_impl2 impl2 = *(to_iterator_impl2*)&func;
|
||||||
|
to_iterator_impl3 impl3 = *(to_iterator_impl3*)&func;
|
||||||
|
to_iterator_impl4 impl4 = *(to_iterator_impl4*)&func;
|
||||||
|
string rtable = YAML::Text_Serialize(table);
|
||||||
|
std::cout << rtable << std::endl;
|
||||||
|
auto table2 = YAML::Text_Unserialize<std::map<int, string>>(rtable);
|
||||||
|
if (table2) {
|
||||||
|
std::map<int, string> aa = table2.value();
|
||||||
|
std::cout << "success!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
using size_impl = size_t(*)(const void*);
|
||||||
int main() {
|
int main() {
|
||||||
constexpr bool m1 = refl::is_map_v<std::vector<int>>;
|
constexpr bool m1 = refl::is_map_v<std::vector<int>>;
|
||||||
constexpr bool m2 = refl::is_sequence_v<std::map<int, float>>;
|
constexpr bool m2 = refl::is_sequence_v<std::map<int, float>>;
|
||||||
auto cls = &TypeInfo<Guid>::StaticClass;
|
auto cls = &TypeInfo<Guid>::StaticClass;
|
||||||
testGuid();
|
std::vector<int> vi;
|
||||||
testMeta();
|
using T = std::vector<int>;
|
||||||
|
using iterator = T::iterator;
|
||||||
|
struct myiterator {
|
||||||
|
void* ptr;
|
||||||
|
};
|
||||||
|
using to_iterator_impl_func = myiterator*(*)(const void*);
|
||||||
|
using to_iterator_func = void(T::*)(T::value_type&&);
|
||||||
|
to_iterator_func to_iterator = &T::push_back;
|
||||||
|
to_iterator_impl_func to_iterator_impl = * (to_iterator_impl_func*) &to_iterator;
|
||||||
|
iterator it = vi.begin();
|
||||||
|
void* pptr = it._Ptr;
|
||||||
|
//testGuid();
|
||||||
|
//testMeta();
|
||||||
|
testTuple();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user