zengine-old/engine/3rdparty/zlib/include/refl/detail/convert.inl
2024-04-25 21:45:41 +08:00

32 lines
766 B
C++

#pragma once
#include <string>
#include "convert.h"
namespace refl {
bool Convert::ToString(Any& dst, const Any& src)
{
if (src.Parent() == &TypeInfo<char>::StaticClass) {
std::construct_at(dst.CastTo<std::string*>(), src.CastTo<const char*>());
return true;
}
return false;
}
inline bool Convert::Construct(Any& dst, const Any& src)
{
if (dst.Check(src.cls)) {
dst.cls->InitObject((void*)dst.ptr);
dst.cls->CopyObject((void*)dst.ptr, src.ptr);
return true;
}
auto it = ClassMap.find(dst.cls);
if (it == ClassMap.end()) {
return false;
}
return it->second(dst, src);
}
ConvertMap Convert::BuildClassMap()
{
ConvertMap classMap;
classMap.emplace(&TypeInfo<std::string*>::StaticClass, &ToString);
return classMap;
}
}