Files
pip/main.cpp
Ivan Pelipenko d0ef71c933 version 1.12.0_beta.
Very important fix in PIByteArray! Now containers stream operators for trivial types works correct
2020-10-17 21:16:26 +03:00

65 lines
1.6 KiB
C++

#include "pip.h"
#include "pivariantsimple.h"
#pragma pack(push, 1)
struct MM {
int x;
int x2;
double y;
char c[16];
int e2;
int e;
//PIPointd h;
};
#pragma pack(pop)
int Acnt = 0;
class A {
public:
A() {moved = false; i = "constructor"; piCout << "A()"; ++Acnt;}
A(const PIString & s): i(s) {moved = false; piCout << "A(String)"; ++Acnt;}
A(const A & a): i(a.i) {moved = false; piCout << "copy A(&)"; ++Acnt;}
A(A && a): i(std::move(a.i)) {moved = false; a.moved = true; piCout << "copy A(&&)"; ++Acnt;}
~A() {piCout << "~A()" << moved; --Acnt;}
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;
static void F(int) {}
};
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;}
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;
MM 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;
ba >> m;
piCout << ba;
ba.clear();
piCout << "v:";
ba << v;
piCout << ba;
ba >> v;
piCout << ba;
return 0;
}