#include #include #include "refl/uclass.h" #include "vertex.h" #include "tstring.h" using namespace std; using namespace refl; struct vec3_parent { }; struct vec3 : public vec3_parent { using UClass = class vec3_UClass; float x = 1; float y = 2; float z = 3; string name{ "hellohellohellohellohellohello" }; float norm() { return x * y * z; } }; struct vec3_UClass : public UClass { array FList; using UClass::UClass; const FieldPtr* GetField(const Name& name)const override { for (auto& field : FList) { if (field.name == name) { return &field; } } return nullptr; } void InitObject(void* ptr)const override { vec3 obj{}; std::construct_at((vec3*)ptr, obj); } static vec3_UClass BuildClass() { vec3_UClass cls(type_name().View(), sizeof(vec3), &TypeInfo::StaticClass); //offsetof(vec3, x) 很坑,相当坑 cls.FList[0] = cls.MakeMemberField(&vec3::x, "x"); cls.FList[1] = cls.MakeMemberField(&vec3::y, "y"); cls.FList[2] = cls.MakeMemberField(&vec3::z, "z"); cls.FList[3] = cls.MakeMemberField(&vec3::name, "name"); return cls; } }; int main() { using uclass = TypeInfo::UClass; auto& res = TypeInfo::StaticClass; auto& res2 = TypeInfo::StaticClass; auto& res3 = TypeInfo::StaticClass; vec3 v1; auto res4 = TypeInfo::StaticClass; auto res5 = TypeInfo::StaticClass; auto t1 = res3.FList[0]; vec3_parent* v2 = res3.New(); vec3* v22 = (vec3*)v2; auto v3 = res3.New(); int x1 = 110; float x = *res.New(&x1); v3.Get("x", x); v3.Set("z", (float)33); v2 = (vec3*)v3.ptr; using T = int; auto b1 = res3.IsChildOf(); constexpr auto cls = UClass_Auto(type_name().View(), sizeof(T)); cout << sizeof(Name) << "Type2: " << typeid(vec3).name() << endl; delete v2; cout << "hello world\n"; }