PIVariant custom casts works
This commit is contained in:
@@ -112,7 +112,18 @@ void PIVariant::setValueFromString(const PIString & v) {
|
||||
case PIVariant::pivDir: {PIVariantTypes::Dir r = toDir(); r.dir = v; setValue(r);} break;
|
||||
case PIVariant::pivColor: {setValue(PIVariantTypes::Color(v.mid(1).toUInt(16)));} break;
|
||||
case PIVariant::pivIODevice: {setValue(PIVariantTypes::IODevice());} break; // TODO
|
||||
case PIVariant::pivCustom: {} break; // TODO;
|
||||
case PIVariant::pivCustom: {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
__PIVariantInfo__ * vi = __PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__<PIString>::typeIDHelper());
|
||||
if (vi) {
|
||||
__PIVariantInfo__::castHelperFunc cf = vi->cast.value(_typeID);
|
||||
if (cf) {
|
||||
PIByteArray sba; sba << v;
|
||||
_content = cf(sba);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -216,8 +227,10 @@ PIVariant::Type PIVariant::typeFromID(uint type_id) {
|
||||
if (type_id == typeID<PIMathMatrixd>()) return PIVariant::pivMathMatrix;
|
||||
if (type_id == typeID<PILined>()) return PIVariant::pivLine;
|
||||
if (type_id == typeID<PIVariantTypes::IODevice>()) return PIVariant::pivIODevice;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(type_id))
|
||||
return PIVariant::pivCustom;
|
||||
#endif
|
||||
return PIVariant::pivInvalid;
|
||||
}
|
||||
|
||||
|
||||
@@ -136,12 +136,12 @@ public:
|
||||
return ret; \
|
||||
} \
|
||||
STATIC_INITIALIZER_BEGIN \
|
||||
__PIVariantInfo__ * vi(__PIVariantInfoStorage__::get()->map->value(name.hash(), nullptr)); \
|
||||
__PIVariantInfo__ * vi(__PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__< classname_from >::typeIDHelper(), nullptr)); \
|
||||
if (!vi) { \
|
||||
piCout << "Warning! Using REGISTER_VARIANT_CAST("#classname_from", "#classname_to") before REGISTER_VARIANT("#classname_from"), ignore."; \
|
||||
return; \
|
||||
} \
|
||||
vi->cast[cname.hash()] = __PIVariantFunctions__<classname_from>::castHelper<classname_to>; \
|
||||
vi->cast[__PIVariantFunctions__< classname_to >::typeIDHelper()] = __PIVariantFunctions__<classname_from>::castHelper<classname_to>; \
|
||||
STATIC_INITIALIZER_END \
|
||||
template<> template<> \
|
||||
classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(const classname_from & v)
|
||||
@@ -737,7 +737,11 @@ public:
|
||||
|
||||
template <typename T>
|
||||
static uint typeID() {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
return __PIVariantFunctions__<T>::typeIDHelper();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -762,13 +766,13 @@ private:
|
||||
template<typename T> inline static T getAsValue(const PIVariant & v) {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (v._content.isEmpty() || !v._info) return T();
|
||||
PIString cn = __PIVariantFunctions__<T>::typeNameHelper();
|
||||
uint cnid = __PIVariantFunctions__<T>::typeIDHelper();
|
||||
//piCout << "gav" << cn;
|
||||
PIByteArray ba;
|
||||
if (cn == v._info->typeName) {
|
||||
if (cnid == v._info->typeID) {
|
||||
ba = v._content;
|
||||
} else {
|
||||
__PIVariantInfo__::castHelperFunc cf = v._info->cast.value(cn.hash());
|
||||
__PIVariantInfo__::castHelperFunc cf = v._info->cast.value(cnid);
|
||||
//piCout << "gav cast" << cf;
|
||||
if (!cf) return T();
|
||||
ba = cf(v._content);
|
||||
|
||||
Reference in New Issue
Block a user