version 1.12.0_beta.
Very important fix in PIByteArray! Now containers stream operators for trivial types works correct
This commit is contained in:
72
main.cpp
72
main.cpp
@@ -1,7 +1,6 @@
|
||||
#include "pip.h"
|
||||
#include "pivariantsimple.h"
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct MM {
|
||||
int x;
|
||||
@@ -14,9 +13,6 @@ struct MM {
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const MM & v) {piCout << "xep1"; ba << v.x << v.y << v.c; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << "xep2"; ba >> v.x >> v.y >> v.c; return ba;}
|
||||
|
||||
int Acnt = 0;
|
||||
|
||||
class A {
|
||||
@@ -29,6 +25,7 @@ public:
|
||||
void swap(A & a) {piCout << "swap A()"; piSwap(i, a.i);}
|
||||
A & operator =(const A & a) {i = a.i; piCout << "= A&"; return *this;}
|
||||
A & operator =(A && a) {piSwap(i, a.i); a.moved = true; piCout << "= A&&)"; return *this;}
|
||||
bool operator ==(const A & a) {return true;}
|
||||
PIString i;
|
||||
bool moved;
|
||||
MM m;
|
||||
@@ -38,61 +35,30 @@ public:
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const A & v) {ba << v.i << v.m; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, A & v) {ba >> v.i >> v.m; return ba;}
|
||||
|
||||
|
||||
/*
|
||||
class HelperBase {
|
||||
public:
|
||||
virtual void bsl(PIByteArray & ba, void * o) = 0;
|
||||
};
|
||||
|
||||
|
||||
template<typename X>
|
||||
class Helper : public HelperBase {
|
||||
public:
|
||||
void bsl(PIByteArray & ba, void * o) override {
|
||||
ba << (*(X*)o);
|
||||
piCout << ba.size();
|
||||
ba >> (*(X*)o);
|
||||
piCout << ba.size();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TypeHelper {
|
||||
public:
|
||||
HelperBase * h;
|
||||
template<typename T> inline void regtype() {
|
||||
h = new Helper<T>();
|
||||
}
|
||||
};
|
||||
*/
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const MM & v) {piCout << "<<"; ba << v.x << v.y << v.c; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << ">>"; ba >> v.x >> v.y >> v.c; return ba;}
|
||||
|
||||
|
||||
int main() {
|
||||
PIByteArray ba;
|
||||
// TypeHelper th;
|
||||
// th.regtype<MM>();
|
||||
MM m;
|
||||
memset(&m, 0xAC, sizeof(MM));
|
||||
PIVector<MM> vm;
|
||||
vm << m;
|
||||
m.e = 2;
|
||||
m.y = 0.1;
|
||||
PIVector<MM> v;
|
||||
//v.resize(1,2,m);
|
||||
v << m << m;
|
||||
|
||||
piCout << "m:";
|
||||
ba << m;
|
||||
piCout << ba.toHex();
|
||||
piCout << ba;
|
||||
ba >> m;
|
||||
piCout << ba;
|
||||
|
||||
ba.clear();
|
||||
piCout << "===";
|
||||
ba << vm;
|
||||
piCout << ba.toHex();
|
||||
// th.h->bsl(ba, &m);
|
||||
// th.regtype<CAN_Raw>();
|
||||
// CAN_Raw c;
|
||||
// th.h->bsl(ba, &c);
|
||||
// PIVariantSimple v;
|
||||
// v.setValue(m);
|
||||
// ba = v.save();
|
||||
// piCout << ba.toHex();
|
||||
// PIVariantSimple v2;
|
||||
// v2.load(ba);
|
||||
// piCout << v2.save().toHex();
|
||||
piCout << "v:";
|
||||
ba << v;
|
||||
piCout << ba;
|
||||
ba >> v;
|
||||
piCout << ba;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user