version 1.12.0_beta.
Very important fix in PIByteArray! Now containers stream operators for trivial types works correct
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 11)
|
set(pip_MINOR 12)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX beta)
|
set(pip_SUFFIX beta)
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
|
|||||||
@@ -119,6 +119,16 @@ public:
|
|||||||
static PIByteArray fromHex(PIString str);
|
static PIByteArray fromHex(PIString str);
|
||||||
static PIByteArray fromBase64(const PIByteArray & base64);
|
static PIByteArray fromBase64(const PIByteArray & base64);
|
||||||
static PIByteArray fromBase64(const PIString & base64);
|
static PIByteArray fromBase64(const PIString & base64);
|
||||||
|
|
||||||
|
|
||||||
|
class StreamRef {
|
||||||
|
public:
|
||||||
|
StreamRef(PIByteArray & s): ba(s) {}
|
||||||
|
operator PIByteArray&() {return ba;}
|
||||||
|
private:
|
||||||
|
PIByteArray & ba;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Byte arrays compare operator
|
//! \relatesalso PIByteArray \brief Byte arrays compare operator
|
||||||
@@ -177,7 +187,7 @@ inline PIByteArray & operator <<(PIByteArray & s, const uchar v) {s.push_back(v)
|
|||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for any trivial copyable type
|
//! \relatesalso PIByteArray \brief Store operator for any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const T & v) {
|
inline PIByteArray::StreamRef operator <<(PIByteArray & s, const T & v) {
|
||||||
int os = s.size_s();
|
int os = s.size_s();
|
||||||
s.enlarge(sizeof(v));
|
s.enlarge(sizeof(v));
|
||||||
memcpy(s.data(os), &v, sizeof(v));
|
memcpy(s.data(os), &v, sizeof(v));
|
||||||
@@ -197,8 +207,10 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for PIVector of any fundamental type
|
//! \relatesalso PIByteArray \brief Store operator for PIVector of any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
||||||
s << int(v.size_s());
|
s << int(v.size_s());
|
||||||
int os = s.size_s();
|
int os = s.size_s();
|
||||||
@@ -208,9 +220,19 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
||||||
|
s << int(v.size_s());
|
||||||
|
for (uint i = 0; i < v.size(); ++i) s << v[i];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for PIDeque of any fundamental type
|
//! \relatesalso PIByteArray \brief Store operator for PIDeque of any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
||||||
s << int(v.size_s());
|
s << int(v.size_s());
|
||||||
int os = s.size_s();
|
int os = s.size_s();
|
||||||
@@ -220,9 +242,19 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
||||||
|
s << int(v.size_s());
|
||||||
|
for (uint i = 0; i < v.size(); ++i) s << v[i];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any fundamental type
|
//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
||||||
s << int(v.rows()) << int(v.cols());
|
s << int(v.rows()) << int(v.cols());
|
||||||
int os = s.size_s();
|
int os = s.size_s();
|
||||||
@@ -232,6 +264,13 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
||||||
|
s << int(v.rows()) << int(v.cols()) << v.toPlainVector();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator
|
//! \relatesalso PIByteArray \brief Store operator
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;}
|
inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;}
|
||||||
@@ -257,7 +296,7 @@ inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >=
|
|||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for any trivial copyable type
|
//! \relatesalso PIByteArray \brief Restore operator for any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, T & v) {
|
inline PIByteArray::StreamRef operator >>(PIByteArray & s, T & v) {
|
||||||
assert(s.size() >= sizeof(v));
|
assert(s.size() >= sizeof(v));
|
||||||
memcpy((void*)(&v), s.data(), sizeof(v));
|
memcpy((void*)(&v), s.data(), sizeof(v));
|
||||||
s.remove(0, sizeof(v));
|
s.remove(0, sizeof(v));
|
||||||
@@ -277,8 +316,10 @@ inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any fundamental type
|
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
||||||
assert(s.size_s() >= 4);
|
assert(s.size_s() >= 4);
|
||||||
int sz; s >> sz;
|
int sz; s >> sz;
|
||||||
@@ -289,9 +330,21 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
||||||
|
assert(s.size_s() >= 4);
|
||||||
|
int sz; s >> sz;
|
||||||
|
v.resize(sz);
|
||||||
|
for (int i = 0; i < sz; ++i) s >> v[i];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any fundamental type
|
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
||||||
assert(s.size_s() >= 4);
|
assert(s.size_s() >= 4);
|
||||||
int sz; s >> sz;
|
int sz; s >> sz;
|
||||||
@@ -302,9 +355,21 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
||||||
|
assert(s.size_s() >= 4);
|
||||||
|
int sz; s >> sz;
|
||||||
|
v.resize(sz);
|
||||||
|
for (int i = 0; i < sz; ++i) s >> v[i];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any fundamental type
|
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any trivial copyable type
|
||||||
template<typename T, typename std::enable_if< std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
||||||
assert(s.size_s() >= 8);
|
assert(s.size_s() >= 8);
|
||||||
int r, c; s >> r >> c;
|
int r, c; s >> r >> c;
|
||||||
@@ -316,6 +381,17 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
|
||||||
|
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
||||||
|
assert(s.size_s() >= 8);
|
||||||
|
int r,c;
|
||||||
|
PIVector<T> tmp;
|
||||||
|
s >> r >> c >> tmp;
|
||||||
|
v = PIVector2D<T>(r, c, tmp);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator
|
//! \relatesalso PIByteArray \brief Restore operator
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIBitArray & v) {assert(s.size_s() >= 8); s >> v.size_ >> v.data_; return s;}
|
inline PIByteArray & operator >>(PIByteArray & s, PIBitArray & v) {assert(s.size_s() >= 8); s >> v.size_ >> v.data_; return s;}
|
||||||
@@ -331,7 +407,7 @@ inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & v) {s >
|
|||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for PIVector of any compound type
|
//! \relatesalso PIByteArray \brief Store operator for PIVector of any compound type
|
||||||
template<typename T, typename std::enable_if<!std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
||||||
s << int(v.size_s());
|
s << int(v.size_s());
|
||||||
for (uint i = 0; i < v.size(); ++i) s << v[i];
|
for (uint i = 0; i < v.size(); ++i) s << v[i];
|
||||||
@@ -339,7 +415,7 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for PIDeque of any compound type
|
//! \relatesalso PIByteArray \brief Store operator for PIDeque of any compound type
|
||||||
template<typename T, typename std::enable_if<!std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
||||||
s << int(v.size_s());
|
s << int(v.size_s());
|
||||||
for (uint i = 0; i < v.size(); ++i) s << v[i];
|
for (uint i = 0; i < v.size(); ++i) s << v[i];
|
||||||
@@ -347,7 +423,7 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any compound type
|
//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any compound type
|
||||||
template<typename T, typename std::enable_if<!std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
||||||
s << int(v.rows()) << int(v.cols()) << v.toPlainVector();
|
s << int(v.rows()) << int(v.cols()) << v.toPlainVector();
|
||||||
return s;
|
return s;
|
||||||
@@ -360,7 +436,7 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
|||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any compound type
|
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any compound type
|
||||||
template<typename T, typename std::enable_if<!std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
||||||
assert(s.size_s() >= 4);
|
assert(s.size_s() >= 4);
|
||||||
int sz; s >> sz;
|
int sz; s >> sz;
|
||||||
@@ -370,7 +446,7 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any compound type
|
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any compound type
|
||||||
template<typename T, typename std::enable_if<!std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
||||||
assert(s.size_s() >= 4);
|
assert(s.size_s() >= 4);
|
||||||
int sz; s >> sz;
|
int sz; s >> sz;
|
||||||
@@ -380,7 +456,7 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any compound type
|
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any compound type
|
||||||
template<typename T, typename std::enable_if<!std::is_fundamental<T>::value, int>::type = 0>
|
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
||||||
assert(s.size_s() >= 8);
|
assert(s.size_s() >= 8);
|
||||||
int r,c;
|
int r,c;
|
||||||
|
|||||||
72
main.cpp
72
main.cpp
@@ -1,7 +1,6 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
#include "pivariantsimple.h"
|
#include "pivariantsimple.h"
|
||||||
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct MM {
|
struct MM {
|
||||||
int x;
|
int x;
|
||||||
@@ -14,9 +13,6 @@ struct MM {
|
|||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#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;
|
int Acnt = 0;
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
@@ -29,6 +25,7 @@ public:
|
|||||||
void swap(A & a) {piCout << "swap A()"; piSwap(i, a.i);}
|
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 =(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;}
|
A & operator =(A && a) {piSwap(i, a.i); a.moved = true; piCout << "= A&&)"; return *this;}
|
||||||
|
bool operator ==(const A & a) {return true;}
|
||||||
PIString i;
|
PIString i;
|
||||||
bool moved;
|
bool moved;
|
||||||
MM m;
|
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, 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, 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;}
|
||||||
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>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
PIByteArray ba;
|
PIByteArray ba;
|
||||||
// TypeHelper th;
|
|
||||||
// th.regtype<MM>();
|
|
||||||
MM m;
|
MM m;
|
||||||
memset(&m, 0xAC, sizeof(MM));
|
m.e = 2;
|
||||||
PIVector<MM> vm;
|
m.y = 0.1;
|
||||||
vm << m;
|
PIVector<MM> v;
|
||||||
|
//v.resize(1,2,m);
|
||||||
|
v << m << m;
|
||||||
|
|
||||||
|
piCout << "m:";
|
||||||
ba << m;
|
ba << m;
|
||||||
piCout << ba.toHex();
|
piCout << ba;
|
||||||
|
ba >> m;
|
||||||
|
piCout << ba;
|
||||||
|
|
||||||
ba.clear();
|
ba.clear();
|
||||||
piCout << "===";
|
piCout << "v:";
|
||||||
ba << vm;
|
ba << v;
|
||||||
piCout << ba.toHex();
|
piCout << ba;
|
||||||
// th.h->bsl(ba, &m);
|
ba >> v;
|
||||||
// th.regtype<CAN_Raw>();
|
piCout << ba;
|
||||||
// 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();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user