From b2bc385397fa7dfb338a22af71bac8616d6b550b Mon Sep 17 00:00:00 2001 From: peri4 Date: Tue, 10 May 2022 15:23:18 +0300 Subject: [PATCH] PIByteArray works on binary stream --- 3rd/lua/lapi.c | 2 +- 3rd/lua/lcode.c | 2 +- 3rd/lua/lctype.c | 2 +- 3rd/lua/ldebug.c | 2 +- 3rd/lua/ldo.c | 2 +- 3rd/lua/ldump.c | 2 +- 3rd/lua/lfunc.c | 2 +- 3rd/lua/lgc.c | 2 +- 3rd/lua/llex.c | 2 +- 3rd/lua/lmem.c | 2 +- 3rd/lua/lobject.c | 2 +- 3rd/lua/lopcodes.c | 2 +- 3rd/lua/lparser.c | 2 +- 3rd/lua/lstate.c | 2 +- 3rd/lua/lstring.c | 2 +- 3rd/lua/ltable.c | 2 +- 3rd/lua/ltm.c | 2 +- 3rd/lua/lundump.c | 2 +- 3rd/lua/lvm.c | 2 +- 3rd/lua/lzio.c | 2 +- libs/cloud/picloudtcp.cpp | 4 +- libs/compress/picompress.cpp | 2 +- libs/main/console/pikbdlistener.h | 6 - libs/main/console/piscreentypes.h | 6 +- libs/main/containers/pimap.h | 8 +- libs/main/core/pibinarystream.h | 25 +- libs/main/core/pibitarray.h | 6 +- libs/main/core/pibytearray.cpp | 35 -- libs/main/core/pibytearray.h | 496 +----------------- libs/main/core/pichunkstream.cpp | 2 +- libs/main/core/pichunkstream.h | 2 +- libs/main/core/pidatetime.h | 10 - libs/main/core/pimemoryblock.h | 60 +++ libs/main/core/pipropertystorage.h | 4 - libs/main/core/pistring.h | 4 - libs/main/core/pistringlist.h | 11 - libs/main/core/pivariant.h | 42 +- libs/main/core/pivarianttypes.h | 12 - .../piintrospection_containers_p.cpp | 12 - .../piintrospection_containers_p.h | 2 - .../piintrospection_server_p.cpp | 76 --- .../introspection/piintrospection_server_p.h | 9 - .../piintrospection_threads_p.cpp | 16 - .../introspection/piintrospection_threads_p.h | 2 - libs/main/io_devices/pifile.h | 15 +- libs/main/io_devices/pipeer.h | 16 +- libs/main/io_utils/pibasetransfer.h | 15 +- libs/main/io_utils/pifiletransfer.h | 18 +- libs/main/math/pievaluator.h | 46 +- libs/main/math/pimathmatrix.h | 12 +- libs/main/math/pimathvector.h | 14 +- libs/main/resources/piresourcesstorage.cpp | 27 - libs/main/resources/piresourcesstorage.h | 26 +- libs/main/system/pisystemmonitor.cpp | 31 -- libs/main/system/pisystemmonitor.h | 29 +- main.cpp | 22 +- utils/piterminal/main.cpp | 2 +- utils/system_daemon/daemon.h | 12 +- 58 files changed, 254 insertions(+), 923 deletions(-) create mode 100644 libs/main/core/pimemoryblock.h diff --git a/3rd/lua/lapi.c b/3rd/lua/lapi.c index 02b7fab7..ec4bdddd 100644 --- a/3rd/lua/lapi.c +++ b/3rd/lua/lapi.c @@ -5,7 +5,7 @@ */ #define lapi_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lcode.c b/3rd/lua/lcode.c index 12619f54..7f32d33c 100644 --- a/3rd/lua/lcode.c +++ b/3rd/lua/lcode.c @@ -5,7 +5,7 @@ */ #define lcode_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lctype.c b/3rd/lua/lctype.c index f8ad7a2e..7d8123d2 100644 --- a/3rd/lua/lctype.c +++ b/3rd/lua/lctype.c @@ -5,7 +5,7 @@ */ #define lctype_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/ldebug.c b/3rd/lua/ldebug.c index e1389296..110146c9 100644 --- a/3rd/lua/ldebug.c +++ b/3rd/lua/ldebug.c @@ -5,7 +5,7 @@ */ #define ldebug_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/ldo.c b/3rd/lua/ldo.c index 316e45c8..36e7d26d 100644 --- a/3rd/lua/ldo.c +++ b/3rd/lua/ldo.c @@ -5,7 +5,7 @@ */ #define ldo_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/ldump.c b/3rd/lua/ldump.c index f025acac..222b372d 100644 --- a/3rd/lua/ldump.c +++ b/3rd/lua/ldump.c @@ -5,7 +5,7 @@ */ #define ldump_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lfunc.c b/3rd/lua/lfunc.c index ccafbb8a..897526c4 100644 --- a/3rd/lua/lfunc.c +++ b/3rd/lua/lfunc.c @@ -5,7 +5,7 @@ */ #define lfunc_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lgc.c b/3rd/lua/lgc.c index db4df829..6fe4a808 100644 --- a/3rd/lua/lgc.c +++ b/3rd/lua/lgc.c @@ -5,7 +5,7 @@ */ #define lgc_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/llex.c b/3rd/lua/llex.c index 66fd411b..42f0f247 100644 --- a/3rd/lua/llex.c +++ b/3rd/lua/llex.c @@ -5,7 +5,7 @@ */ #define llex_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lmem.c b/3rd/lua/lmem.c index 0241cc3b..bf081c28 100644 --- a/3rd/lua/lmem.c +++ b/3rd/lua/lmem.c @@ -5,7 +5,7 @@ */ #define lmem_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lobject.c b/3rd/lua/lobject.c index 2218c8cd..25547694 100644 --- a/3rd/lua/lobject.c +++ b/3rd/lua/lobject.c @@ -5,7 +5,7 @@ */ #define lobject_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lopcodes.c b/3rd/lua/lopcodes.c index 5ca3eb26..744bda77 100644 --- a/3rd/lua/lopcodes.c +++ b/3rd/lua/lopcodes.c @@ -5,7 +5,7 @@ */ #define lopcodes_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lparser.c b/3rd/lua/lparser.c index cc54de43..23ebf10a 100644 --- a/3rd/lua/lparser.c +++ b/3rd/lua/lparser.c @@ -5,7 +5,7 @@ */ #define lparser_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lstate.c b/3rd/lua/lstate.c index c1a76643..fa96483f 100644 --- a/3rd/lua/lstate.c +++ b/3rd/lua/lstate.c @@ -5,7 +5,7 @@ */ #define lstate_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lstring.c b/3rd/lua/lstring.c index 6257f211..14103e22 100644 --- a/3rd/lua/lstring.c +++ b/3rd/lua/lstring.c @@ -5,7 +5,7 @@ */ #define lstring_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/ltable.c b/3rd/lua/ltable.c index ea4fe7fc..ae9145f1 100644 --- a/3rd/lua/ltable.c +++ b/3rd/lua/ltable.c @@ -5,7 +5,7 @@ */ #define ltable_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/ltm.c b/3rd/lua/ltm.c index 0e7c7132..aa61c87d 100644 --- a/3rd/lua/ltm.c +++ b/3rd/lua/ltm.c @@ -5,7 +5,7 @@ */ #define ltm_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lundump.c b/3rd/lua/lundump.c index 7a67d75a..b3e79253 100644 --- a/3rd/lua/lundump.c +++ b/3rd/lua/lundump.c @@ -5,7 +5,7 @@ */ #define lundump_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lvm.c b/3rd/lua/lvm.c index cc43d871..da27d5e9 100644 --- a/3rd/lua/lvm.c +++ b/3rd/lua/lvm.c @@ -5,7 +5,7 @@ */ #define lvm_c -#define LUA_CORE + #include "lprefix.h" diff --git a/3rd/lua/lzio.c b/3rd/lua/lzio.c index 6f790944..b2ef5c4c 100644 --- a/3rd/lua/lzio.c +++ b/3rd/lua/lzio.c @@ -5,7 +5,7 @@ */ #define lzio_c -#define LUA_CORE + #include "lprefix.h" diff --git a/libs/cloud/picloudtcp.cpp b/libs/cloud/picloudtcp.cpp index 178560fe..a5ff2a6c 100644 --- a/libs/cloud/picloudtcp.cpp +++ b/libs/cloud/picloudtcp.cpp @@ -168,14 +168,14 @@ PIByteArray PICloud::TCP::parseConnect_d(PIByteArray & ba) { uint PICloud::TCP::parseConnect(PIByteArray & ba) { - uint ret; + uint ret = 0; ba >> ret; return ret; } uint PICloud::TCP::parseDisconnect(PIByteArray & ba) { - uint ret; + uint ret = 0; ba >> ret; return ret; } diff --git a/libs/compress/picompress.cpp b/libs/compress/picompress.cpp index 6fc21a30..3e450960 100644 --- a/libs/compress/picompress.cpp +++ b/libs/compress/picompress.cpp @@ -53,7 +53,7 @@ PIByteArray piCompress(const PIByteArray & ba, int level) { PIByteArray piDecompress(const PIByteArray & zba) { #ifdef PIP_COMPRESS - ullong sz; + ullong sz = 0; if (zba.size() < sizeof(ullong)) { piCout << "[PICompress]" << "Error: invalid input"; return zba; diff --git a/libs/main/console/pikbdlistener.h b/libs/main/console/pikbdlistener.h index 27f278de..b266d11e 100644 --- a/libs/main/console/pikbdlistener.h +++ b/libs/main/console/pikbdlistener.h @@ -247,12 +247,6 @@ private: }; -inline PIByteArray & operator <<(PIByteArray & s, const PIKbdListener::MouseEvent & v) {s << v.x << v.y << (int)v.action << v.buttons << v.modifiers; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIKbdListener::WheelEvent & v) {s << (*(PIKbdListener::MouseEvent*)&v) << (uchar)v.direction; return s;} - -inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::MouseEvent & v) {int a(0); s >> v.x >> v.y >> a >> v.buttons >> v.modifiers; v.action = (PIKbdListener::MouseAction)a; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::WheelEvent & v) {uchar d(0); s >> (*(PIKbdListener::MouseEvent*)&v) >> d; v.direction = d; return s;} - BINARY_STREAM_STORE(PIKbdListener::MouseEvent) {s << v.x << v.y << v.action << v.buttons << v.modifiers; return s;} BINARY_STREAM_RESTORE(PIKbdListener::MouseEvent) {s >> v.x >> v.y >> v.action >> v.buttons >> v.modifiers; return s;} diff --git a/libs/main/console/piscreentypes.h b/libs/main/console/piscreentypes.h index 4a7b15cb..5f33b4f5 100644 --- a/libs/main/console/piscreentypes.h +++ b/libs/main/console/piscreentypes.h @@ -146,10 +146,10 @@ namespace PIScreenTypes { //inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::Cell & v) {s << v.format.raw_format << v.symbol; return s;} //inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::Cell & v) {s >> v.format.raw_format >> v.symbol; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::TileEvent & v) {s << v.type << v.data; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::TileEvent & v) {s >> v.type >> v.data; return s;} +BINARY_STREAM_STORE (PIScreenTypes::Cell) {s << v.format.raw_format << v.symbol; return s;} +BINARY_STREAM_RESTORE(PIScreenTypes::Cell) {s >> v.format.raw_format >> v.symbol; return s;} -BINARY_STREAM_STORE(PIScreenTypes::TileEvent) {s << v.type << v.data; return s;} +BINARY_STREAM_STORE (PIScreenTypes::TileEvent) {s << v.type << v.data; return s;} BINARY_STREAM_RESTORE(PIScreenTypes::TileEvent) {s >> v.type >> v.data; return s;} REGISTER_PIVARIANTSIMPLE(PIScreenTypes::TileEvent) diff --git a/libs/main/containers/pimap.h b/libs/main/containers/pimap.h index 85dbddaf..bfe94175 100644 --- a/libs/main/containers/pimap.h +++ b/libs/main/containers/pimap.h @@ -71,8 +71,6 @@ class PIMapIterator; template class PIMap { - template friend PIByteArray & operator >>(PIByteArray & s, PIMap & v); - template friend PIByteArray & operator <<(PIByteArray & s, const PIMap & v); template friend class PIMapIterator; template friend PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIMap & v); @@ -299,8 +297,10 @@ protected: bool operator <(const MapIndex & s) const {return key < s.key;} bool operator >(const MapIndex & s) const {return key > s.key;} }; - template friend PIByteArray & operator >>(PIByteArray & s, PIDeque::MapIndex> & v); - template friend PIByteArray & operator <<(PIByteArray & s, const PIDeque::MapIndex> & v); + template + friend PIBinaryStream

& operator >>(PIBinaryStream

& s, PIDeque::MapIndex> & v); + template + friend PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIDeque::MapIndex> & v); ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const { ssize_t mid; diff --git a/libs/main/core/pibinarystream.h b/libs/main/core/pibinarystream.h index 4ff2a73b..35625665 100644 --- a/libs/main/core/pibinarystream.h +++ b/libs/main/core/pibinarystream.h @@ -26,6 +26,7 @@ #ifndef PIBINARYSTREAM_H #define PIBINARYSTREAM_H +#include "pimemoryblock.h" #include "pibitarray.h" #include "pimap.h" #include "pivector2d.h" @@ -86,7 +87,7 @@ template inline PIBinaryStream

& operator <<(PIBinary template inline PIBinaryStream

& operator >>(PIBinaryStreamTrivialRef

s, T & v) {s.p >> v; return s.p;} -// small types +// specify types template inline PIBinaryStreamTrivialRef

operator <<(PIBinaryStream

& s, const bool v) {s.binaryStreamAppend((uchar)v); return s;} template inline PIBinaryStreamTrivialRef

operator <<(PIBinaryStream

& s, const char v) {s.binaryStreamAppend((uchar)v); return s;} template inline PIBinaryStreamTrivialRef

operator <<(PIBinaryStream

& s, const uchar v) {s.binaryStreamAppend((uchar)v); return s;} @@ -94,6 +95,15 @@ template inline PIBinaryStreamTrivialRef

operator >>(PIBinaryStre template inline PIBinaryStreamTrivialRef

operator >>(PIBinaryStream

& s, char & v) {v = s.binaryStreamTakeByte(); return s;} template inline PIBinaryStreamTrivialRef

operator >>(PIBinaryStream

& s, uchar & v) {v = s.binaryStreamTakeByte(); return s;} +template inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIMemoryBlock v) { + s.binaryStreamAppend(v.data(), v.size()); + return s; +} +template inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIMemoryBlock v) { + s.binaryStreamTake(v.data(), v.size()); + return s; +} + @@ -308,7 +318,18 @@ inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIVector2D & v) v = PIVector2D(r, c, tmp); return s; } -; + + +//! \~english Restore operator +//! \~russian Оператор извлечения +template +inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIBitArray & v) {s >> v.size_ >> v.data_; return s;} + + +//! \~english Restore operator +//! \~russian Оператор извлечения +template +inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIPair & v) {s >> v.first >> v.second; return s;} diff --git a/libs/main/core/pibitarray.h b/libs/main/core/pibitarray.h index c9eae0e9..65574b51 100644 --- a/libs/main/core/pibitarray.h +++ b/libs/main/core/pibitarray.h @@ -28,8 +28,10 @@ #include "pivector.h" class PIP_EXPORT PIBitArray { - friend PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v); - friend PIByteArray & operator >>(PIByteArray & s, PIBitArray & v); + template + friend PIBinaryStream

& operator >>(PIBinaryStream

& s, PIBitArray & v); + template + friend PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIBitArray & v); public: PIBitArray(const int & size = 0) {resize(size);} PIBitArray(uchar val) {resize(sizeof(val) * 8); data_[0] = val;} diff --git a/libs/main/core/pibytearray.cpp b/libs/main/core/pibytearray.cpp index bdc33f1c..c589e584 100644 --- a/libs/main/core/pibytearray.cpp +++ b/libs/main/core/pibytearray.cpp @@ -438,38 +438,3 @@ std::ostream &operator <<(std::ostream & s, const PIByteArray & ba) { return s; } #endif - - -PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) { - if (s.size_s() < 4) { - s.clear(); - v.clear(); - return s; - } - assert(s.size_s() >= 4); - int sz = 0; - s >> sz; - if (sz > s.size_s()) { - piCout << "[PIByteArray] Warning: operator >> wants too much data, discard!" << sz << s.size_s(); - s.clear(); - v.clear(); - return s; - } - v.resize(sz); - if (sz > 0) { - memcpy(v.data(), s.data(), sz); - s.remove(0, sz); - } - 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 0999baec..f2221090 100644 --- a/libs/main/core/pibytearray.h +++ b/libs/main/core/pibytearray.h @@ -38,9 +38,10 @@ class PIByteArray; //! \~\brief //! \~english The %PIByteArray class provides an array of bytes. //! \~russian Класс %PIByteArray представляет собой массив байтов. -class PIP_EXPORT PIByteArray: public PIDeque +class PIP_EXPORT PIByteArray: public PIDeque, public PIBinaryStream { public: + typedef ::PIMemoryBlock RawData; //! \~english Constructs an empty byte array //! \~russian Создает пустой байтовый массив @@ -69,28 +70,6 @@ public: PIByteArray(const uint size, uchar t): PIDeque(size, t) {} - //! \~english Help struct to store/restore custom blocks of data to/from PIByteArray - //! \~russian Вспомогательная структура для сохранения/извлечения произвольного блока данных в/из байтового массива - struct RawData { - friend PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v); - friend PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v); - public: - //! \~english Constructs data block - //! \~russian Создает блок данных - RawData(void * data_ = 0, int size_ = 0) {d = data_; s = size_;} - RawData(const RawData & o) {d = o.d; s = o.s;} - //! \~english Constructs data block - //! \~russian Создает блок данных - RawData(const void * data_, const int size_) {d = const_cast(data_); s = size_;} - RawData & operator =(const RawData & o) {d = o.d; s = o.s; return *this;} - void * data() {return d;} - const void * data() const {return d;} - int size() const {return s;} - private: - void * d; - int s; - }; - //! \~english Return resized byte array //! \~russian Возвращает копию байтового массива с измененным размером PIByteArray resized(uint new_size) const {PIByteArray ret(new_size); memcpy(ret.data(), data(), new_size); return ret;} @@ -171,13 +150,17 @@ public: static PIByteArray fromBase64(const PIString & base64); - class StreamRef { - public: - StreamRef(PIByteArray & s): ba(s) {} - operator PIByteArray&() {return ba;} - private: - PIByteArray & ba; - }; + bool binaryStreamAppendImp(const void * d, size_t s) { + append(d, s); + return true; + } + bool binaryStreamTakeImp(void * d, size_t s) { + if (size() < s) + return false; + memcpy(d, data(), s); + remove(0, s); + return true; + } }; @@ -236,459 +219,6 @@ inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba); PIP_EXPORT PICout operator <<(PICout s, const PIByteArray & ba); - - -// store operators for basic types - - -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const bool v) {s.push_back(v); return s;} - -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const char v) {s.push_back(v); return s;} - -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const uchar v) {s.push_back(v); return s;} - -//! \relatesalso PIByteArray -//! \~english Store operator for any trivial copyable type -//! \~russian Оператор сохранения для тривиальных типов -template::value, int>::type = 0> -inline PIByteArray::StreamRef 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 -//! \~english Store operator, see \ref PIByteArray_sec1 for details -//! \~russian Оператор сохранения, подробнее в \ref PIByteArray_sec1 -PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v); - -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) { - int os = s.size_s(); - if (v.s > 0) { - s.enlarge(v.s); - memcpy(s.data(os), v.d, v.s); - } - return s; -} - -//! \relatesalso PIByteArray -//! \~english Store operator for PIVector of any trivial copyable type -//! \~russian Оператор сохранения для PIVector тривиальных типов -template::value, int>::type = 0, - typename std::enable_if< std::is_same() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) { - s << int(v.size_s()); - int os = s.size_s(); - if (v.size_s() > 0) { - s.enlarge(v.size_s()*sizeof(T)); - memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); - } - return s; -} -template::value, int>::type = 0, - typename std::enable_if() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) { - s << int(v.size_s()); - for (uint i = 0; i < v.size(); ++i) s << v[i]; - return s; -} - -//! \relatesalso PIByteArray -//! \~english Store operator for PIDeque of any trivial copyable type -//! \~russian Оператор сохранения для PIDeque тривиальных типов -template::value, int>::type = 0, - typename std::enable_if< std::is_same() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) { - s << int(v.size_s()); - int os = s.size_s(); - if (v.size_s() > 0) { - s.enlarge(v.size_s()*sizeof(T)); - memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); - } - return s; -} -template::value, int>::type = 0, - typename std::enable_if() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) { - s << int(v.size_s()); - for (uint i = 0; i < v.size(); ++i) s << v[i]; - return s; -} - -//! \relatesalso PIByteArray -//! \~english Store operator for PIVector2D of any trivial copyable type -//! \~russian Оператор сохранения для PIVector2D тривиальных типов -template::value, int>::type = 0, - typename std::enable_if< std::is_same() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) { - s << int(v.rows()) << int(v.cols()); - int os = s.size_s(); - if (v.size_s() > 0) { - s.enlarge(v.size_s()*sizeof(T)); - memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); - } - return s; -} -template::value, int>::type = 0, - typename std::enable_if() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) { - s << int(v.rows()) << int(v.cols()) << v.toPlainVector(); - return s; -} - -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;} - -//! \relatesalso PIPair -//! \~english Store operator -//! \~russian Оператор сохранения -template -inline PIByteArray & operator <<(PIByteArray & s, const PIPair & v) {s << v.first << v.second; return s;} - - - - -// restore operators for basic types - - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, bool & v) {assert(s.size() >= 1u); v = s.take_front(); return s;} - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, char & v) {assert(s.size() >= 1u); v = s.take_front(); return s;} - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >= 1u); v = s.take_front(); return s;} - -//! \relatesalso PIByteArray -//! \~english Restore operator for any trivial copyable type -//! \~russian Оператор извлечения для тривиальных типов -template::value, int>::type = 0> -inline PIByteArray::StreamRef operator >>(PIByteArray & s, T & v) { - if (s.size() < sizeof(v)) { - printf("error with %s\n", __PIP_TYPENAME__(T)); - assert(s.size() >= sizeof(v)); - } - memcpy((void*)(&v), s.data(), sizeof(v)); - s.remove(0, sizeof(v)); - return s; -} - -//! \relatesalso PIByteArray -//! \~english Restore operator, see \ref PIByteArray_sec1 for details -//! \~russian Оператор извлечения, подробнее в \ref PIByteArray_sec1 -PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v); - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) { - if (s.size_s() < v.s) { - printf("error with RawData %d < %d\n", (int)s.size_s(), v.s); - assert(s.size_s() >= v.s); - } - if (v.s > 0) { - memcpy((void*)(v.d), s.data(), v.s); - s.remove(0, v.s); - } - return s; -} - -//! \relatesalso PIByteArray -//! \~english Restore operator for PIVector of any trivial copyable type -//! \~russian Оператор извлечения для PIVector тривиальных типов -template::value, int>::type = 0, - typename std::enable_if< std::is_same() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { - if (s.size_s() < 4) { - printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T)); - 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::value, int>::type = 0, - typename std::enable_if() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { - if (s.size_s() < 4) { - printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T)); - 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 -//! \~english Restore operator for PIDeque of any trivial copyable type -//! \~russian Оператор извлечения для PIDeque тривиальных типов -template::value, int>::type = 0, - typename std::enable_if< std::is_same() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { - if (s.size_s() < 4) { - printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T)); - 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::value, int>::type = 0, - typename std::enable_if() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { - if (s.size_s() < 4) { - printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T)); - 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 -//! \~english Restore operator for PIVector2D of any trivial copyable type -//! \~russian Оператор извлечения для PIVector2D тривиальных типов -template::value, int>::type = 0, - typename std::enable_if< std::is_same() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) { - if (s.size_s() < 8) { - printf("error with PIVecto2Dr<%s>\n", __PIP_TYPENAME__(T)); - 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; -} -template::value, int>::type = 0, - typename std::enable_if() << std::declval()), PIByteArray::StreamRef>::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) { - if (s.size_s() < 8) { - printf("error with PIVecto2Dr<%s>\n", __PIP_TYPENAME__(T)); - assert(s.size_s() >= 8); - } - int r,c; - PIVector tmp; - s >> r >> c >> tmp; - v = PIVector2D(r, c, tmp); - return s; -} - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, PIBitArray & v) {assert(s.size_s() >= 8); s >> v.size_ >> v.data_; return s;} - -//! \relatesalso PIPair -//! \~english Restore operator -//! \~russian Оператор извлечения -template -inline PIByteArray & operator >>(PIByteArray & s, PIPair & v) {s >> v.first >> v.second; return s;} - - - - -// store operators for complex types - - -//! \relatesalso PIByteArray -//! \~english Store operator for PIVector of any compound type -//! \~russian Оператор сохранения для PIVector сложных типов -template::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) { - s << int(v.size_s()); - for (uint i = 0; i < v.size(); ++i) s << v[i]; - return s; -} - -//! \relatesalso PIByteArray -//! \~english Store operator for PIDeque of any compound type -//! \~russian Оператор сохранения для PIDeque сложных типов -template::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) { - s << int(v.size_s()); - for (uint i = 0; i < v.size(); ++i) s << v[i]; - return s; -} - -//! \relatesalso PIByteArray -//! \~english Store operator for PIVector2D of any compound type -//! \~russian Оператор сохранения для PIVector2D сложных типов -template::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) { - s << int(v.rows()) << int(v.cols()) << v.toPlainVector(); - return s; -} - - - - -// restore operators for complex types - - -//! \relatesalso PIByteArray -//! \~english Restore operator for PIVector of any compound type -//! \~russian Оператор извлечения для PIVector сложных типов -template::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { - if (s.size_s() < 4) { - printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T)); - 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 -//! \~english Restore operator for PIDeque of any compound type -//! \~russian Оператор извлечения для PIDeque сложных типов -template::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { - if (s.size_s() < 4) { - printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T)); - 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 -//! \~english Restore operator for PIVector2D of any compound type -//! \~russian Оператор извлечения для PIVector2D сложных типов -template::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) { - if (s.size_s() < 8) { - printf("error with PIVecto2Dr<%s>\n", __PIP_TYPENAME__(T)); - assert(s.size_s() >= 8); - } - int r,c; - PIVector tmp; - s >> r >> c >> tmp; - v = PIVector2D(r, c, tmp); - return s; -} - - - - -// other types - - -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -template -inline PIByteArray & operator <<(PIByteArray & s, const PIMap & v) { - s << int(v.pim_index.size_s()); - for (uint i = 0; i < v.size(); ++i) - s << int(v.pim_index[i].index) << v.pim_index[i].key; - s << v.pim_content; - return s; -} - - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -template -inline PIByteArray & operator >>(PIByteArray & s, PIMap & v) { - if (s.size_s() < 4) { - printf("error with PIMap<%s, %s>\n", __PIP_TYPENAME__(Key), __PIP_TYPENAME__(T)); - assert(s.size_s() >= 4); - } - int sz; s >> sz; v.pim_index.resize(sz); - int ind = 0; - for (int i = 0; i < sz; ++i) { - s >> ind >> v.pim_index[i].key; - v.pim_index[i].index = ind; - } - s >> v.pim_content; - if (v.pim_content.size_s() != v.pim_index.size_s()) { - piCout << "Warning: loaded invalid PIMap, clear"; - v.clear(); - } - return s; -} - - - -template::value, int>::type = 0> -inline PIByteArray & operator <<(PIByteArray & s, const T & ) { - static_assert(std::is_trivially_copyable::value, "[PIByteArray] Error: using undeclared operator << for complex type!"); - return s; -} - -template::value, int>::type = 0> -inline PIByteArray & operator >>(PIByteArray & s, T & ) { - static_assert(std::is_trivially_copyable::value, "[PIByteArray] Error: using undeclared operator >> for complex type!"); - return s; -} - - - - -BINARY_STREAM_STORE(PIByteArray::RawData) { - s.binaryStreamAppend(v.data(), v.size()); - return s; -} -BINARY_STREAM_RESTORE(PIByteArray::RawData) { - s.binaryStreamTake(v.data(), v.size()); - return s; -} - - BINARY_STREAM_STORE(PIByteArray) { s.binaryStreamAppend((int)v.size_s()); s.binaryStreamAppend(v.data(), v.size()); diff --git a/libs/main/core/pichunkstream.cpp b/libs/main/core/pichunkstream.cpp index 6255c955..fa0b1b7f 100644 --- a/libs/main/core/pichunkstream.cpp +++ b/libs/main/core/pichunkstream.cpp @@ -117,7 +117,7 @@ int PIChunkStream::read() { last_id = readVInt(*data_); last_data.resize(readVInt(*data_)); //piCout << last_id << last_data.size(); - (*data_) >> PIByteArray::RawData(last_data.data(), last_data.size_s()); + (*data_) >> PIMemoryBlock(last_data.data(), last_data.size_s()); break; default: break; } diff --git a/libs/main/core/pichunkstream.h b/libs/main/core/pichunkstream.h index a0456541..c7039c04 100644 --- a/libs/main/core/pichunkstream.h +++ b/libs/main/core/pichunkstream.h @@ -124,7 +124,7 @@ public: //! \~english Returns value of last readed chunk //! \~russian Возвращает значение последнего прочитанного чанка template - T getData() const {T ret; PIByteArray s(last_data); s >> ret; return ret;} + T getData() const {T ret{}; PIByteArray s(last_data); s >> ret; return ret;} //! \~english Place value of last readed chunk into \"v\" //! \~russian Записывает значение последнего прочитанного чанка в \"v\" diff --git a/libs/main/core/pidatetime.h b/libs/main/core/pidatetime.h index 9b009613..c5da3208 100644 --- a/libs/main/core/pidatetime.h +++ b/libs/main/core/pidatetime.h @@ -311,16 +311,6 @@ inline bool operator <=(const PIDateTime & t0, const PIDateTime & t1) {return !( //! \~russian Оператор сравнения inline bool operator >=(const PIDateTime & t0, const PIDateTime & t1) {return !(t0 < t1);} -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const PIDateTime & v) {s << v.year << v.month << v.day << v.hours << v.minutes << v.seconds << v.milliseconds; return s;} - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, PIDateTime & v) {s >> v.year >> v.month >> v.day >> v.hours >> v.minutes >> v.seconds >> v.milliseconds; return s;} - //! \relatesalso PICout //! \~english \brief Output operator to PICout //! \~russian \brief Оператор вывода в PICout diff --git a/libs/main/core/pimemoryblock.h b/libs/main/core/pimemoryblock.h new file mode 100644 index 00000000..33753955 --- /dev/null +++ b/libs/main/core/pimemoryblock.h @@ -0,0 +1,60 @@ +/*! \file pimemoryblock.h + * \ingroup Core + * \~\brief + * \~english Base types and functions + * \~russian Базовые типы и методы +*/ +/* + PIP - Platform Independent Primitives + Base types and functions + Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#ifndef PIMEMORYBLOCK_H +#define PIMEMORYBLOCK_H + + +//! \ingroup Core +//! \include pimemoryblock.h +//! \brief +//! \~english Help struct to store/restore custom blocks of data to/from PIBinaryStream +//! \~russian Вспомогательная структура для сохранения/извлечения произвольного блока данных в/из PIBinaryStream +struct PIMemoryBlock { +public: + + //! \~english Constructs data block + //! \~russian Создает блок данных + PIMemoryBlock(void * data_ = 0, int size_ = 0) {d = data_; s = size_;} + + //! \~english Constructs data block + //! \~russian Создает блок данных + PIMemoryBlock(const void * data_, const int size_) {d = const_cast(data_); s = size_;} + + PIMemoryBlock(const PIMemoryBlock & o) {d = o.d; s = o.s;} + + PIMemoryBlock & operator =(const PIMemoryBlock & o) {d = o.d; s = o.s; return *this;} + + void * data() {return d;} + const void * data() const {return d;} + int size() const {return s;} + +private: + void * d; + int s; + +}; + +#endif // PIMEMORYBLOCK_H diff --git a/libs/main/core/pipropertystorage.h b/libs/main/core/pipropertystorage.h index 597ad177..4573debc 100644 --- a/libs/main/core/pipropertystorage.h +++ b/libs/main/core/pipropertystorage.h @@ -271,13 +271,9 @@ protected: }; -inline PIByteArray & operator <<(PIByteArray & s, const PIPropertyStorage::Property & v) {s << v.name << v.value << v.comment << v.flags; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIPropertyStorage::Property & v) {s >> v.name >> v.value >> v.comment >> v.flags; return s;} template inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIPropertyStorage::Property & v) {s << v.name << v.value << v.comment << v.flags; return s;} template inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIPropertyStorage::Property & v) {s >> v.name >> v.value >> v.comment >> v.flags; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIPropertyStorage & v) {s << v.properties(); return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIPropertyStorage & v) {s >> v.properties(); return s;} template inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIPropertyStorage & v) {s << v.properties(); return s;} template inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIPropertyStorage & v) {s >> v.properties(); return s;} diff --git a/libs/main/core/pistring.h b/libs/main/core/pistring.h index e404b215..9b965845 100644 --- a/libs/main/core/pistring.h +++ b/libs/main/core/pistring.h @@ -40,8 +40,6 @@ class PIStringList; //! \~russian Класс строки. class PIP_EXPORT PIString { - friend PIByteArray & operator >>(PIByteArray & s, PIString & v); - friend PIByteArray & operator <<(PIByteArray & s, const PIString & v); BINARY_STREAM_FRIEND(PIString); public: typedef PIDeque::iterator iterator; @@ -1584,13 +1582,11 @@ PIP_EXPORT PICout operator <<(PICout s, const PIString & v); //! \relatesalso PIByteArray //! \~english Store operator. //! \~russian Оператор сохранения. -inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << v.d; return s;} BINARY_STREAM_STORE(PIString) {s << v.d; return s;} //! \relatesalso PIByteArray //! \~english Restore operator. //! \~russian Оператор извлечения. -inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.d.clear(); s >> v.d; return s;} BINARY_STREAM_RESTORE(PIString) {v.d.clear(); s >> v.d; return s;} diff --git a/libs/main/core/pistringlist.h b/libs/main/core/pistringlist.h index ba11e6a4..b8ed7211 100644 --- a/libs/main/core/pistringlist.h +++ b/libs/main/core/pistringlist.h @@ -126,17 +126,6 @@ public: }; -//! \relatesalso PIByteArray -//! \~english Store operator -//! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const PIStringList & v) {s << int(v.size_s()); for (int i = 0; i < v.size_s(); ++i) s << v[i]; return s;} - -//! \relatesalso PIByteArray -//! \~english Restore operator -//! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, PIStringList & v) {int sz; s >> sz; v.resize(sz); for (int i = 0; i < sz; ++i) s >> v[i]; return s;} - - BINARY_STREAM_STORE(PIStringList) { s.binaryStreamAppend(v.size()); for (int i = 0; i < v.size_s(); ++i) diff --git a/libs/main/core/pivariant.h b/libs/main/core/pivariant.h index e334617c..123fb3f6 100644 --- a/libs/main/core/pivariant.h +++ b/libs/main/core/pivariant.h @@ -206,8 +206,7 @@ classname_to __PIVariantFunctions__::castVariant(c //! \~english Variant type. class PIP_EXPORT PIVariant { friend PICout operator <<(PICout s, const PIVariant & v); - friend PIByteArray & operator <<(PIByteArray & s, const PIVariant & v); - friend PIByteArray & operator >>(PIByteArray & s, PIVariant & v); + BINARY_STREAM_FRIEND(PIVariant); public: //! Type of %PIVariant content @@ -773,38 +772,9 @@ REGISTER_VARIANT(PILined) REGISTER_VARIANT(PIMathVectord) REGISTER_VARIANT(PIMathMatrixd) -inline PIByteArray & operator <<(PIByteArray & s, const PIVariant & v) { - s << v._content << int(v._type); - if (v._type == PIVariant::pivCustom) { -#ifdef CUSTOM_PIVARIANT - if (v._info) { - s << v._info->typeName; - } else { - s << PIStringAscii(""); - } -#else - s << PIStringAscii(""); -#endif - } - return s; -} -inline PIByteArray & operator >>(PIByteArray & s, PIVariant & v) { - int t(0); - s >> v._content >> t; - v._type = (PIVariant::Type)t; - if (v._type == PIVariant::pivCustom) { - PIString tn; - s >> tn; -#ifdef CUSTOM_PIVARIANT - PIByteArray vc = v._content; - v = PIVariant::fromValue(vc, tn); -#endif - } - return s; -} -template inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIVariant & v) { - s << v._content << int(v._type); +BINARY_STREAM_STORE(PIVariant) { + s << v._content << v._type; if (v._type == PIVariant::pivCustom) { #ifdef CUSTOM_PIVARIANT if (v._info) { @@ -818,10 +788,8 @@ template inline PIBinaryStream

& operator <<(PIBinaryStream

& } return s; } -template inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIVariant & v) { - int t(0); - s >> v._content >> t; - v._type = (PIVariant::Type)t; +BINARY_STREAM_RESTORE(PIVariant) { + s >> v._content >> v._type; if (v._type == PIVariant::pivCustom) { PIString tn; s >> tn; diff --git a/libs/main/core/pivarianttypes.h b/libs/main/core/pivarianttypes.h index 1c20d8a3..74a723f4 100644 --- a/libs/main/core/pivarianttypes.h +++ b/libs/main/core/pivarianttypes.h @@ -164,28 +164,16 @@ struct PIP_EXPORT IODevice { } -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Enumerator & v) {s << v.value << v.name; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Enumerator & v) {s >> v.value >> v.name; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Enumerator & v) {s << v.name << "(" << v.value << ")"; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Enum & v) {s << v.enum_name << v.selected << v.enum_list; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Enum & v) {s >> v.enum_name >> v.selected >> v.enum_list; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Enum & v) {s << "Enum(" << v.selectedValue() << "=" << v.selectedName() << ")"; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::File & v) {s << v.file << v.filter << uchar((v.is_abs ? 1 : 0) + (v.is_save ? 2 : 0)); return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::File & v) {uchar f(0); s >> v.file >> v.filter >> f; v.is_abs = ((f & 1) == 1); v.is_save = ((f & 2) == 2); return s;} inline PICout operator <<(PICout s, const PIVariantTypes::File & v) {s << "File(\"" << v.file << "\")"; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Dir & v) {s << v.dir << v.is_abs; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Dir & v) {s >> v.dir >> v.is_abs; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Dir & v) {s << "Dir(\"" << v.dir << "\")"; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Color & v) {s << v.rgba; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::Color & v) {s >> v.rgba; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::Color & v) {s.saveControl(); s << PICoutManipulators::Hex << "Color(#" << v.rgba << ")"; s.restoreControl(); return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::IODevice & v) {s << v.prefix << v.mode << v.options << v.props; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIVariantTypes::IODevice & v) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;} inline PICout operator <<(PICout s, const PIVariantTypes::IODevice & v) {s << v.toPICout(); return s;} BINARY_STREAM_STORE (PIVariantTypes::Enumerator) {s << v.value << v.name; return s;} diff --git a/libs/main/introspection/piintrospection_containers_p.cpp b/libs/main/introspection/piintrospection_containers_p.cpp index 039e461b..75d80037 100644 --- a/libs/main/introspection/piintrospection_containers_p.cpp +++ b/libs/main/introspection/piintrospection_containers_p.cpp @@ -96,15 +96,3 @@ PIVector PIIntrospectionContainers::getInfo } return ret; } - - - - -PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v) { - s << PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name; - return s; -} -PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v) { - s >> PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) >> v.name; - return s; -} diff --git a/libs/main/introspection/piintrospection_containers_p.h b/libs/main/introspection/piintrospection_containers_p.h index b693367a..14bdc349 100644 --- a/libs/main/introspection/piintrospection_containers_p.h +++ b/libs/main/introspection/piintrospection_containers_p.h @@ -65,8 +65,6 @@ public: mutable PISpinlock mutex; }; -PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::TypeInfo & v); -PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::TypeInfo & v); BINARY_STREAM_STORE (PIIntrospectionContainers::TypeInfo) { s << PIByteArray::RawData(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name; diff --git a/libs/main/introspection/piintrospection_server_p.cpp b/libs/main/introspection/piintrospection_server_p.cpp index eb818065..b32f2de5 100644 --- a/libs/main/introspection/piintrospection_server_p.cpp +++ b/libs/main/introspection/piintrospection_server_p.cpp @@ -77,82 +77,6 @@ PIVector PIIntrospection::getObjects() { } -PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v) { - PIChunkStream cs; - cs.add(1, v.types); - b << cs.data(); - return b; -} - - -PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v) { - PIByteArray csba; b >> csba; - PIChunkStream cs(csba); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: cs.get(v.types); break; - default: break; - } - } - return b; -} - - -PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v) { - PIChunkStream cs; - cs.add(1, v.architecture).add(2, v.execCommand).add(3, v.execDateTime).add(4, v.hostname).add(5, v.OS_name) - .add(6, v.OS_version).add(7, v.processorsCount).add(8, v.user).add(9, v.build_options); - b << cs.data(); - return b; -} - - -PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v) { - PIByteArray csba; b >> csba; - PIChunkStream cs(csba); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: cs.get(v.architecture); break; - case 2: cs.get(v.execCommand); break; - case 3: cs.get(v.execDateTime); break; - case 4: cs.get(v.hostname); break; - case 5: cs.get(v.OS_name); break; - case 6: cs.get(v.OS_version); break; - case 7: cs.get(v.processorsCount); break; - case 8: cs.get(v.user); break; - case 9: cs.get(v.build_options); break; - default: break; - } - } - return b; -} - - -PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v) { - PIChunkStream cs; - cs.add(1, v.classname).add(2, v.name).add(3, v.parents).add(4, v.properties).add(5, v.queued_events); - b << cs.data(); - return b; -} - - -PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v) { - PIByteArray csba; b >> csba; - PIChunkStream cs(csba); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: cs.get(v.classname); break; - case 2: cs.get(v.name); break; - case 3: cs.get(v.parents); break; - case 4: cs.get(v.properties); break; - case 5: cs.get(v.queued_events); break; - default: break; - } - } - return b; -} - - PIByteArray PIIntrospection::packInfo() { diff --git a/libs/main/introspection/piintrospection_server_p.h b/libs/main/introspection/piintrospection_server_p.h index 6c3db74f..a5e503f8 100644 --- a/libs/main/introspection/piintrospection_server_p.h +++ b/libs/main/introspection/piintrospection_server_p.h @@ -92,15 +92,6 @@ public: }; -PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v); -PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v); - -PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v); -PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v); - -PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v); -PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v); - BINARY_STREAM_STORE (PIIntrospection::RequiredInfo) { PIChunkStream cs; diff --git a/libs/main/introspection/piintrospection_threads_p.cpp b/libs/main/introspection/piintrospection_threads_p.cpp index d872d479..9c5bdd72 100644 --- a/libs/main/introspection/piintrospection_threads_p.cpp +++ b/libs/main/introspection/piintrospection_threads_p.cpp @@ -81,19 +81,3 @@ void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) { ThreadInfo & ti(threads[t]); ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING } - - - - -PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v) { - b << v.classname << v.name << v.id << int(v.state) << v.priority << v.delay << v.run_us << v.run_count; - return b; -} - - -PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v) { - int st(0); - b >> v.classname >> v.name >> v.id >> st >> v.priority >> v.delay >> v.run_us >> v.run_count; - v.state = (PIIntrospectionThreads::ThreadState)st; - return b; -} diff --git a/libs/main/introspection/piintrospection_threads_p.h b/libs/main/introspection/piintrospection_threads_p.h index 0164d862..df507fa3 100644 --- a/libs/main/introspection/piintrospection_threads_p.h +++ b/libs/main/introspection/piintrospection_threads_p.h @@ -57,8 +57,6 @@ public: }; -PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v); -PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v); BINARY_STREAM_STORE(PIIntrospectionThreads::ThreadInfo) { s << v.classname << v.name << v.id << v.state << v.priority << v.delay << v.run_us << v.run_count; diff --git a/libs/main/io_devices/pifile.h b/libs/main/io_devices/pifile.h index 8a9481dc..ee539635 100644 --- a/libs/main/io_devices/pifile.h +++ b/libs/main/io_devices/pifile.h @@ -518,14 +518,19 @@ inline PICout operator <<(PICout s, const PIFile::FileInfo & v) { //! \relatesalso PIByteArray //! \~english Store operator //! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const PIFile::FileInfo & v) {s << v.path << v.size << v.time_access << v.time_modification << - (int)v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;} +BINARY_STREAM_STORE (PIFile::FileInfo) { + s << v.path << v.size << v.time_access << v.time_modification << + v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; + return s; +} //! \relatesalso PIByteArray //! \~english Restore operator //! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, PIFile::FileInfo & v) {s >> v.path >> v.size >> v.time_access >> v.time_modification >> - *(int*)(&(v.flags)) >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;} - +BINARY_STREAM_RESTORE(PIFile::FileInfo) { + s >> v.path >> v.size >> v.time_access >> v.time_modification >> + v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; + return s; +} #endif // PIFILE_H diff --git a/libs/main/io_devices/pipeer.h b/libs/main/io_devices/pipeer.h index a592eb90..5565606c 100644 --- a/libs/main/io_devices/pipeer.h +++ b/libs/main/io_devices/pipeer.h @@ -41,8 +41,7 @@ public: class PIP_EXPORT PeerInfo { friend class PIPeer; - friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v); - friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v); + BINARY_STREAM_FRIEND(PIPeer::PeerInfo); public: PeerInfo() {dist = sync = cnt = 0; trace = -1; was_update = false; _data = 0;} ~PeerInfo() {} @@ -80,9 +79,8 @@ public: PeerData * _data; }; - - friend PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v); - friend PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v); + + BINARY_STREAM_FRIEND(PIPeer::PeerInfo); bool send(const PIString & to, const PIByteArray & data) {return send(to, data.data(), data.size_s());} bool send(const PIString & to, const PIString & data) {return send(to, data.data(), data.size_s());} @@ -209,10 +207,10 @@ private: inline PICout operator <<(PICout c, const PIPeer::PeerInfo::PeerAddress & v) {c.space(); c << "PeerAddress(" << v.address << ", " << v.netmask << ", " << v.ping << ")"; return c;} inline PICout operator <<(PICout c, const PIPeer::PeerInfo & v) {c.space(); c << "PeerInfo(" << v.name << ", " << v.dist << ", " << v.addresses << ")"; return c;} -inline PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo::PeerAddress & v) {s << v.address << v.netmask << v.ping; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo::PeerAddress & v) {s >> v.address >> v.netmask >> v.ping; return s;} +BINARY_STREAM_STORE (PIPeer::PeerInfo::PeerAddress) {s << v.address << v.netmask << v.ping; return s;} +BINARY_STREAM_RESTORE(PIPeer::PeerInfo::PeerAddress) {s >> v.address >> v.netmask >> v.ping; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIPeer::PeerInfo & v) {s << v.name << v.addresses << v.dist << v.neighbours << v.cnt << v.time; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIPeer::PeerInfo & v) {s >> v.name >> v.addresses >> v.dist >> v.neighbours >> v.cnt >> v.time; return s;} +BINARY_STREAM_STORE (PIPeer::PeerInfo) {s << v.name << v.addresses << v.dist << v.neighbours << v.cnt << v.time; return s;} +BINARY_STREAM_RESTORE(PIPeer::PeerInfo) {s >> v.name >> v.addresses >> v.dist >> v.neighbours >> v.cnt >> v.time; return s;} #endif // PIPEER_H diff --git a/libs/main/io_utils/pibasetransfer.h b/libs/main/io_utils/pibasetransfer.h index 2cadd57f..3f945e3f 100644 --- a/libs/main/io_utils/pibasetransfer.h +++ b/libs/main/io_utils/pibasetransfer.h @@ -115,8 +115,7 @@ private: }; # pragma pack(pop) - friend PIByteArray & operator >>(PIByteArray & s, PIBaseTransfer::StartRequest & v); - friend PIByteArray & operator <<(PIByteArray & s, const PIBaseTransfer::StartRequest & v); + BINARY_STREAM_FRIEND(PIBaseTransfer::StartRequest); void processData(int id, PIByteArray &data); PIByteArray build_packet(int id); @@ -145,14 +144,14 @@ private: PIString pm_string; }; -inline PIByteArray & operator <<(PIByteArray & s, const PIBaseTransfer::PacketHeader & v) {s << v.sig << v.type << v.session_id << v.id << v.crc; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIBaseTransfer::PacketHeader & v) {s >> v.sig >> v.type >> v.session_id >> v.id >> v.crc; return s;} +BINARY_STREAM_STORE (PIBaseTransfer::PacketHeader) {s << v.sig << v.type << v.session_id << v.id << v.crc; return s;} +BINARY_STREAM_RESTORE(PIBaseTransfer::PacketHeader) {s >> v.sig >> v.type >> v.session_id >> v.id >> v.crc; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIBaseTransfer::Part & v) {s << v.id << v.size << v.start; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIBaseTransfer::Part & v) {s >> v.id >> v.size >> v.start; return s;} +BINARY_STREAM_STORE (PIBaseTransfer::Part) {s << v.id << v.size << v.start; return s;} +BINARY_STREAM_RESTORE(PIBaseTransfer::Part) {s >> v.id >> v.size >> v.start; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIBaseTransfer::StartRequest & v) {s << v.packets << v.size; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIBaseTransfer::StartRequest & v) {s >> v.packets >> v.size; return s;} +BINARY_STREAM_STORE (PIBaseTransfer::StartRequest) {s << v.packets << v.size; return s;} +BINARY_STREAM_RESTORE(PIBaseTransfer::StartRequest) {s >> v.packets >> v.size; return s;} inline PICout operator <<(PICout s, const PIBaseTransfer::Part & v) {s.setControl(0, true); s << "Part(\"" << v.id << "\", " << PIString::readableSize(v.start) << " b | " << PIString::readableSize(v.size) << " b)"; s.restoreControl(); return s;} diff --git a/libs/main/io_utils/pifiletransfer.h b/libs/main/io_utils/pifiletransfer.h index 4638e876..4083dda7 100644 --- a/libs/main/io_utils/pifiletransfer.h +++ b/libs/main/io_utils/pifiletransfer.h @@ -111,13 +111,19 @@ private: EVENT_HANDLER1(void, receive_finished, bool, ok); }; -inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PFTHeader & v) {s << v.raw_sig << v.step << v.session_id; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PFTHeader & v) {s >> v.raw_sig >> v.step >> v.session_id; return s;} +BINARY_STREAM_STORE (PIFileTransfer::PFTHeader) {s << v.raw_sig << v.step << v.session_id; return s;} +BINARY_STREAM_RESTORE(PIFileTransfer::PFTHeader) {s >> v.raw_sig >> v.step >> v.session_id; return s;} -inline PIByteArray & operator <<(PIByteArray & s, const PIFileTransfer::PFTFileInfo & v) {s << v.dest_path << v.size << v.time_access << v.time_modification << - v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIFileTransfer::PFTFileInfo & v) {s >> v.dest_path >> v.size >> v.time_access >> v.time_modification >> - v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; return s;} +BINARY_STREAM_STORE (PIFileTransfer::PFTFileInfo) { + s << v.dest_path << v.size << v.time_access << v.time_modification << + v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw; + return s; +} +BINARY_STREAM_RESTORE(PIFileTransfer::PFTFileInfo) { + s >> v.dest_path >> v.size >> v.time_access >> v.time_modification >> + v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw; + return s; +} inline PICout operator <<(PICout s, const PIFileTransfer::PFTFileInfo & v) { s.setControl(0, true); diff --git a/libs/main/math/pievaluator.h b/libs/main/math/pievaluator.h index 01aadca2..05af3cad 100644 --- a/libs/main/math/pievaluator.h +++ b/libs/main/math/pievaluator.h @@ -96,8 +96,7 @@ namespace PIEvaluatorTypes { class PIP_EXPORT PIEvaluatorContent { friend class PIEvaluator; - friend inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorContent & v); - friend inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorContent & v); + BINARY_STREAM_FRIEND(PIEvaluatorContent); public: PIEvaluatorContent(); ~PIEvaluatorContent() {;} @@ -229,37 +228,16 @@ private: inline bool operator ==(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type == e2.type && e1.num == e2.num);} inline bool operator !=(PIEvaluatorTypes::Element e1, PIEvaluatorTypes::Element e2) {return (e1.type != e2.type || e1.num != e2.num);} -inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Instruction & v) { - s << PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) << v.operators; - return s; -} -inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Instruction & v) { - s >> PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) >> v.operators; - return s; -} -inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Element & v) { - s << PIByteArray::RawData(&v, sizeof(v)); - return s; -} -inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Element & v) { - s >> PIByteArray::RawData(&v, sizeof(v)); - return s; -} -inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorTypes::Variable & v) { - s << v.name << v.value; - return s; -} -inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorTypes::Variable & v) { - s >> v.name >> v.value; - return s; -} -inline PIByteArray & operator <<(PIByteArray & s, const PIEvaluatorContent & v) { - s << v.variables << v.cv_count; - return s; -} -inline PIByteArray & operator >>(PIByteArray & s, PIEvaluatorContent & v) { - s >> v.variables >> v.cv_count; - return s; -} +BINARY_STREAM_STORE (PIEvaluatorTypes::Instruction) {s << PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) << v.operators; return s;} +BINARY_STREAM_RESTORE(PIEvaluatorTypes::Instruction) {s >> PIByteArray::RawData(&v, sizeof(v) - sizeof(v.operators)) >> v.operators; return s;} + +BINARY_STREAM_STORE (PIEvaluatorTypes::Element) {s << PIByteArray::RawData(&v, sizeof(v)); return s;} +BINARY_STREAM_RESTORE(PIEvaluatorTypes::Element) {s >> PIByteArray::RawData(&v, sizeof(v)); return s;} + +BINARY_STREAM_STORE (PIEvaluatorTypes::Variable) {s << v.name << v.value; return s;} +BINARY_STREAM_RESTORE(PIEvaluatorTypes::Variable) {s >> v.name >> v.value; return s;} + +BINARY_STREAM_STORE (PIEvaluatorContent) {s << v.variables << v.cv_count; return s;} +BINARY_STREAM_RESTORE(PIEvaluatorContent) {s >> v.variables >> v.cv_count; return s;} #endif // PIEVALUATOR_H diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index fc48ae84..92a48b7d 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -1172,9 +1172,9 @@ inline PICout operator<<(PICout s, const PIMathMatrix &m) { * @param v PIMathMatrix type * @return PIBiteArray serialized PIMathMatrix */ -template -inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { - s << (const PIVector2D &) v; +template +inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIMathMatrix & v) { + s << (const PIVector2D &) v; return s; } @@ -1185,9 +1185,9 @@ inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix &v) { * @param v PIMathMatrix type * @return PIMathMatrix deserialized from PIByteArray */ -template -inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix &v) { - s >> (PIVector2D &) v; +template +inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIMathMatrix & v) { + s >> (PIVector2D &) v; return s; } diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index 5ec4c13d..f6d9281c 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -258,8 +258,10 @@ typedef PIMathVectorT<4u, double> PIMathVectorT4d; template class PIP_EXPORT PIMathVector { typedef PIMathVector _CVector; - template friend PIByteArray & operator <<(PIByteArray & s, const PIMathVector & v); - template friend PIByteArray & operator >>(PIByteArray & s, PIMathVector & v); + template + friend PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIMathVector & v); + template + friend PIBinaryStream

& operator >>(PIBinaryStream

& s, PIMathVector & v); public: PIMathVector(const uint size = 0, const Type & new_value = Type()) {c.resize(size, new_value);} PIMathVector(const PIVector & val) {c = val;} @@ -510,10 +512,10 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathVector & v template inline PICout operator <<(PICout s, const PIMathVector & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;} -template -inline PIByteArray & operator <<(PIByteArray & s, const PIMathVector & v) {s << v.c; return s;} -template -inline PIByteArray & operator >>(PIByteArray & s, PIMathVector & v) {s >> v.c; return s;} +template +inline PIBinaryStream

& operator <<(PIBinaryStream

& s, const PIMathVector & v) {s << v.c; return s;} +template +inline PIBinaryStream

& operator >>(PIBinaryStream

& s, PIMathVector & v) {s >> v.c; return s;} typedef PIMathVector PIMathVectori; diff --git a/libs/main/resources/piresourcesstorage.cpp b/libs/main/resources/piresourcesstorage.cpp index 054e900c..ab721895 100644 --- a/libs/main/resources/piresourcesstorage.cpp +++ b/libs/main/resources/piresourcesstorage.cpp @@ -140,30 +140,3 @@ PIResourcesStorage * PIResourcesStorage::instance() { static PIResourcesStorage * ret = new PIResourcesStorage(); return ret; } - - -PIByteArray & operator <<(PIByteArray & b, const PIResourcesStorage::__RCEntry & v) { - PIChunkStream cs; - cs.add(1, v.section).add(2, v.name).add(3, v.file).add(4, v.size) - .add(5, v.offset).add(6, v.flags).add(7, v.alias); - b << cs.data(); - return b; -} - - -PIByteArray & operator >>(PIByteArray & b, PIResourcesStorage::__RCEntry & v) { - PIByteArray ba; b >> ba; - PIChunkStream cs(ba); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: cs.get(v.section); break; - case 2: cs.get(v.name); break; - case 3: cs.get(v.file); break; - case 4: cs.get(v.size); break; - case 5: cs.get(v.offset); break; - case 6: cs.get(v.flags); break; - case 7: cs.get(v.alias); break; - } - } - return b; -} diff --git a/libs/main/resources/piresourcesstorage.h b/libs/main/resources/piresourcesstorage.h index 3f67aac2..8e9bae13 100644 --- a/libs/main/resources/piresourcesstorage.h +++ b/libs/main/resources/piresourcesstorage.h @@ -22,6 +22,7 @@ #include "pistring.h" #include "pimap.h" +#include "pichunkstream.h" class PIResources; @@ -75,8 +76,29 @@ private: }; -PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIResourcesStorage::__RCEntry & v); -PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIResourcesStorage::__RCEntry & v); +BINARY_STREAM_STORE (PIResourcesStorage::__RCEntry) { + PIChunkStream cs; + cs.add(1, v.section).add(2, v.name).add(3, v.file).add(4, v.size) + .add(5, v.offset).add(6, v.flags).add(7, v.alias); + s << cs.data(); + return s; +} +BINARY_STREAM_RESTORE(PIResourcesStorage::__RCEntry) { + PIByteArray ba; s >> ba; + PIChunkStream cs(ba); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: cs.get(v.section); break; + case 2: cs.get(v.name); break; + case 3: cs.get(v.file); break; + case 4: cs.get(v.size); break; + case 5: cs.get(v.offset); break; + case 6: cs.get(v.flags); break; + case 7: cs.get(v.alias); break; + } + } + return s; +} #endif // PIRESOURCES_H diff --git a/libs/main/system/pisystemmonitor.cpp b/libs/main/system/pisystemmonitor.cpp index 4912d3dd..11e735f9 100644 --- a/libs/main/system/pisystemmonitor.cpp +++ b/libs/main/system/pisystemmonitor.cpp @@ -457,34 +457,3 @@ void PISystemMonitor::Pool::remove(PISystemMonitor * sm) { PIMutexLocker _ml(mutex); sysmons.remove(sm->pID()); } - - - - -PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ProcessStats & v) { - s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ProcessStatsFixed)) - << v.exec_name << v.state; - return s; -} - - -PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ProcessStats & v) { - s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ProcessStatsFixed)) - >> v.exec_name >> v.state; - v.makeStrings(); - return s; -} - - -PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ThreadStats & v) { - s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed)) - << v.name; - return s; -} - - -PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ThreadStats & v) { - s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed)) - >> v.name; - return s; -} diff --git a/libs/main/system/pisystemmonitor.h b/libs/main/system/pisystemmonitor.h index 50c2a855..1b604ed0 100644 --- a/libs/main/system/pisystemmonitor.h +++ b/libs/main/system/pisystemmonitor.h @@ -291,24 +291,37 @@ inline PICout operator <<(PICout s, const PISystemMonitor::ThreadStats & v) { } -//! \relatesalso PIByteArray //! \~english Store operator //! \~russian Оператор сохранения -PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ProcessStats & v); +BINARY_STREAM_STORE (PISystemMonitor::ProcessStats) { + s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ProcessStatsFixed)) + << v.exec_name << v.state; + return s; +} -//! \relatesalso PIByteArray //! \~english Restore operator //! \~russian Оператор извлечения -PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ProcessStats & v); +BINARY_STREAM_RESTORE(PISystemMonitor::ProcessStats) { + s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ProcessStatsFixed)) + >> v.exec_name >> v.state; + v.makeStrings(); + return s; +} -//! \relatesalso PIByteArray //! \~english Store operator //! \~russian Оператор сохранения -PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PISystemMonitor::ThreadStats & v); +BINARY_STREAM_STORE (PISystemMonitor::ThreadStats) { + s << PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed)) + << v.name; + return s; +} -//! \relatesalso PIByteArray //! \~english Restore operator //! \~russian Оператор извлечения -PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PISystemMonitor::ThreadStats & v); +BINARY_STREAM_RESTORE(PISystemMonitor::ThreadStats) { + s >> PIByteArray::RawData(&v, sizeof(PISystemMonitor::ThreadStatsFixed)) + >> v.name; + return s; +} #endif // PISYSTEMMONITOR_H diff --git a/main.cpp b/main.cpp index 29a9e9ba..477dab6c 100644 --- a/main.cpp +++ b/main.cpp @@ -6,22 +6,6 @@ using namespace PICoutManipulators; -class ByteArray: public PIBinaryStream { -public: - PIByteArray data; - bool binaryStreamAppendImp(const void * d, size_t s) { - data.append(d, s); - return true; - } - bool binaryStreamTakeImp(void * d, size_t s) { - if (data.size() < s) - return false; - memcpy(d, data.data(), s); - data.remove(0, s); - return true; - } -}; - class File: public PIBinaryStream { public: PIFile file; @@ -50,7 +34,7 @@ template inline PIBinaryStream

& operator <<(PIBinaryStream

& template inline PIBinaryStream

& operator >>(PIBinaryStream

& s, TS & v) {s >> v.i; return s;} int main(int argc, char * argv[]) { - ByteArray ba; + PIByteArray ba; /*ProcessStatsFixed_ ps; ba << ps; piCout << "s" << ba.data;*/ @@ -78,12 +62,12 @@ int main(int argc, char * argv[]) { piCout << map; ba << map; - piCout << ba.data; + piCout << ba; map.clear(); ba >> map; piCout << map; - piCout << ba.data; + piCout << ba; return 0; } diff --git a/utils/piterminal/main.cpp b/utils/piterminal/main.cpp index aeae643d..d8283dfc 100644 --- a/utils/piterminal/main.cpp +++ b/utils/piterminal/main.cpp @@ -185,7 +185,7 @@ public: void parseMessage() { if (msg.size_s() < 4) return; PIMutexLocker _ml(con_mutex); - int type; msg >> type; + int type = 0; msg >> type; //piCout << "msg" << type; switch ((PITerminalAuxMessageType)type) { case mtKey: { diff --git a/utils/system_daemon/daemon.h b/utils/system_daemon/daemon.h index 05a084f3..665b29c5 100644 --- a/utils/system_daemon/daemon.h +++ b/utils/system_daemon/daemon.h @@ -195,21 +195,21 @@ private: int offset, cur, height; }; -inline PIByteArray & operator <<(PIByteArray & b, const Daemon::HostInfo & v) { - b << v.execCommand << v.hostname << v.user << v.OS_name +BINARY_STREAM_STORE (Daemon::HostInfo) { + s << v.execCommand << v.hostname << v.user << v.OS_name << v.OS_version << v.architecture << v.execDateTime << v.processorsCount << v.ID << v.threads << v.priority << v.physical_memsize << v.share_memsize << v.cpu_load_system << v.cpu_load_user; - return b; + return s; } -inline PIByteArray & operator >>(PIByteArray & b, Daemon::HostInfo & v) { - b >> v.execCommand >> v.hostname >> v.user >> v.OS_name +BINARY_STREAM_RESTORE(Daemon::HostInfo) { + s >> v.execCommand >> v.hostname >> v.user >> v.OS_name >> v.OS_version >> v.architecture >> v.execDateTime >> v.processorsCount >> v.ID >> v.threads >> v.priority >> v.physical_memsize >> v.share_memsize >> v.cpu_load_system >> v.cpu_load_user; - return b; + return s; } #endif // DAEMON_H