29 lines
948 B
C++
29 lines
948 B
C++
#pragma once
|
|
#include "any.h"
|
|
#include <unordered_map>
|
|
namespace refl {
|
|
using UClassPair = std::pair<const UClass*, const UClass*>;
|
|
// 自定义哈希函数
|
|
struct UClassPairHash {
|
|
std::size_t operator()(const UClassPair& pair) const {
|
|
std::hash<const UClass*> ptr_hash;
|
|
return ptr_hash(pair.first) ^ (ptr_hash(pair.second) << 1);
|
|
}
|
|
};
|
|
struct UClassPairEqual {
|
|
bool operator()(const UClassPair& lhs, const UClassPair& rhs) const {
|
|
return lhs.first == rhs.first && lhs.second == rhs.second;
|
|
}
|
|
};
|
|
using ConvertFunc = bool (*)(Any& to, const Any& from);
|
|
using ConvertMap = std::unordered_map<UClassPair, ConvertFunc, UClassPairHash, UClassPairEqual>;
|
|
class Convert {
|
|
protected:
|
|
static ConvertMap BuildClassMap();
|
|
template<typename From, typename To>
|
|
static bool ConvertTo(Any& to, const Any& from);
|
|
public:
|
|
static bool Construct(Any& to,const Any& from);
|
|
inline static ConvertMap ClassMap = BuildClassMap();
|
|
};
|
|
} |