diff --git a/engine/3rdparty/zlib/include/refl/detail/type.h b/engine/3rdparty/zlib/include/refl/detail/type.h index 914c5fc..023d6d8 100644 --- a/engine/3rdparty/zlib/include/refl/detail/type.h +++ b/engine/3rdparty/zlib/include/refl/detail/type.h @@ -12,20 +12,46 @@ namespace refl_impl { template struct _Meta; + + template + struct _ContainerMeta; } namespace refl { - using refl_impl::MetaImpl; + // 定义一个模板结构体用于检测是否为 数组 + template + struct is_array : std::false_type {}; - template - concept _ReflCheck_Parent = requires { typename MyMeta::Parent;} && std::is_same_v; + template + struct is_array : std::true_type { + using type = T; + consteval static size_t Size() { + return N; + } + }; - template - concept _ReflCheck_Ctor = requires { T(); }; - template - concept _ReflCheck_UClass = requires { typename MetaImpl::MyMeta; }; - template - concept _ReflCheck_Ctor_NoUClass = _ReflCheck_Ctor && !_ReflCheck_UClass; + // 定义一个模板结构体用于检测是否为 std::pair + template + struct is_pair : std::false_type {}; + template + struct is_pair> : std::true_type {}; + + template + concept is_pair_v = is_pair::value; + + template + concept is_container_v = requires(T a) { + { a.begin() } -> std::input_iterator; + { a.end() } -> std::input_iterator; + }; + + template + concept is_map_v = is_pair_v && is_container_v; + + template + concept is_sequence_v = !is_pair_v && is_container_v; +}; +namespace refl { template struct real_type { using type = std::remove_cv_t; @@ -57,6 +83,19 @@ namespace refl { }; template using args_type_t = args_type>::type; +}; +namespace refl { + using refl_impl::MetaImpl; + + template + concept _ReflCheck_Parent = requires { typename MyMeta::Parent;} && std::is_same_v; + + template + concept _ReflCheck_Ctor = requires { T(); }; + template + concept _ReflCheck_UClass = requires { typename MetaImpl::MyMeta; }; + template + concept _ReflCheck_Ctor_NoUClass = _ReflCheck_Ctor && !_ReflCheck_UClass; //类型接口 template diff --git a/engine/3rdparty/zlib/include/refl/detail/uclass.inl b/engine/3rdparty/zlib/include/refl/detail/uclass.inl index 2460b73..346a5c5 100644 --- a/engine/3rdparty/zlib/include/refl/detail/uclass.inl +++ b/engine/3rdparty/zlib/include/refl/detail/uclass.inl @@ -14,12 +14,20 @@ namespace refl { consteval static MyUClass BuildClass() { MyUClass cls(type_name().View(), sizeof(T)); if constexpr (std::is_pointer_v){ - using RawT = std::remove_pointer_t; + using RT = std::remove_pointer_t; cls.flag = CLASS_POINTER_FLAG; - if constexpr (!std::is_same_v) { - cls.parent = &TypeInfo::StaticClass; + if constexpr (!std::is_same_v) { + cls.parent = &TypeInfo::StaticClass; } } + else if constexpr (is_array::value) { + using RT = typename is_array::type; + cls.flag = CLASS_ARRAY_FLAG; + if constexpr (std::is_pointer_v) { + cls.flag |= CLASS_POINTER_FLAG; + } + cls.parent = &TypeInfo::StaticClass; + } else { cls.vtable.CtorObject = &MyUClass::CtorObject; } @@ -35,23 +43,6 @@ namespace refl { return *(T*)ptr; } }; - template<_ReflCheck_Ctor T, int N> - class UClass_Array : public UClass { - public: - using UClass::UClass; - using MyUClass = UClass_Array; - public: - consteval static MyUClass BuildClass() { - MyUClass cls(type_name().View(), sizeof(T) * N, &TypeInfo::StaticClass); - if constexpr (std::is_pointer_v) { - cls.flag = CLASS_POINTER_FLAG | CLASS_ARRAY_FLAG; - } - else { - cls.flag = CLASS_ARRAY_FLAG; - } - return cls; - } - }; /* * 模板优化 * 成员参数转化为const void* @@ -115,6 +106,17 @@ namespace refl { return cls; } }; + template + class UClass_Container : public UClass { + using MyUClass = UClass_Container; + using MyMeta = refl_impl::_ContainerMeta; + using FieldsType = decltype(MyMeta::__MakeFields()); + FieldsType Fields{ MyMeta::__MakeFields() }; + public: + consteval static MyUClass BuildClass() { + return MyMeta::__BuildClass(); + } + }; template class UClass_Meta : public UClass { public: @@ -211,9 +213,9 @@ namespace refl { using UClass = UMethod_Auto; inline constexpr static UClass StaticClass = UClass::BuildClass(); }; - template - struct TypeInfoImpl { - using UClass = UClass_Array; + template + struct TypeInfoImpl { + using UClass = UClass_Container; inline constexpr static UClass StaticClass = UClass::BuildClass(); }; //基础类型的偏特化 diff --git a/engine/3rdparty/zlib/include/refl/impl/container.inl b/engine/3rdparty/zlib/include/refl/impl/container.inl new file mode 100644 index 0000000..4c657e3 --- /dev/null +++ b/engine/3rdparty/zlib/include/refl/impl/container.inl @@ -0,0 +1,15 @@ +#pragma once +#include "refl/detail/uclass.h" +namespace refl::impl { + template + struct _ContainerMeta { + auto __MakeFields() { + return std::array{ + + }; + } + auto __BuildClass() { + return cls; + } + }; +} \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/yaml/guid.h b/engine/3rdparty/zlib/test/yaml/guid.h index 3c20f82..47b6360 100644 --- a/engine/3rdparty/zlib/test/yaml/guid.h +++ b/engine/3rdparty/zlib/test/yaml/guid.h @@ -4,84 +4,87 @@ #include using std::string; using std::vector; - -using std::string_view; -namespace test { - struct Guid +struct Guid +{ + using MyMeta = class Guid_Meta; + UPROPERTY({}) + unsigned int Data1; + UPROPERTY({}) + unsigned short Data2; + UPROPERTY({}) + unsigned short Data3; + UPROPERTY({}) + unsigned char Data4[8]; + constexpr Guid() noexcept + : Data1{ 0 }, Data2{ 0 }, Data3{ 0 }, Data4{ 0,0,0,0,0,0,0,0 } + {} + Guid(const std::string_view& str) noexcept + : Guid{} { - UPROPERTY({}) - unsigned int Data1; - UPROPERTY({}) - unsigned short Data2; - UPROPERTY({}) - unsigned short Data3; - UPROPERTY({}) - unsigned char Data4[8]; - constexpr Guid() noexcept - : Data1{ 0 }, Data2{ 0 }, Data3{ 0 }, Data4{ 0,0,0,0,0,0,0,0 } - {} - - USING_OVERLOAD_CTOR(Guid, const string_view&) - UFUNCTION({}, ref = USING_CTOR_NAME) - Guid(const std::string_view& str) noexcept - : Guid{} - { - sscanf_s(str.data(), - "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", - &Data1, &Data2, &Data3, - &Data4[0], &Data4[1], &Data4[2], &Data4[3], - &Data4[4], &Data4[5], &Data4[6], &Data4[7]); + sscanf_s(str.data(), + "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", + &Data1, &Data2, &Data3, + &Data4[0], &Data4[1], &Data4[2], &Data4[3], + &Data4[4], &Data4[5], &Data4[6], &Data4[7]); + } + constexpr Guid(unsigned int a, unsigned short b, unsigned short c, unsigned long long d) + : Data1{ a } + , Data2{ b } + , Data3{ c } + , Data4{ + (unsigned char)(d >> 56 & 0xFF) + , (unsigned char)(d >> 48 & 0xFF) + , (unsigned char)(d >> 40 & 0xFF) + , (unsigned char)(d >> 32 & 0xFF) + , (unsigned char)(d >> 24 & 0xFF) + , (unsigned char)(d >> 16 & 0xFF) + , (unsigned char)(d >> 8 & 0xFF) + , (unsigned char)(d >> 0 & 0xFF) } - constexpr Guid(unsigned int a, unsigned short b, unsigned short c, unsigned long long d) - : Data1{ a } - , Data2{ b } - , Data3{ c } - , Data4{ - (unsigned char)(d >> 56 & 0xFF) - , (unsigned char)(d >> 48 & 0xFF) - , (unsigned char)(d >> 40 & 0xFF) - , (unsigned char)(d >> 32 & 0xFF) - , (unsigned char)(d >> 24 & 0xFF) - , (unsigned char)(d >> 16 & 0xFF) - , (unsigned char)(d >> 8 & 0xFF) - , (unsigned char)(d >> 0 & 0xFF) - } - {}; - auto operator<=>(const Guid&) const noexcept = default; - operator bool() const noexcept - { - return *reinterpret_cast(this) != GUID_NULL; - } + {}; + auto operator<=>(const Guid&) const noexcept = default; + operator bool() const noexcept + { + return *reinterpret_cast(this) != GUID_NULL; + } + operator std::string() const + { + char guid_cstr[39]; + snprintf(guid_cstr, sizeof(guid_cstr), + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + Data1, Data2, Data3, + Data4[0], Data4[1], Data4[2], Data4[3], + Data4[4], Data4[5], Data4[6], Data4[7]); + return std::string{ guid_cstr }; + } + UFUNCTION({}) + bool test(int a, float* b, char** c){} + static Guid Make() + { + Guid guid; + const auto res = CoCreateGuid((GUID*)&guid); + return guid; + } +}; +struct SerializedMeta +{ + UPROPERTY({}) + Guid guid; + UPROPERTY({}) + string name; + UPROPERTY({}) + string t_hash{}; + UPROPERTY({}) + string metadata; +}; +struct ResourceBundle; - USING_OVERLOAD_CLASS_FUNC(void, Guid, int) - UFUNCTION({}, ref = USING_FUNC_NAME) - void test(int x) { - - } - USING_OVERLOAD_CLASS_FUNC(void, Guid, float) - UFUNCTION({}, ref = USING_FUNC_NAME) - void test(float x) { - - } - operator std::string() const - { - char guid_cstr[39]; - snprintf(guid_cstr, sizeof(guid_cstr), - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - Data1, Data2, Data3, - Data4[0], Data4[1], Data4[2], Data4[3], - Data4[4], Data4[5], Data4[6], Data4[7]); - return std::string{ guid_cstr }; - } - static Guid Make() - { - Guid guid; - const auto res = CoCreateGuid((GUID*)&guid); - return guid; - } - - }; -} +struct MetaBundle +{ + UPROPERTY({}) + vector metadatas; + MetaBundle() = default; +}; #include "guid_gen.inl" \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/yaml/main.cpp b/engine/3rdparty/zlib/test/yaml/main.cpp index 966d5f6..7c65bd1 100644 --- a/engine/3rdparty/zlib/test/yaml/main.cpp +++ b/engine/3rdparty/zlib/test/yaml/main.cpp @@ -4,34 +4,32 @@ #include using namespace refl; using namespace std; -using namespace test; -int main() { - using T = test::Guid; - auto cls = &TypeInfo::StaticClass; - int x = 123; - Guid g1 = Guid::Make(); +void testGuid() { + Guid guid = Guid::Make(); YAML::TextArchive::Register(); - string rx = YAML::Text_Serialize(x); - string rg1 = YAML::Text_Serialize(g1); - YAML::Node rg2 = YAML::Load(rg1); - auto res1 = YAML::Text_Unserialize(rg1); - Guid g2 = res1.value(); - assert(g1 == g2); - //auto res2 = YAML::Text_Unserialize(rg1); - //if (res2) { - //MetaBundle aa = res2.value(); - //} - std::cout << rg1 << std::endl; - YAML::Node primes = YAML::Load("[2, 3, 5, 7, 11]"); - for (std::size_t i = 0; i < primes.size(); i++) { - std::cout << primes[i].as() << "\n"; + string text = YAML::Text_Serialize(guid); + auto res = YAML::Text_Unserialize(text); + Guid guid2 = res.value(); + assert(guid == guid2); + std::cout << guid << std::endl; +} +void testMeta() { + MetaBundle mb1; + mb1.metadatas.push_back({ Guid::Make() , "hello1" }); + mb1.metadatas.push_back({ Guid::Make() , "hello2" }); + mb1.metadatas.push_back({ Guid::Make() , "hello3" }); + mb1.metadatas.push_back({ Guid::Make() , "hello4" }); + string rmb1 = YAML::Text_Serialize(mb1); + auto rmb2 = YAML::Text_Unserialize(rmb1); + if (rmb2) { + MetaBundle aa = rmb2.value(); } - // or: - for (YAML::const_iterator it = primes.begin(); it != primes.end(); ++it) { - std::cout << it->as() << "\n"; - } - - primes.push_back(13); - assert(primes.size() == 6); +} +int main() { + constexpr bool m1 = refl::is_map_v>; + constexpr bool m2 = refl::is_sequence_v>; + auto cls = &TypeInfo::StaticClass; + testGuid(); + testMeta(); return 0; } \ No newline at end of file