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

41 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "detail/uclass.inl"
#include "detail/view.inl"
namespace refl {
/* 成员变量需要定义默认值吗那为什么不在initObjec里初始化?*/
template<typename T, typename Obj>
static FieldPtr MakeMemberField(T Obj::* ptr, Name name) {
FieldPtr::Default value;
Offset offset = reinterpret_cast<std::size_t>(&(reinterpret_cast<const Obj*>(0)->*ptr));
FieldPtr::Data member = { offset };
constexpr uint32_t flag = FIELD_MEMBER_FLAG | FIELD_ATTRIBUTE_FLAG;
return { name, &TypeInfo<T>::StaticClass, member, value, flag };
}
template<typename R, typename ...Args>
static FieldPtr MakeMethodField(R(*ptr)(Args...), Name name, const std::vector<ArgsValue>& args = {}) {
uint32_t flag = FIELD_METHOD_FLAG;
FieldPtr::Default value;
if (args.size() > 0) {
flag |= FIELD_METHOD_VALUE_FLAG;
static const ArgsValueList argsValue(args);
value.method = []() ->std::pair<ArgsView*, int> {
return { argsValue.ptr , argsValue.num };
};
}
FieldPtr::Data method = { *(Method*)&ptr };
return { name, &TypeInfo<R(*)(typename RealTypeImpl<Args>::type...)>::StaticClass, method, value, flag };
}
template<typename T, typename R, typename ...Args>
static FieldPtr MakeMethodField(R(T::* ptr)(Args...), Name name, const std::vector<ArgsValue>& args = {}) {
uint32_t flag = FIELD_MEMBER_FLAG | FIELD_METHOD_FLAG;
FieldPtr::Default value;
if (args.size() > 0) {
flag |= FIELD_METHOD_VALUE_FLAG;
static const ArgsValueList argsValue(args);
value.method = []() ->std::pair<ArgsView*, int> {
return { argsValue.ptr , argsValue.num };
};
}
FieldPtr::Data method = { *(Method*)&ptr };
return { name, &TypeInfo<R(*)(const void*, typename RealTypeImpl<Args>::type...)>::StaticClass, method, value,flag };
}
}