diff --git a/main.cpp b/main.cpp index 1443675b..61c13687 100644 --- a/main.cpp +++ b/main.cpp @@ -16,12 +16,11 @@ int main(int argc, char *argv[]) { s.text = "123"; s.i = -1; PIVariant v = PIVariant::fromValue(s); - piCout << v; - s1 = v.value<__S__>(); - piCout << s1.text << s1.i << v.value(); - PIPropertyStorage ps; - piForeachC (PIPropertyStorage::Property & p, ps) - ; + PIByteArray ba; + ba << v; + PIVariant v1; + ba >> v1; + piCout << v1; return 0; } diff --git a/src/core/pipropertystorage.h b/src/core/pipropertystorage.h index 03b07951..e2aa114d 100644 --- a/src/core/pipropertystorage.h +++ b/src/core/pipropertystorage.h @@ -70,4 +70,11 @@ protected: }; + +inline PIByteArray & operator <<(PIByteArray & s, const PIPropertyStorage::Property & v) {s << v.name << v.value << v.comment << v.flags; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIPropertyStorage::Property & v) {s >> v.name >> v.value >> v.comment >> v.flags; return s;} + +inline PIByteArray & operator <<(PIByteArray & s, const PIPropertyStorage & v) {s << v.properties(); return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIPropertyStorage & v) {s >> v.properties(); return s;} + #endif // PIPROPERTYSTORAGE_H diff --git a/src/core/pivariant.h b/src/core/pivariant.h index 91bb8010..4bd234e4 100755 --- a/src/core/pivariant.h +++ b/src/core/pivariant.h @@ -142,6 +142,8 @@ classname_to __PIVariantFunctions__::castVariant(c class PIP_EXPORT PIVariant { friend PICout operator <<(PICout s, const PIVariant & v); + friend PIByteArray & operator <<(PIByteArray & s, const PIVariant & v); + friend PIByteArray & operator >>(PIByteArray & s, PIVariant & v); public: //! Type of %PIVariant content @@ -611,6 +613,36 @@ REGISTER_VARIANT(PIDate) REGISTER_VARIANT(PIDateTime) REGISTER_VARIANT(PISystemTime) +inline PIByteArray & operator <<(PIByteArray & s, const PIVariant & v) { + s << v._content << int(v._type); + if (v._type == PIVariant::pivCustom) { +#ifdef CUSTOM_PIVARIANT + if (v._info) { + s << v._info->typeName; + } else { + s << PIStringAscii(""); + } +#else + s << PIStringAscii(""); +#endif + } + return s; +} +inline PIByteArray & operator >>(PIByteArray & s, PIVariant & v) { + int t(0); + s >> v._content >> t; + v._type = (PIVariant::Type)t; + if (v._type == PIVariant::pivCustom) { + PIString tn; + s >> tn; +#ifdef CUSTOM_PIVARIANT + PIByteArray vc = v._content; + v = PIVariant::fromValue(vc, tn); +#endif + } + return s; +} + inline PICout operator <<(PICout s, const PIVariant & v) { s.space(); s.setControl(0, true); s << "PIVariant(" << v.typeName() << ", " << v.toString() << ")";