PIVariant::fromType() methods
This commit is contained in:
@@ -338,6 +338,14 @@ PIVariant PIVariant::fromValue(const PIByteArray & c, const PIString & type) {
|
||||
}
|
||||
|
||||
|
||||
PIVariant PIVariant::fromType(uint type_id) {
|
||||
__PIVariantInfo__ * vi = __PIVariantInfoStorage__::get()->map->value(type_id);
|
||||
if (!vi) return PIVariant();
|
||||
piCout << "empty for" << type_id << "=" << vi->empty;
|
||||
return PIVariant::fromValue(vi->empty, type_id);
|
||||
}
|
||||
|
||||
|
||||
PIString PIVariant::typeName(PIVariant::Type type) {
|
||||
switch (type) {
|
||||
case PIVariant::pivBool: return "Bool";
|
||||
@@ -370,6 +378,7 @@ PIString PIVariant::typeName(PIVariant::Type type) {
|
||||
case PIVariant::pivRect: return "Rect";
|
||||
case PIVariant::pivMathVector: return "Vector";
|
||||
case PIVariant::pivMathMatrix: return "Matrix";
|
||||
case PIVariant::pivIODevice: return "IODevice";
|
||||
case PIVariant::pivCustom: return "Custom";
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,14 @@ public:
|
||||
};
|
||||
|
||||
struct PIP_EXPORT __PIVariantInfo__ {
|
||||
__PIVariantInfo__(const PIString & n) {typeName = n; typeID = n.hash();}
|
||||
__PIVariantInfo__(const PIString & n, const PIByteArray & e) {
|
||||
typeName = n;
|
||||
typeID = n.hash();
|
||||
empty = e;
|
||||
}
|
||||
typedef PIByteArray(*castHelperFunc)(PIByteArray);
|
||||
PIMap<uint, castHelperFunc> cast;
|
||||
PIByteArray empty;
|
||||
PIString typeName;
|
||||
uint typeID = 0;
|
||||
bool simple = false;
|
||||
@@ -119,7 +124,8 @@ public:
|
||||
uint type_id = __PIVariantFunctions__< classname >::typeIDHelper(); \
|
||||
PIString type_name = __PIVariantFunctions__< classname >::typeNameHelper(); \
|
||||
if (__PIVariantInfoStorage__::get()->map->contains(type_id)) return; \
|
||||
(*(__PIVariantInfoStorage__::get()->map))[type_id] = new __PIVariantInfo__(type_name); \
|
||||
PIByteArray empty; empty << classname(); \
|
||||
(*(__PIVariantInfoStorage__::get()->map))[type_id] = new __PIVariantInfo__(type_name, empty); \
|
||||
STATIC_INITIALIZER_END
|
||||
|
||||
|
||||
@@ -714,6 +720,14 @@ public:
|
||||
static PIVariant fromValue(const PIByteArray & c, uint type_id);
|
||||
static PIVariant fromValue(const PIByteArray & c, const PIString & type);
|
||||
|
||||
//! \~english Returns new %PIVariant from default-constructed type with name "type".
|
||||
//! \~russian Возвращает новый %PIVariant из пустого конструктора типа "type".
|
||||
static PIVariant fromType(const PIString & type) {return fromType(typeIDFromName(type));}
|
||||
|
||||
//! \~english Returns new %PIVariant from default-constructed type with type ID "type_id".
|
||||
//! \~russian Возвращает новый %PIVariant из пустого конструктора типа c ID "type_id".
|
||||
static PIVariant fromType(uint type_id);
|
||||
|
||||
|
||||
//! \~english Returns type from its name.
|
||||
//! \~russian Возвращает тип из его названия.
|
||||
|
||||
6
main.cpp
6
main.cpp
@@ -25,7 +25,7 @@ public:
|
||||
Editable = 0x02,
|
||||
Label = 0x04,
|
||||
ArrayReorder = 0x1001,
|
||||
ArrayDynamic = 0x1002,
|
||||
ArrayResize = 0x1002,
|
||||
};
|
||||
|
||||
bool isNull() const {return _is_null;}
|
||||
@@ -175,11 +175,11 @@ int main(int argc, char * argv[]) {
|
||||
//for (auto it: root.children()) {
|
||||
// piCout << it.name() << it.value();
|
||||
//}
|
||||
PIVariant v = PIVariant::fromValue(SomeType{1, 0.5f});
|
||||
PIVariant v = PIVariant::fromType("PIVariantTypes::IODevice");
|
||||
piCout << v;
|
||||
piCout << v.toString();
|
||||
v.setValueFromString("2;-0.1");
|
||||
piCout << v;
|
||||
piCout << v.value<PIVariantTypes::IODevice>();
|
||||
piCout << v.toString();
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user