git-svn-id: svn://db.shs.com.ru/pip@211 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -30,6 +30,11 @@
|
||||
#include "pitime.h"
|
||||
#include "pimathbase.h"
|
||||
|
||||
#ifndef QNX
|
||||
# define CUSTOM_PIVARIANT
|
||||
#endif
|
||||
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
|
||||
template<typename T>
|
||||
class __PIVariantFunctions__ {
|
||||
@@ -120,6 +125,7 @@ classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(c
|
||||
#define REGISTER_VARIANT_CAST_SIMPLE_H(classname_from, classname_to) REGISTER_VARIANT_CAST_H(classname_from, classname_to)
|
||||
#define REGISTER_VARIANT_CAST_SIMPLE_CPP(classname_from, classname_to) REGISTER_VARIANT_CAST_CPP(classname_from, classname_to) {return classname_to(v);}
|
||||
|
||||
#endif
|
||||
|
||||
class PIP_EXPORT PIVariant {
|
||||
friend PICout operator <<(PICout s, const PIVariant & v);
|
||||
@@ -426,16 +432,20 @@ public:
|
||||
|
||||
static PIVariant fromValue(const PIByteArray & c, const PIString & type) {
|
||||
PIVariant ret;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
ret._info = __PIVariantInfoStorage__::get()->map->value(type, 0);
|
||||
if (!ret._info) {
|
||||
#endif
|
||||
PIVariant::Type t = typeFromName(type);
|
||||
if (t == Invalid) {
|
||||
piCout << "Can`t initialize PIVariant from unregistered type \"" << type << "\"!";
|
||||
return ret;
|
||||
}
|
||||
ret._type = t;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
} else
|
||||
ret._type = Custom;
|
||||
#endif
|
||||
ret._content = c;
|
||||
return ret;
|
||||
}
|
||||
@@ -454,14 +464,17 @@ private:
|
||||
_content.clear();
|
||||
_content << v;
|
||||
_type = getType<T>();
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (_type == Custom) {
|
||||
_info = __PIVariantInfoStorage__::get()->map->value(__PIVariantFunctions__<T>::typeNameHelper(), 0);
|
||||
if (!_info)
|
||||
piCout << "Can`t initialize PIVariant from unregistered type!";
|
||||
} else
|
||||
_info = 0;
|
||||
#endif
|
||||
}
|
||||
template<typename T> static T getAsValue(const PIVariant & v) {
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
if (v._content.isEmpty() || !v._info) return T();
|
||||
PIString cn = __PIVariantFunctions__<T>::typeNameHelper();
|
||||
piCout << "gav" << cn;
|
||||
@@ -476,11 +489,16 @@ private:
|
||||
}
|
||||
T ret; ba >> ret;
|
||||
return ret;
|
||||
#else
|
||||
return T();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIByteArray _content;
|
||||
PIVariant::Type _type;
|
||||
#ifdef CUSTOM_PIVARIANT
|
||||
__PIVariantInfo__ * _info;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user