git-svn-id: svn://db.shs.com.ru/pip@298 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-12-15 08:30:17 +00:00
parent 7a83933934
commit 9e6cdee552
3 changed files with 44 additions and 6 deletions

View File

@@ -16,12 +16,11 @@ int main(int argc, char *argv[]) {
s.text = "123"; s.text = "123";
s.i = -1; s.i = -1;
PIVariant v = PIVariant::fromValue(s); PIVariant v = PIVariant::fromValue(s);
piCout << v; PIByteArray ba;
s1 = v.value<__S__>(); ba << v;
piCout << s1.text << s1.i << v.value<int>(); PIVariant v1;
PIPropertyStorage ps; ba >> v1;
piForeachC (PIPropertyStorage::Property & p, ps) piCout << v1;
;
return 0; return 0;
} }

View File

@@ -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 #endif // PIPROPERTYSTORAGE_H

View File

@@ -142,6 +142,8 @@ classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(c
class PIP_EXPORT PIVariant { class PIP_EXPORT PIVariant {
friend PICout operator <<(PICout s, const PIVariant & v); friend PICout operator <<(PICout s, const PIVariant & v);
friend PIByteArray & operator <<(PIByteArray & s, const PIVariant & v);
friend PIByteArray & operator >>(PIByteArray & s, PIVariant & v);
public: public:
//! Type of %PIVariant content //! Type of %PIVariant content
@@ -611,6 +613,36 @@ REGISTER_VARIANT(PIDate)
REGISTER_VARIANT(PIDateTime) REGISTER_VARIANT(PIDateTime)
REGISTER_VARIANT(PISystemTime) 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) { inline PICout operator <<(PICout s, const PIVariant & v) {
s.space(); s.setControl(0, true); s.space(); s.setControl(0, true);
s << "PIVariant(" << v.typeName() << ", " << v.toString() << ")"; s << "PIVariant(" << v.typeName() << ", " << v.toString() << ")";