PIByteArray doc
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/*! \file pibitarray.h
|
||||
* \brief Bit array
|
||||
* \~\brief
|
||||
* \~english Bit array
|
||||
* \~russian Битовый массив
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
|
||||
@@ -21,6 +21,82 @@
|
||||
#include "pistringlist.h"
|
||||
#include <iostream>
|
||||
|
||||
//! \class PIByteArray
|
||||
//!
|
||||
//! \~\brief
|
||||
//! \~english The PIByteArray class provides an array of bytes
|
||||
//! \~russian Класс PIByteArray представляет собой массив байтов
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! %PIByteArray used to store raw bytes.
|
||||
//! It can be constructed from any data and size.
|
||||
//! You can use %PIByteArray as binary stream
|
||||
//! to serialize/deserialize any objects and data.
|
||||
//! This class based on PIDeque<uchar> and provide some handle function
|
||||
//! to manipulate it.
|
||||
//! \~russian
|
||||
//! %PIByteArray используется для хранения байтов.
|
||||
//! Он может быть сконструирован из любых даных.
|
||||
//! Можно использовать %PIByteArray как потоковый объект
|
||||
//! для сериализации/десериализации любых типов и данных.
|
||||
//! Этот класс наследован от PIDeque<uchar> и предоставляет набор
|
||||
//! удобных методов для работы с байтами.
|
||||
//!
|
||||
//! \~english \section PIByteArray_sec0 Usage
|
||||
//! \~russian \section PIByteArray_sec0 Использование
|
||||
//! \~english
|
||||
//! %PIByteArray can be used to store custom data and manipulate it. There are many
|
||||
//! stream operators to store/restore common types to byte array. Store operators
|
||||
//! places data at the end of array, restore operators takes data from the beginning
|
||||
//! of array.
|
||||
//! In addition there are Hex and Base64 convertions
|
||||
//! \~russian
|
||||
//! %PIByteArray может быть использован для сохранения любых данных и работы с ними.
|
||||
//! Он предоставляет множество операторов для сохранения/извлечения общих типов.
|
||||
//! Операторы сохранения добавляют данные в конец массива, а операторы извлечения
|
||||
//! берут данные из его начала.
|
||||
//!
|
||||
//! \~english
|
||||
//! One of the major usage of %PIByteArray is stream functions. You can form binary
|
||||
//! packet from many types (also dynamic types, e.g. PIVector) with one line:
|
||||
//! \~russian
|
||||
//! Один из основных сценариев использования %PIByteArray - это потоковый объект.
|
||||
//! Можно сформировать пакет бинарных данных из многих типов (также и контейнеров,
|
||||
//! например, PIVector) в одну строку:
|
||||
//! \~\snippet pibytearray.cpp 0
|
||||
//!
|
||||
//! \~english
|
||||
//! Or you can descibe stream operator of your own type and store/restore vectors of
|
||||
//! your type:
|
||||
//! \~russian
|
||||
//! Также можно описать операторы сохранения/извлечения для собственных типов:
|
||||
//! \~\snippet pibytearray.cpp 1
|
||||
//!
|
||||
//! \~english
|
||||
//! For store/restore custom data blocks there is PIByteArray::RawData class. Stream
|
||||
//! operators of this class simply store/restore data block to/from byte array:
|
||||
//! \~russian
|
||||
//! Для сохранения/извлечения блоков произвольных данных используется класс PIByteArray::RawData.
|
||||
//! Потоковые операторы для него просто сохраняют/извлекают блоки байтов:
|
||||
//! \~\snippet pibytearray.cpp 2
|
||||
//!
|
||||
//! \~english \section PIByteArray_sec1 Attention
|
||||
//! \~russian \section PIByteArray_sec1 Внимание
|
||||
//! \~english
|
||||
//! Stream operator of %PIByteArray store byte array as vector, not simply append
|
||||
//! content of byte array. This operators useful to transmit custom data as %PIByteArray
|
||||
//! packed into parent byte array, e.g. to form packet from %PIByteArray.
|
||||
//! To append one byte array to another use funtion \a append().
|
||||
//! \~russian
|
||||
//! Потоковый оператор для типа %PIByteArray сохраняет его как контейнер,
|
||||
//! а не просто добавляет его содержимое в конец. Этот оператор полезен для управляемой
|
||||
//! упаковки произвольных данных в виде %PIByteArray.
|
||||
//! Для добавления содержимого одного байтового массива к другому используется
|
||||
//! метов \a append().
|
||||
//! \~\snippet pibytearray.cpp 3
|
||||
//!
|
||||
|
||||
|
||||
static const uchar base64Table[64] = {
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||
@@ -221,6 +297,19 @@ PIByteArray & PIByteArray::decompressRLE(uchar threshold) {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This is simple sum of all bytes, if "inverse" then add 1 and inverse.
|
||||
//! Pseudocode:
|
||||
//! \~russian
|
||||
//! Это простая сумма всех байтов, если "inverse", то ещё добавляется 1 и инвертируется результат.
|
||||
//! Псевдокод:
|
||||
//! \~\code
|
||||
//! for (i)
|
||||
//! sum += at(i);
|
||||
//! if (inverse) return ~(sum + 1);
|
||||
//! else return sum;
|
||||
//! \endcode
|
||||
uchar PIByteArray::checksumPlain8(bool inverse) const {
|
||||
uchar c = 0;
|
||||
int sz = size_s();
|
||||
@@ -231,6 +320,19 @@ uchar PIByteArray::checksumPlain8(bool inverse) const {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This is sum of all bytes multiplied by index+1, if inverse then add 1 and inverse.
|
||||
//! Pseudocode:
|
||||
//! \~russian
|
||||
//! Это простая сумма всех байтов, умноженных на индекс+1, если "inverse", то ещё добавляется 1 и инвертируется результат.
|
||||
//! Псевдокод:
|
||||
//! \~\code
|
||||
//! for (i)
|
||||
//! sum += at(i) * (i + 1);
|
||||
//! if (inverse) return ~(sum + 1);
|
||||
//! else return sum;
|
||||
//! \endcode
|
||||
uint PIByteArray::checksumPlain32(bool inverse) const {
|
||||
uint c = 0;
|
||||
int sz = size_s();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/*! \file pibytearray.h
|
||||
* \brief Byte array
|
||||
* \~\brief
|
||||
* \~english Byte array
|
||||
* \~russian Байтовый массив
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
@@ -39,76 +41,49 @@ class PIString;
|
||||
class PIByteArray;
|
||||
|
||||
|
||||
/*! \class PIByteArray
|
||||
* \brief The PIByteArray class provides an array of bytes
|
||||
* \details PIByteArray used to store raw bytes.
|
||||
* It can be constructed from any data and size.
|
||||
* You can use PIByteArray as binary stream
|
||||
* to serialize/deserialize any objects and data.
|
||||
* This class based on PIDeque<uchar> and provide some handle function
|
||||
* to manipulate it.
|
||||
*
|
||||
* \section PIByteArray_sec0 Usage
|
||||
* %PIByteArray can be used to store custom data and manipulate it. There are many
|
||||
* stream operators to store/restore common types to byte array. Store operators
|
||||
* places data at the end of array, restore operators takes data from the beginning
|
||||
* of array.
|
||||
* In addition there are Hex and Base64 convertions
|
||||
*
|
||||
* One of the major usage of %PIByteArray is stream functions. You can form binary
|
||||
* packet from many types (also dynamic types, e.g. PIVector) with one line:
|
||||
* \snippet pibytearray.cpp 0
|
||||
*
|
||||
* Or you can descibe stream operator of your own type and store/restore vectors of
|
||||
* your type:
|
||||
* \snippet pibytearray.cpp 1
|
||||
*
|
||||
* For store/restore custom data blocks there is PIByteArray::RawData class. Stream
|
||||
* operators of this class simply store/restore data block to/from byte array.
|
||||
* \snippet pibytearray.cpp 2
|
||||
*
|
||||
* \section PIByteArray_sec1 Attention
|
||||
* Stream operator of %PIByteArray store byte array as vector, not simply append
|
||||
* content of byte array. This operators useful to transmit custom data as %PIByteArray
|
||||
* packed into parent byte array, e.g. to form packet from %PIByteArray.
|
||||
* To append one byte array to another use funtion \a append().
|
||||
* \snippet pibytearray.cpp 3
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class PIP_EXPORT PIByteArray: public PIDeque<uchar>
|
||||
{
|
||||
public:
|
||||
|
||||
//! Constructs an empty byte array
|
||||
//! \~english Constructs an empty byte array
|
||||
//! \~russian Создает пустой байтовый массив
|
||||
PIByteArray() {;}
|
||||
|
||||
//! \~english Constructs copy of byte array "o"
|
||||
//! \~russian Создает копию байтового массива "o"
|
||||
PIByteArray(const PIByteArray & o): PIDeque<uchar>(o) {}
|
||||
|
||||
//! \~english Constructs copy of byte array "o"
|
||||
//! \~russian Создает копию байтового массива "o"
|
||||
PIByteArray(const PIDeque<uchar> & o): PIDeque<uchar>(o) {}
|
||||
|
||||
PIByteArray(PIByteArray && o): PIDeque<uchar>(std::move(o)) {}
|
||||
|
||||
//! Constructs 0-filled byte array with size "size"
|
||||
//! \~english Constructs 0-filled byte array with size "size"
|
||||
//! \~russian Создает заполненный "0" байтовый массив размером "size"
|
||||
PIByteArray(const uint size) {resize(size);}
|
||||
|
||||
//! Constructs byte array from data "data" and size "size"
|
||||
//! \~english Constructs byte array from data "data" and size "size"
|
||||
//! \~russian Создает байтовый массив из данных по указателю "data" размером "size"
|
||||
PIByteArray(const void * data, const uint size): PIDeque<uchar>((const uchar*)data, size_t(size)) {}
|
||||
|
||||
//! Constructs byte array with size "size" filled by "t"
|
||||
//! \~english Constructs byte array with size "size" filled by "t"
|
||||
//! \~russian Создает заполненный "t" байтовый массив размером "size"
|
||||
PIByteArray(const uint size, uchar t): PIDeque<uchar>(size, t) {}
|
||||
|
||||
|
||||
//! Help struct to store/restore custom blocks of data to/from PIByteArray
|
||||
//! \~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:
|
||||
//! Constructs data block
|
||||
//! \~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;}
|
||||
//! Constructs data block
|
||||
//! \~english Constructs data block
|
||||
//! \~russian Создает блок данных
|
||||
RawData(const void * data, const int size) {d = const_cast<void * >(data); s = size;}
|
||||
RawData & operator =(const RawData & o) {d = o.d; s = o.s; return *this;}
|
||||
private:
|
||||
@@ -116,22 +91,27 @@ public:
|
||||
int s;
|
||||
};
|
||||
|
||||
//! Return resized byte array
|
||||
//! \~english Return resized byte array
|
||||
//! \~russian Возвращает копию байтового массива с измененным размером
|
||||
PIByteArray resized(uint new_size) const {PIByteArray ret(new_size); memcpy(ret.data(), data(), new_size); return ret;}
|
||||
|
||||
//! Return sub-array starts from "index" and has "count" or less bytes
|
||||
//! \~english Return sub-array starts from "index" and has "count" or less bytes
|
||||
//! \~russian Возвращает подмассив с данными от индекса "index" и размером не более "count"
|
||||
PIByteArray getRange(size_t index, size_t count) const {
|
||||
return PIDeque<uchar>::getRange(index, count);
|
||||
}
|
||||
|
||||
|
||||
//! Convert data to Base 64 and return this byte array
|
||||
//! \~english Convert data to Base 64 and return this byte array
|
||||
//! \~russian Преобразует данные в Base 64 и возвращает текущий массив
|
||||
PIByteArray & convertToBase64();
|
||||
|
||||
//! Convert data from Base 64 and return this byte array
|
||||
//! \~english Convert data from Base 64 and return this byte array
|
||||
//! \~russian Преобразует данные из Base 64 и возвращает текущий массив
|
||||
PIByteArray & convertFromBase64();
|
||||
|
||||
//! Return converted to Base 64 data
|
||||
//! \~english Return converted to Base 64 data
|
||||
//! \~russian Возвращает копию байтового массива, преобразованного в Base 64
|
||||
PIByteArray toBase64() const;
|
||||
|
||||
PIByteArray & compressRLE(uchar threshold = 192);
|
||||
@@ -139,36 +119,40 @@ public:
|
||||
PIByteArray compressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.compressRLE(threshold); return ba;}
|
||||
PIByteArray decompressedRLE(uchar threshold = 192) {PIByteArray ba(*this); ba.decompressRLE(threshold); return ba;}
|
||||
|
||||
//! \~english Return string representation of data, each byte in "base" base, separated by spaces
|
||||
//! \~russian Возвращает текстовое представление байтового массива, каждый байт в "base" системе, с пробелами
|
||||
PIString toString(int base = 16) const;
|
||||
|
||||
//! Returns a hex encoded copy of the byte array.
|
||||
//! \~english
|
||||
//! Returns a hex encoded copy of the byte array, without spaces.
|
||||
//! The hex encoding uses the numbers 0-9 and the letters a-f.
|
||||
//! \~russian
|
||||
//! Возвращает шестнадцатеричное представление массива, без пробелов.
|
||||
//! Оно использует цифры 0-9 и буквы a-f.
|
||||
PIString toHex() const;
|
||||
|
||||
//! Add to the end data "data" with size "size"
|
||||
//! \~english Add to the end data "data" with size "size"
|
||||
//! \~russian Добавляет в конец массива данные по указателю "data" размером "size"
|
||||
PIByteArray & append(const void * data_, int size_) {uint ps = size(); enlarge(size_); memcpy(data(ps), data_, size_); return *this;}
|
||||
|
||||
//! Add to the end byte array "data"
|
||||
//! \~english Add to the end byte array "data"
|
||||
//! \~russian Добавляет в конец массива содержимое массива "data"
|
||||
PIByteArray & append(const PIByteArray & data_) {uint ps = size(); enlarge(data_.size_s()); memcpy(data(ps), data_.data(), data_.size()); return *this;}
|
||||
|
||||
//! Add to the end "t"
|
||||
//! \~english Add to the end "t"
|
||||
//! \~russian Добавляет в конец массива байт "t"
|
||||
PIByteArray & append(uchar t) {push_back(t); return *this;}
|
||||
|
||||
//! Returns 8-bit checksum
|
||||
//! sum all bytes, if inverse - add 1, inverse
|
||||
//! Pseudocode:
|
||||
//! sum += at(i);
|
||||
//! return ~(sum + 1)
|
||||
//! \~english Returns 8-bit checksum
|
||||
//! \~russian Возвращает 8-битную контрольную сумму
|
||||
uchar checksumPlain8(bool inverse = true) const;
|
||||
|
||||
//! Returns 32-bit checksum
|
||||
//! sum all bytes multiplyed by index+1, if inverse - add 1, inverse
|
||||
//! Pseudocode:
|
||||
//! sum += at(i) * (i + 1);
|
||||
//! return ~(sum + 1)
|
||||
//! \~english Returns 32-bit checksum
|
||||
//! \~russian Возвращает 32-битную контрольную сумму
|
||||
uint checksumPlain32(bool inverse = true) const;
|
||||
|
||||
//! Returns hash
|
||||
//! \~english Returns hash of content
|
||||
//! \~russian Возвращает хэш содержимого
|
||||
uint hash() const;
|
||||
|
||||
void operator =(const PIDeque<uchar> & d) {resize(d.size()); memcpy(data(), d.data(), d.size());}
|
||||
@@ -181,7 +165,8 @@ public:
|
||||
|
||||
static PIByteArray fromHex(PIString str);
|
||||
|
||||
//! Return converted from Base 64 data
|
||||
//! \~english Return converted from Base 64 data
|
||||
//! \~russian Возвращает массив из Base 64 представления
|
||||
static PIByteArray fromBase64(const PIByteArray & base64);
|
||||
static PIByteArray fromBase64(const PIString & base64);
|
||||
|
||||
@@ -196,7 +181,9 @@ public:
|
||||
|
||||
};
|
||||
|
||||
//! \relatesalso PIByteArray \brief Byte arrays compare operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Byte arrays compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
if (v0.size() == v1.size()) {
|
||||
if (v0.isEmpty()) return false;
|
||||
@@ -205,7 +192,9 @@ inline bool operator <(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
return v0.size() < v1.size();
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Byte arrays compare operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Byte arrays compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator >(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
if (v0.size() == v1.size()) {
|
||||
if (v0.isEmpty()) return false;
|
||||
@@ -214,7 +203,9 @@ inline bool operator >(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
return v0.size() > v1.size();
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Byte arrays compare operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Byte arrays compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator ==(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
if (v0.size() == v1.size()) {
|
||||
if (v0.isEmpty()) return true;
|
||||
@@ -223,7 +214,9 @@ inline bool operator ==(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Byte arrays compare operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Byte arrays compare operator
|
||||
//! \~russian Оператор сравнения
|
||||
inline bool operator !=(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
if (v0.size() == v1.size()) {
|
||||
if (v0.isEmpty()) return false;
|
||||
@@ -237,7 +230,9 @@ inline bool operator !=(const PIByteArray & v0, const PIByteArray & v1) {
|
||||
inline std::ostream & operator <<(std::ostream & s, const PIByteArray & ba);
|
||||
#endif
|
||||
|
||||
//! \relatesalso PIByteArray \brief Output to PICout operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Output to PICout operator
|
||||
//! \~russian Оператор вывода в PICout
|
||||
PIP_EXPORT PICout operator <<(PICout s, const PIByteArray & ba);
|
||||
|
||||
|
||||
@@ -246,16 +241,24 @@ PIP_EXPORT PICout operator <<(PICout s, const PIByteArray & ba);
|
||||
// store operators for basic types
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const bool v) {s.push_back(v); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const char v) {s.push_back(v); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const uchar v) {s.push_back(v); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for any trivial copyable type
|
||||
//! \~russian Оператор сохранения для тривиальных типов
|
||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray::StreamRef operator <<(PIByteArray & s, const T & v) {
|
||||
int os = s.size_s();
|
||||
@@ -264,10 +267,14 @@ inline PIByteArray::StreamRef operator <<(PIByteArray & s, const T & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
|
||||
//! \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 \brief Store operator, see \ref PIByteArray_sec1 for details
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator, see \ref PIByteArray_sec1 for details
|
||||
//! \~russian Оператор сохранения, подробнее в \ref PIByteArray_sec1
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {
|
||||
int os = s.size_s();
|
||||
if (v.s > 0) {
|
||||
@@ -277,7 +284,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for PIVector of any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for PIVector of any trivial copyable type
|
||||
//! \~russian Оператор сохранения для PIVector тривиальных типов
|
||||
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>
|
||||
@@ -299,7 +308,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for PIDeque of any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for PIDeque of any trivial copyable type
|
||||
//! \~russian Оператор сохранения для PIDeque тривиальных типов
|
||||
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>
|
||||
@@ -321,7 +332,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for PIVector2D of any trivial copyable type
|
||||
//! \~russian Оператор сохранения для PIVector2D тривиальных типов
|
||||
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>
|
||||
@@ -342,10 +355,14 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;}
|
||||
|
||||
//! \relatesalso PIPair \brief Store operator
|
||||
//! \relatesalso PIPair
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
template<typename Type0, typename Type1>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & v) {s << v.first << v.second; return s;}
|
||||
|
||||
@@ -355,16 +372,24 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & v
|
||||
// restore operators for basic types
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
//! \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 \brief Restore operator
|
||||
//! \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 \brief Restore operator
|
||||
//! \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 \brief Restore operator for any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for any trivial copyable type
|
||||
//! \~russian Оператор извлечения для тривиальных типов
|
||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray::StreamRef operator >>(PIByteArray & s, T & v) {
|
||||
if (s.size() < sizeof(v)) {
|
||||
@@ -376,10 +401,14 @@ inline PIByteArray::StreamRef operator >>(PIByteArray & s, T & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
|
||||
//! \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 \brief Restore operator, see \ref PIByteArray_sec1 for details
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator, see \ref PIByteArray_sec1 for details
|
||||
//! \~russian Оператор извлечения, подробнее в \ref PIByteArray_sec1
|
||||
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);
|
||||
@@ -392,7 +421,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for PIVector of any trivial copyable type
|
||||
//! \~russian Оператор извлечения для PIVector тривиальных типов
|
||||
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>
|
||||
@@ -423,7 +454,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for PIDeque of any trivial copyable type
|
||||
//! \~russian Оператор извлечения для PIDeque тривиальных типов
|
||||
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>
|
||||
@@ -454,7 +487,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any trivial copyable type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for PIVector2D of any trivial copyable type
|
||||
//! \~russian Оператор извлечения для PIVector2D тривиальных типов
|
||||
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>
|
||||
@@ -487,10 +522,14 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
//! \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 \brief Restore operator
|
||||
//! \relatesalso PIPair
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
template<typename Type0, typename Type1>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & v) {s >> v.first >> v.second; return s;}
|
||||
|
||||
@@ -500,7 +539,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & v) {s >
|
||||
// store operators for complex types
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for PIVector of any compound type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for PIVector of any compound type
|
||||
//! \~russian Оператор сохранения для PIVector сложных типов
|
||||
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) {
|
||||
s << int(v.size_s());
|
||||
@@ -508,7 +549,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for PIDeque of any compound type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for PIDeque of any compound type
|
||||
//! \~russian Оператор сохранения для PIDeque сложных типов
|
||||
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) {
|
||||
s << int(v.size_s());
|
||||
@@ -516,7 +559,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any compound type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator for PIVector2D of any compound type
|
||||
//! \~russian Оператор сохранения для PIVector2D сложных типов
|
||||
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) {
|
||||
s << int(v.rows()) << int(v.cols()) << v.toPlainVector();
|
||||
@@ -529,7 +574,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
|
||||
// restore operators for complex types
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector of any compound type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for PIVector of any compound type
|
||||
//! \~russian Оператор извлечения для PIVector сложных типов
|
||||
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
||||
if (s.size_s() < 4) {
|
||||
@@ -542,7 +589,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any compound type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for PIDeque of any compound type
|
||||
//! \~russian Оператор извлечения для PIDeque сложных типов
|
||||
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
||||
if (s.size_s() < 4) {
|
||||
@@ -555,7 +604,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any compound type
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator for PIVector2D of any compound type
|
||||
//! \~russian Оператор извлечения для PIVector2D сложных типов
|
||||
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
||||
if (s.size_s() < 8) {
|
||||
@@ -575,6 +626,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
|
||||
// other types
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
template <typename Key, typename T>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
|
||||
s << int(v.pim_index.size_s());
|
||||
@@ -585,6 +639,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
template <typename Key, typename T>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & v) {
|
||||
if (s.size_s() < 4) {
|
||||
@@ -620,16 +677,29 @@ inline PIByteArray & operator >>(PIByteArray & s, T & ) {
|
||||
}
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Returns PIByteArray::hash() of "ba"
|
||||
//! \~russian Возвращает PIByteArray::hash() от "ba"
|
||||
template<> inline uint piHash(const PIByteArray & ba) {return ba.hash();}
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Swap contents betwee "f" and "s"
|
||||
//! \~russian Меняет содержимое массивов "f" и "s"
|
||||
template<> inline void piSwap(PIByteArray & f, PIByteArray & s) {f.swap(s);}
|
||||
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store "value" to bytearray and returns it
|
||||
//! \~russian Сохраняет "value" в байтовый массив и возвращает его
|
||||
template <typename T> PIByteArray piSerialize(const T & value) {
|
||||
PIByteArray ret;
|
||||
ret << value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore type "T" from bytearray "data" and returns it
|
||||
//! \~russian Извлекает тип "T" из байтового массива "data" и возвращает его
|
||||
template <typename T> T piDeserialize(const PIByteArray & data) {
|
||||
T ret;
|
||||
if (!data.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user