diff --git a/libs/main/core/pibytearray.cpp b/libs/main/core/pibytearray.cpp index f939ef0a..3c4a01a9 100644 --- a/libs/main/core/pibytearray.cpp +++ b/libs/main/core/pibytearray.cpp @@ -401,3 +401,14 @@ PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) { } return s; } + + +PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) { + s << int(v.size_s()); + int os = s.size_s(); + if (v.size_s() > 0) { + s.enlarge(v.size_s()); + memcpy(s.data(os), v.data(), v.size()); + } + return s; +} diff --git a/libs/main/core/pibytearray.h b/libs/main/core/pibytearray.h index a5e9488d..ad00a8a1 100644 --- a/libs/main/core/pibytearray.h +++ b/libs/main/core/pibytearray.h @@ -175,27 +175,18 @@ inline PIByteArray & operator <<(PIByteArray & s, const char v) {s.push_back(v); //! \relatesalso PIByteArray \brief Store operator inline PIByteArray & operator <<(PIByteArray & s, const uchar v) {s.push_back(v); return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, const PIChar & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;} - -//! \relatesalso PIByteArray \brief Store operator -template inline PIByteArray & operator <<(PIByteArray & s, const PIFlags & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;} - //! \relatesalso PIByteArray \brief Store operator for any trivial copyable type template::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const T & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;} - -//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details -inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) { - s << int(v.size_s()); +inline PIByteArray & operator <<(PIByteArray & s, const T & v) { int os = s.size_s(); - if (v.size_s() > 0) { - s.enlarge(v.size_s()); - memcpy(s.data(os), v.data(), v.size()); - } + s.enlarge(sizeof(v)); + memcpy(s.data(os), &v, sizeof(v)); return s; } +//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details +PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v); + //! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) { int os = s.size_s(); @@ -264,15 +255,14 @@ inline PIByteArray & operator >>(PIByteArray & s, char & v) {assert(s.size() >= //! \relatesalso PIByteArray \brief Restore operator inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >= 1u); v = s.take_front(); return s;} -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, PIChar & v) {assert(s.size() >= sizeof(v)); memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;} - //! \relatesalso PIByteArray \brief Restore operator for any trivial copyable type template::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, T & v) {assert(s.size() >= sizeof(v)); memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;} - -//! \relatesalso PIByteArray \brief Restore operator -template inline PIByteArray & operator >>(PIByteArray & s, PIFlags & v) {memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;} +inline PIByteArray & operator >>(PIByteArray & s, T & v) { + assert(s.size() >= sizeof(v)); + memcpy((void*)(&v), s.data(), sizeof(v)); + s.remove(0, sizeof(v)); + return s; +} //! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v); diff --git a/libs/main/core/pichar.h b/libs/main/core/pichar.h index a01b07ce..a2b5dad2 100644 --- a/libs/main/core/pichar.h +++ b/libs/main/core/pichar.h @@ -32,8 +32,6 @@ extern PIP_EXPORT char * __utf8name__; class PIP_EXPORT PIChar { friend class PIString; - friend PIByteArray & operator <<(PIByteArray & s, const PIChar & v); - friend PIByteArray & operator >>(PIByteArray & s, PIChar & v); friend PICout PIP_EXPORT operator <<(PICout s, const PIChar & v); public: //! Contructs ascii symbol diff --git a/libs/main/core/piflags.h b/libs/main/core/piflags.h index d7584dd5..6d824826 100644 --- a/libs/main/core/piflags.h +++ b/libs/main/core/piflags.h @@ -38,8 +38,6 @@ public: PIFlags(): flags(0) {;} //! Constructor with flags = Enum "e" PIFlags(Enum e): flags(e) {;} - //! Constructor with flags = PIFlags "f" - PIFlags(const PIFlags & f): flags(f.flags) {;} //! Constructor with flags = int "i" PIFlags(const int i): flags(i) {;} //! Set flags "f" to value "on" @@ -49,8 +47,6 @@ public: //! Set flag "i" to value "on" PIFlags & setFlag(const int & i, bool on = true) {if (on) flags |= i; else flags &= ~i; return *this;} //! copy operator - void operator =(const PIFlags & f) {flags = f.flags;} - //! copy operator void operator =(const Enum & e) {flags = e;} //! copy operator void operator =(const int & i) {flags = i;} diff --git a/libs/main/core/pipropertystorage.h b/libs/main/core/pipropertystorage.h index c338b968..9dc4098c 100644 --- a/libs/main/core/pipropertystorage.h +++ b/libs/main/core/pipropertystorage.h @@ -162,12 +162,12 @@ public: */ void setPropertyComment(const PIString & name, const PIString & comment); - /** - * @brief Set flags of property with specific name if name is present in storage. - * - * @param name of property to set flags - * @param flags to set - */ + /** + * @brief Set flags of property with specific name if name is present in storage. + * + * @param name of property to set flags + * @param flags to set + */ void setPropertyFlags(const PIString & name, int flags); PIPropertyStorage & operator <<(const PIPropertyStorage::Property & p) {props << p; return *this;} diff --git a/libs/main/core/pitime.h b/libs/main/core/pitime.h index 90df73c7..9c9a959d 100644 --- a/libs/main/core/pitime.h +++ b/libs/main/core/pitime.h @@ -60,8 +60,6 @@ public: //! Contructs system time with s = "s" and ns = "ns" PISystemTime(int s, int ns) {seconds = s; nanoseconds = ns; checkOverflows();} - //! Contructs system time from another - PISystemTime(const PISystemTime & t) {seconds = t.seconds; nanoseconds = t.nanoseconds;} //! Returns stored system time value in seconds double toSeconds() const {return double(seconds) + nanoseconds / 1.e+9;} @@ -172,13 +170,6 @@ private: //! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout inline PICout operator <<(PICout s, const PISystemTime & v) {s.space(); s.setControl(0, true); s << "(" << v.seconds << " s, " << v.nanoseconds << " ns)"; s.restoreControl(); return s;} -//! \relatesalso PISystemTime \relatesalso PIByteArray \brief Output operator to PIByteArray -inline PIByteArray & operator <<(PIByteArray & s, const PISystemTime & v) {s << v.seconds << v.nanoseconds; return s;} - -//! \relatesalso PISystemTime \relatesalso PIByteArray \brief Input operator from PIByteArray -inline PIByteArray & operator >>(PIByteArray & s, PISystemTime & v) {s >> v.seconds >> v.nanoseconds; return s;} - - struct PIP_EXPORT PITime { @@ -199,8 +190,6 @@ PIP_EXPORT bool operator >(const PITime & t0, const PITime & t1); inline bool operator !=(const PITime & t0, const PITime & t1) {return !(t0 == t1);} inline bool operator <=(const PITime & t0, const PITime & t1) {return !(t0 > t1);} inline bool operator >=(const PITime & t0, const PITime & t1) {return !(t0 < t1);} -inline PIByteArray & operator <<(PIByteArray & s, const PITime & v) {s << v.hours << v.minutes << v.seconds << v.milliseconds; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PITime & v) {s >> v.hours >> v.minutes >> v.seconds >> v.milliseconds; return s;} //! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout PIP_EXPORT PICout operator <<(PICout s, const PITime & v); @@ -223,8 +212,6 @@ PIP_EXPORT bool operator >(const PIDate & t0, const PIDate & t1); inline bool operator !=(const PIDate & t0, const PIDate & t1) {return !(t0 == t1);} inline bool operator <=(const PIDate & t0, const PIDate & t1) {return !(t0 > t1);} inline bool operator >=(const PIDate & t0, const PIDate & t1) {return !(t0 < t1);} -inline PIByteArray & operator <<(PIByteArray & s, const PIDate & v) {s << v.year << v.month << v.day; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIDate & v) {s >> v.year >> v.month >> v.day; return s;} //! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout PIP_EXPORT PICout operator <<(PICout s, const PIDate & v); diff --git a/libs/main/io_devices/piethernet.h b/libs/main/io_devices/piethernet.h index bb9f988e..266134a0 100644 --- a/libs/main/io_devices/piethernet.h +++ b/libs/main/io_devices/piethernet.h @@ -65,8 +65,6 @@ public: //! \brief IPv4 network address, IP and port class PIP_EXPORT Address { friend class PIEthernet; - friend inline PIByteArray & operator <<(PIByteArray & s, const PIEthernet::Address & v); - friend inline PIByteArray & operator >>(PIByteArray & s, PIEthernet::Address & v); public: //! Contructs %Address with binary representation of IP and port @@ -519,7 +517,5 @@ inline PICout operator <<(PICout s, const PIEthernet::Address & v) {s.space(); s inline bool operator ==(const PIEthernet::Address & v0, const PIEthernet::Address & v1) {return (v0.ip() == v1.ip() && v0.port() == v1.port());} inline bool operator !=(const PIEthernet::Address & v0, const PIEthernet::Address & v1) {return (v0.ip() != v1.ip() || v0.port() != v1.port());} -inline PIByteArray & operator <<(PIByteArray & s, const PIEthernet::Address & v) {s << v.ip_ << v.port_; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIEthernet::Address & v) {s >> v.ip_ >> v.port_; return s;} #endif // PIETHERNET_H diff --git a/libs/main/math/pigeometry.h b/libs/main/math/pigeometry.h index ad2df750..65bf39d1 100644 --- a/libs/main/math/pigeometry.h +++ b/libs/main/math/pigeometry.h @@ -59,12 +59,6 @@ public: template PICout operator <<(PICout & s, const PIPoint & v) {s.setControl(0, true); s << "Point{" << v.x << ", " << v.y << "}"; s.restoreControl(); return s;} -template -inline PIByteArray & operator <<(PIByteArray & s, const PIPoint & v) {s << v.x << v.y; return s;} - -template -inline PIByteArray & operator >>(PIByteArray & s, PIPoint & v) {s >> v.x >> v.y; return s;} - typedef PIPoint PIPointi; typedef PIPoint PIPointu; @@ -145,12 +139,6 @@ public: template PICout operator <<(PICout & s, const PIRect & v) {s.setControl(0, true); s << "Rect{" << v.x0 << ", " << v.y0 << "; " << v.x1 - v.x0 << ", " << v.y1 - v.y0 << "}"; s.restoreControl(); return s;} -template -inline PIByteArray & operator <<(PIByteArray & s, const PIRect & v) {s << v.x0 << v.x1 << v.y0 << v.y1; return s;} - -template -inline PIByteArray & operator >>(PIByteArray & s, PIRect & v) {s >> v.x0 >> v.x1 >> v.y0 >> v.y1; return s;} - typedef PIRect PIRecti; typedef PIRect PIRectu; diff --git a/libs/main/math/pimathcomplex.h b/libs/main/math/pimathcomplex.h index 79e651d5..369513a4 100644 --- a/libs/main/math/pimathcomplex.h +++ b/libs/main/math/pimathcomplex.h @@ -69,20 +69,6 @@ inline complexd log10(const complexd & c) {return log(c) / M_LN10;} template inline PICout operator <<(PICout s, const complex & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, complexf v) {float t; t = v.real(); s << t; t = v.imag(); s << t; return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, complexd v) {double t; t = v.real(); s << t; t = v.imag(); s << t; return s;} -//! \relatesalso PIByteArray \brief Store operator -inline PIByteArray & operator <<(PIByteArray & s, complexld v) {ldouble t; t = v.real(); s << t; t = v.imag(); s << t; return s;} - -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, complexf & v) {float t0, t1; s >> t0; s >> t1; v = complexf(t0, t1); return s;} -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, complexd & v) {double t0, t1; s >> t0; s >> t1; v = complexd(t0, t1); return s;} -//! \relatesalso PIByteArray \brief Restore operator -inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;} - inline PIVector abs(const PIVector & v) { PIVector result; diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 7c4a9b41..09b8d07b 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -130,6 +130,7 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;} + template inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector() << x << y);} template diff --git a/main.cpp b/main.cpp index 28bd520d..732d268d 100644 --- a/main.cpp +++ b/main.cpp @@ -74,6 +74,14 @@ inline PICout operator <<(PICout c, const SwitchChannel & v) { int Acnt = 0; +struct MM { + int x; + double y; + char c; + PIPointd h; +}; + + class A { public: A() {moved = false; i = "constructor"; piCout << "A()"; ++Acnt;} @@ -86,10 +94,12 @@ public: A & operator =(A && a) {piSwap(i, a.i); a.moved = true; piCout << "= A&&)"; return *this;} PIString i; bool moved; + MM m; static void F(int) {} }; -PIByteArray & operator <<(PIByteArray & ba, const A & v) {ba << v.i; return ba;} -PIByteArray & operator >>(PIByteArray & ba, A & v) {ba >> v.i; 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;} int main() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07693426..bebb15da 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,4 +17,3 @@ endmacro() # Concurrent tests pip_test(concurrent "") pip_test(math "") -#pip_test(core "")