zengine-old/engine/3rdparty/zlib/include/refl/detail/convert.inl

30 lines
713 B
Plaintext
Raw Normal View History

2024-04-25 21:45:41 +08:00
#pragma once
#include <string>
#include "convert.h"
namespace refl {
inline bool Convert::ToString(Any& dst, const Any& src)
2024-04-25 21:45:41 +08:00
{
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)
{
2024-06-12 22:07:45 +08:00
if (dst.cls->CtorObject((void*)dst.ptr, src)) {
2024-04-25 21:45:41 +08:00
return true;
}
auto it = ClassMap.find(dst.cls);
if (it == ClassMap.end()) {
return false;
}
return it->second(dst, src);
}
inline ConvertMap Convert::BuildClassMap()
2024-04-25 21:45:41 +08:00
{
ConvertMap classMap;
classMap.emplace(&TypeInfo<std::string*>::StaticClass, &ToString);
return classMap;
}
}