diff --git a/main.cpp b/main.cpp index 31a3ed1b..d37706be 100644 --- a/main.cpp +++ b/main.cpp @@ -3,8 +3,14 @@ int main(int argc, char *argv[]) { - PIConnection conn; - conn.configureFromConfig("0.conf"); + PIVector2D v(2, 2, PIVector() << PIVariant(1) << PIVariant(2) << PIVariant(3) << PIVariant(4)); + piCout << v; + PIByteArray ba; + ba << v; + piCout << ba.size(); + PIVector2D v2; + ba >> v2; + piCout << v2; return 0; } diff --git a/src_main/containers/pivector2d.h b/src_main/containers/pivector2d.h index d51cb617..d4ed2e16 100644 --- a/src_main/containers/pivector2d.h +++ b/src_main/containers/pivector2d.h @@ -126,6 +126,12 @@ public: } PIVector toPlainVector() const {return mat;} + inline PIVector2D & _resizeRaw(size_t r, size_t c) { + piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIVECTOR_SIMPLE_TYPE__ macro!"; + assert(0); + return *this; + } + private: inline void copyRow(size_t start, const T * data, size_t size) { for (size_t i = 0; i < size; i++) @@ -156,4 +162,23 @@ inline PICout operator <<(PICout s, const PIVector2D & v) { return s; } +#define __PIVECTOR2D_SIMPLE_TYPE__(T) \ + template<> inline void PIVector2D::copyRow(size_t start, const T * data, size_t size) {memcpy(mat.data(start), data, size * sizeof(T));} \ + template<> inline PIVector2D & PIVector2D::_resizeRaw(size_t r, size_t c) {rows_ = r; cols_ = c; mat._resizeRaw(r*c); return *this;} + +__PIVECTOR2D_SIMPLE_TYPE__(bool) +__PIVECTOR2D_SIMPLE_TYPE__(char) +__PIVECTOR2D_SIMPLE_TYPE__(uchar) +__PIVECTOR2D_SIMPLE_TYPE__(short) +__PIVECTOR2D_SIMPLE_TYPE__(ushort) +__PIVECTOR2D_SIMPLE_TYPE__(int) +__PIVECTOR2D_SIMPLE_TYPE__(uint) +__PIVECTOR2D_SIMPLE_TYPE__(long) +__PIVECTOR2D_SIMPLE_TYPE__(ulong) +__PIVECTOR2D_SIMPLE_TYPE__(llong) +__PIVECTOR2D_SIMPLE_TYPE__(ullong) +__PIVECTOR2D_SIMPLE_TYPE__(float) +__PIVECTOR2D_SIMPLE_TYPE__(double) +__PIVECTOR2D_SIMPLE_TYPE__(ldouble) + #endif // PIVECTOR2D_H diff --git a/src_main/core/pibytearray.h b/src_main/core/pibytearray.h index 383803c7..599ed60e 100755 --- a/src_main/core/pibytearray.h +++ b/src_main/core/pibytearray.h @@ -26,6 +26,7 @@ #include "pichar.h" #include "pibitarray.h" #include "pimap.h" +#include "pivector2d.h" __PICONTAINERS_SIMPLE_TYPE__(PIChar) @@ -37,7 +38,11 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.siz template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ +template<> \ +inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) {s << int(v.rows()) << int(v.cols()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ +template<> \ +inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} class PIString; @@ -244,6 +249,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIMap & v) { s << v.pim_content; return s; } +template +inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) {s << int(v.rows()) << int(v.cols()) << v.toPlainVector(); return s;} //! \relatesalso PIByteArray \brief Restore operator @@ -263,6 +270,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIMap & v) { s >> v.pim_content; return s; } +template +inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) {assert(s.size_s() >= 8); int r,c; PIVector tmp; s >> r >> c >> tmp; v = PIVector2D(r, c, tmp); return s;} + template inline PIByteArray & operator <<(PIByteArray & s, const T & ) {piCout << "[PIByteArray] Warning: using undeclared operator < #include "pimathbase.h" #include "pibytearray.h" +#include "pivector2d.h" #define PIP_MATH_COMPLEX @@ -49,6 +50,10 @@ __PICONTAINERS_SIMPLE_TYPE__(complexi) __PICONTAINERS_SIMPLE_TYPE__(complexf) __PICONTAINERS_SIMPLE_TYPE__(complexd) __PICONTAINERS_SIMPLE_TYPE__(complexld) +__PIVECTOR2D_SIMPLE_TYPE__(complexi) +__PIVECTOR2D_SIMPLE_TYPE__(complexf) +__PIVECTOR2D_SIMPLE_TYPE__(complexd) +__PIVECTOR2D_SIMPLE_TYPE__(complexld) __PIBYTEARRAY_SIMPLE_TYPE__(complexi) __PIBYTEARRAY_SIMPLE_TYPE__(complexf) __PIBYTEARRAY_SIMPLE_TYPE__(complexd)