Merge remote-tracking branch 'remotes/origin/stream_interface'

PIBinaryLog
This commit is contained in:
Бычков Андрей
2022-07-22 15:22:33 +03:00
92 changed files with 1807 additions and 1791 deletions

View File

@@ -1050,7 +1050,7 @@ PIString PICodeParser::procMacros(PIString fc) {
if (ifcnt > 0) ifcnt--;
else {
//piCout << "main endif" << skip << grab;
if (grab) pfc << procMacros(nfc);
if (grab) pfc += procMacros(nfc);
skip = grab = false;
continue;
}
@@ -1059,7 +1059,7 @@ PIString PICodeParser::procMacros(PIString fc) {
//piCout << "main elif" << skip << grab << cond_ok;
if (cond_ok) {
if (grab) {
pfc << procMacros(nfc);
pfc += procMacros(nfc);
skip = true; grab = false;
}
continue;
@@ -1075,12 +1075,12 @@ PIString PICodeParser::procMacros(PIString fc) {
}
if (mif.left(4) == s_else && ifcnt == 0) {
//piCout << "main else" << skip << grab;
if (grab) pfc << procMacros(nfc);
if (grab) pfc += procMacros(nfc);
if (skip && !cond_ok) {skip = false; grab = true;}
else {skip = true; grab = false;}
continue;
}
if (grab) nfc << line << '\n';
if (grab) nfc += line + '\n';
continue;
}
if (mif.left(2) == s_if) {
@@ -1095,8 +1095,8 @@ PIString PICodeParser::procMacros(PIString fc) {
//return false; /// WARNING: now skip errors
}
} else {
if (grab) nfc << line << '\n';
else if (!skip) pfc << line << '\n';
if (grab) nfc += line + '\n';
else if (!skip) pfc += line + '\n';
}
}
return pfc;

View File

@@ -247,13 +247,11 @@ private:
};
inline PIByteArray & operator <<(PIByteArray & s, const PIKbdListener::KeyEvent & v) {s << v.key << v.modifiers; return s;}
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;}
BINARY_STREAM_WRITE(PIKbdListener::MouseEvent) {s << v.x << v.y << v.action << v.buttons << v.modifiers; return s;}
BINARY_STREAM_READ (PIKbdListener::MouseEvent) {s >> v.x >> v.y >> v.action >> v.buttons >> v.modifiers; return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIKbdListener::KeyEvent & v) {s >> v.key >> v.modifiers; 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_WRITE(PIKbdListener::WheelEvent) {s << (*(PIKbdListener::MouseEvent*)&v) << v.direction; return s;}
BINARY_STREAM_READ (PIKbdListener::WheelEvent) {s >> (*(PIKbdListener::MouseEvent*)&v) >> v.direction; return s;}
REGISTER_PIVARIANTSIMPLE(PIKbdListener::KeyEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::MouseEvent)

View File

@@ -143,11 +143,14 @@ 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::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_WRITE(PIScreenTypes::Cell) {s << v.format.raw_format << v.symbol; return s;}
BINARY_STREAM_READ (PIScreenTypes::Cell) {s >> v.format.raw_format >> v.symbol; return s;}
BINARY_STREAM_WRITE(PIScreenTypes::TileEvent) {s << v.type << v.data; return s;}
BINARY_STREAM_READ (PIScreenTypes::TileEvent) {s >> v.type >> v.data; return s;}
REGISTER_PIVARIANTSIMPLE(PIScreenTypes::TileEvent)

View File

@@ -71,9 +71,11 @@ class PIMapIterator;
template <typename Key, typename T>
class PIMap {
template <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, PIMap<Key1, T1> & v);
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIMap<Key1, T1> & v);
template <typename Key1, typename T1> friend class PIMapIterator;
template <typename P, typename Key1, typename T1>
friend PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMap<Key1, T1> & v);
template <typename P, typename Key1, typename T1>
friend PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIMap<Key1, T1> & v);
public:
PIMap() {;}
PIMap(const PIMap<Key, T> & other) {*this = other;}
@@ -295,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 <typename Key1, typename T1> friend PIByteArray & operator >>(PIByteArray & s, PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
template <typename Key1, typename T1> friend PIByteArray & operator <<(PIByteArray & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
template <typename P, typename Key1, typename T1>
friend PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
template <typename P, typename Key1, typename T1>
friend PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
ssize_t binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
ssize_t mid;

View File

@@ -132,6 +132,10 @@ template< class T1, class T2 >
PIPair<T1,T2> createPIPair(const T1 & f, const T2 & s) {
return PIPair<T1,T2>(f, s);
}
template< class T1, class T2 >
PIPair<T1,T2> makePIPair(const T1 & f, const T2 & s) {
return PIPair<T1,T2>(f, s);
}
//! \~english Creates \a PIPair object, deducing the target type from the types of arguments.
//! \~russian Создает \a PIPair выводя типы из аргументов.
@@ -140,5 +144,9 @@ template< class T1, class T2 >
PIPair<T1,T2> createPIPair(T1 && f, T2 && s) {
return PIPair<T1,T2>(std::move(f), std::move(s));
}
template< class T1, class T2 >
PIPair<T1,T2> makePIPair(T1 && f, T2 && s) {
return PIPair<T1,T2>(std::move(f), std::move(s));
}
#endif // PIPAIR_H

View File

@@ -265,13 +265,15 @@
#ifdef CC_GCC
# undef DEPRECATED
# undef DEPRECATEDM
# define DEPRECATED __attribute__((deprecated))
# define DEPRECATEDM(msg) __attribute__((deprecated(msg)))
# if CC_GCC_VERSION > 0x025F // > 2.95
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# ifdef LINUX
# define HAS_LOCALE
# endif
# ifdef MAC_OS
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# pragma GCC diagnostic ignored "-Wundefined-bool-conversion"
# pragma GCC diagnostic ignored "-Wc++11-extensions"
# endif
@@ -287,7 +289,9 @@
#ifdef CC_VC
# undef DEPRECATED
# define DEPRECATED
# undef DEPRECATEDM
# define DEPRECATED __declspec(deprecated)
# define DEPRECATEDM(msg) __declspec(deprecated(msg))
# pragma warning(disable: 4018)
# pragma warning(disable: 4061)
# pragma warning(disable: 4100)
@@ -312,7 +316,9 @@
#ifdef CC_OTHER
# undef DEPRECATED
# undef DEPRECATEDM
# define DEPRECATED
# define DEPRECATEDM(msg)
#endif
#endif //DOXYGEN

View File

@@ -0,0 +1,504 @@
/*! \file pibinarystream.h
* \ingroup Core
* \~\brief
* \~english Binary serialization interface
* \~russian Интерфейс бинарной сериализации
*/
/*
PIP - Platform Independent Primitives
Binary serialization interface
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 <http://www.gnu.org/licenses/>.
*/
#ifndef PIBINARYSTREAM_H
#define PIBINARYSTREAM_H
#include "pimemoryblock.h"
#include "pibitarray.h"
#include "pimap.h"
#include "pivector2d.h"
#define PIP_BINARY_STREAM
#define BINARY_STREAM_FRIEND(T) \
template<typename P> friend PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const T & v); \
template<typename P> friend PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, T & v);
#define BINARY_STREAM_WRITE(T) \
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const T & v)
#define BINARY_STREAM_READ(T) \
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, T & v)
//! \ingroup Core
//! \~\brief
//! \~english Binary serialization interface.
//! \~russian Интерфейс бинарной сериализации.
template<typename P>
class PIBinaryStream {
public:
// one should implement next methods:
//
// bool binaryStreamAppendImp(const void * d, size_t s);
// bool binaryStreamTakeImp ( void * d, size_t s);
bool binaryStreamAppend(const void * d, size_t s) {
if (!static_cast<P*>(this)->binaryStreamAppendImp(d, s)) {
return false;
printf("[PIBinaryStream] binaryStreamAppend() error\n");
}
return true;
}
bool binaryStreamTake(void * d, size_t s) {
if (!static_cast<P*>(this)->binaryStreamTakeImp(d, s)) {
return false;
printf("[PIBinaryStream] binaryStreamTake() error\n");
}
return true;
}
template<typename T>
void binaryStreamAppend(T v) {binaryStreamAppend(&v, sizeof(v));}
uchar binaryStreamTakeByte(bool * ok = nullptr) {
uchar r = 0;
if (binaryStreamTake(&r, sizeof(r))) {
if (ok) *ok = true;
} else {
if (ok) *ok = false;
}
return r;
}
int binaryStreamTakeInt(bool * ok = nullptr) {
int r = 0;
if (binaryStreamTake(&r, sizeof(r))) {
if (ok) *ok = true;
} else {
if (ok) *ok = false;
}
return r;
}
};
// helper class to detect default operators
template<typename P>
class PIBinaryStreamTrivialRef {
public:
PIBinaryStreamTrivialRef(PIBinaryStream<P> & s): p(s) {}
PIBinaryStream<P> & p;
};
template<typename P, typename T> inline PIBinaryStream<P> & operator <<(PIBinaryStreamTrivialRef<P> s, const T & v) {s.p << v; return s.p;}
template<typename P, typename T> inline PIBinaryStream<P> & operator >>(PIBinaryStreamTrivialRef<P> s, T & v) {s.p >> v; return s.p;}
// specify types
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const bool v) {s.binaryStreamAppend((uchar)v); return s;}
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, bool & v) {v = s.binaryStreamTakeByte(); return s;}
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMemoryBlock v) {
s.binaryStreamAppend(v.data(), v.size());
return s;
}
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIMemoryBlock v) {
s.binaryStreamTake(v.data(), v.size());
return s;
}
// store simple types
template<typename P, typename T,
typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const T & v) {
//piCout << "<< enum";
s.binaryStreamAppend((int)v);
return s;
}
template<typename P, typename T,
typename std::enable_if<!std::is_enum<T>::value, int>::type = 0,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStreamTrivialRef<P> operator <<(PIBinaryStream<P> & s, const T & v) {
s.binaryStreamAppend(&v, sizeof(v));
return s;
}
//! \~english Store operator for PIVector of any trivial copyable type
//! \~russian Оператор сохранения для PIVector тривиальных типов
template<typename P, 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<PIBinaryStream<P>&>() << std::declval<const T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIVector<T> & v) {
//piCout << "<< vector trivial default";
s.binaryStreamAppend((int)v.size());
s.binaryStreamAppend(v.data(), v.size() * sizeof(T));
return s;
}
template<typename P, 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<PIBinaryStream<P>&>() << std::declval<const T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIVector<T> & v) {
//piCout << "<< vector trivial custom";
s.binaryStreamAppend((int)v.size());
for (size_t i = 0; i < v.size(); ++i) s << v[i];
return s;
}
//! \~english Store operator for PIDeque of any trivial copyable type
//! \~russian Оператор сохранения для PIDeque тривиальных типов
template<typename P, 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<PIBinaryStream<P>&>() << std::declval<const T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIDeque<T> & v) {
//piCout << "<< deque trivial default";
s.binaryStreamAppend((int)v.size());
s.binaryStreamAppend(v.data(), v.size() * sizeof(T));
return s;
}
template<typename P, 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<PIBinaryStream<P>&>() << std::declval<const T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIDeque<T> & v) {
//piCout << "<< deque trivial custom";
s.binaryStreamAppend((int)v.size());
for (size_t i = 0; i < v.size(); ++i) s << v[i];
return s;
}
//! \~english Store operator for PIVector2D of any trivial copyable type
//! \~russian Оператор сохранения для PIVector2D тривиальных типов
template<typename P, 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<PIBinaryStream<P>&>() << std::declval<const T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIVector2D<T> & v) {
//piCout << "<< vector2d trivial default";
s.binaryStreamAppend((int)v.rows());
s.binaryStreamAppend((int)v.cols());
s.binaryStreamAppend(v.data(), v.size() * sizeof(T));
return s;
}
template<typename P, 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<PIBinaryStream<P>&>() << std::declval<const T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIVector2D<T> & v) {
//piCout << "<< vector2d trivial custom";
s.binaryStreamAppend((int)v.rows());
s.binaryStreamAppend((int)v.cols());
s << v.toPlainVector();
return s;
}
//! \~english Store operator
//! \~russian Оператор сохранения
template<typename P>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIBitArray & v) {s << v.size_ << v.data_; return s;}
//! \~english Store operator
//! \~russian Оператор сохранения
template<typename P, typename Type0, typename Type1>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIPair<Type0, Type1> & v) {s << v.first << v.second; return s;}
// restore simple types
template<typename P, typename T,
typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, T & v) {
//piCout << ">> enum";
v = (T)s.binaryStreamTakeInt();
return s;
}
template<typename P, typename T,
typename std::enable_if<!std::is_enum<T>::value, int>::type = 0,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStreamTrivialRef<P> operator >>(PIBinaryStream<P> & s, T & v) {
if (!s.binaryStreamTake(&v, sizeof(v))) {
printf("error with %s\n", __PIP_TYPENAME__(T));
assert(false);
}
return s;
}
//! \~english Restore operator for PIVector of any trivial copyable type
//! \~russian Оператор извлечения для PIVector тривиальных типов
template<typename P, 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<PIBinaryStream<P>&>() >> std::declval<T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIVector<T> & v) {
//piCout << ">> vector trivial default";
int sz = s.binaryStreamTakeInt();
v._resizeRaw(sz);
if (!s.binaryStreamTake(v.data(), sz * sizeof(T))) {
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
assert(false);
}
return s;
}
template<typename P, 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<PIBinaryStream<P>&>() >> std::declval<T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIVector<T> & v) {
//piCout << ">> vector trivial custom";
int sz = s.binaryStreamTakeInt();
v._resizeRaw(sz);
for (int i = 0; i < sz; ++i) s >> v[i];
return s;
}
//! \~english Restore operator for PIDeque of any trivial copyable type
//! \~russian Оператор извлечения для PIDeque тривиальных типов
template<typename P, 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<PIBinaryStream<P>&>() >> std::declval<T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIDeque<T> & v) {
//piCout << ">> deque trivial default";
int sz = s.binaryStreamTakeInt();
v._resizeRaw(sz);
if (!s.binaryStreamTake(v.data(), sz * sizeof(T))) {
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
assert(false);
}
return s;
}
template<typename P, 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<PIBinaryStream<P>&>() >> std::declval<T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIDeque<T> & v) {
//piCout << ">> deque trivial custom";
int sz = s.binaryStreamTakeInt();
v._resizeRaw(sz);
for (int i = 0; i < sz; ++i) s >> v[i];
return s;
}
//! \~english Restore operator for PIVector2D of any trivial copyable type
//! \~russian Оператор извлечения для PIVector2D тривиальных типов
template<typename P, 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<PIBinaryStream<P>&>() >> std::declval<T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIVector2D<T> & v) {
//piCout << ">> vector2d trivial default";
int r, c;
r = s.binaryStreamTakeInt();
c = s.binaryStreamTakeInt();
v._resizeRaw(r, c);
if (!s.binaryStreamTake(v.data(), v.size() * sizeof(T))) {
printf("error with PIVector2D<%s>\n", __PIP_TYPENAME__(T));
assert(false);
}
return s;
}
template<typename P, 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<PIBinaryStream<P>&>() >> std::declval<T &>()), PIBinaryStreamTrivialRef<P>>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIVector2D<T> & v) {
//piCout << ">> vector2d trivial custom";
int r, c;
PIVector<T> tmp;
r = s.binaryStreamTakeInt();
c = s.binaryStreamTakeInt();
s >> tmp;
v = PIVector2D<T>(r, c, tmp);
return s;
}
//! \~english Restore operator
//! \~russian Оператор извлечения
template<typename P>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIBitArray & v) {s >> v.size_ >> v.data_; return s;}
//! \~english Restore operator
//! \~russian Оператор извлечения
template<typename P, typename Type0, typename Type1>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIPair<Type0, Type1> & v) {s >> v.first >> v.second; return s;}
// store complex types
//! \~english Store operator for PIVector of any compound type
//! \~russian Оператор сохранения для PIVector сложных типов
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIVector<T> & v) {
//piCout << "<< vector complex";
s.binaryStreamAppend(int(v.size_s()));
for (size_t i = 0; i < v.size(); ++i) s << v[i];
return s;
}
//! \~english Store operator for PIDeque of any compound type
//! \~russian Оператор сохранения для PIDeque сложных типов
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIDeque<T> & v) {
//piCout << "<< deque complex";
s.binaryStreamAppend(int(v.size_s()));
for (size_t i = 0; i < v.size(); ++i) s << v[i];
return s;
}
//! \~english Store operator for PIVector2D of any compound type
//! \~russian Оператор сохранения для PIVector2D сложных типов
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIVector2D<T> & v) {
//piCout << "<< vector2d complex";
s.binaryStreamAppend(int(v.rows()));
s.binaryStreamAppend(int(v.cols()));
s << v.toPlainVector();
return s;
}
// restore complex types
//! \~english Restore operator for PIVector of any compound type
//! \~russian Оператор извлечения для PIVector сложных типов
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIVector<T> & v) {
//piCout << ">> vector complex";
/*if (s.size_s() < 4) {
printf("error with PIVector<%s>\n", __PIP_TYPENAME__(T));
assert(s.size_s() >= 4);
}*/
v.resize(s.binaryStreamTakeInt());
for (size_t i = 0; i < v.size(); ++i) s >> v[i];
return s;
}
//! \~english Restore operator for PIDeque of any compound type
//! \~russian Оператор извлечения для PIDeque сложных типов
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIDeque<T> & v) {
//piCout << ">> deque complex";
/*if (s.size_s() < 4) {
printf("error with PIDeque<%s>\n", __PIP_TYPENAME__(T));
assert(s.size_s() >= 4);
}*/
v.resize(s.binaryStreamTakeInt());
for (size_t i = 0; i < v.size(); ++i) s >> v[i];
return s;
}
//! \~english Restore operator for PIVector2D of any compound type
//! \~russian Оператор извлечения для PIVector2D сложных типов
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIVector2D<T> & v) {
//piCout << ">> vector2d complex";
/*if (s.size_s() < 8) {
printf("error with PIVecto2Dr<%s>\n", __PIP_TYPENAME__(T));
assert(s.size_s() >= 8);
}*/
int r, c;
PIVector<T> tmp;
r = s.binaryStreamTakeInt();
c = s.binaryStreamTakeInt();
s >> tmp;
v = PIVector2D<T>(r, c, tmp);
return s;
}
// other types
//! \~english Store operator
//! \~russian Оператор сохранения
template <typename P, typename Key, typename T>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMap<Key, T> & v) {
s.binaryStreamAppend((int)v.pim_index.size_s());
for (uint i = 0; i < v.size(); ++i) {
s.binaryStreamAppend((int)v.pim_index[i].index);
s << v.pim_index[i].key;
}
s << v.pim_content;
return s;
}
//! \~english Restore operator
//! \~russian Оператор извлечения
template <typename P, typename Key, typename T>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIMap<Key, T> & 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.binaryStreamTakeInt(); v.pim_index.resize(sz);
int ind = 0;
for (int i = 0; i < sz; ++i) {
ind = s.binaryStreamTakeInt();
s >> 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;
}
// non-defined complex types
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const T & ) {
static_assert(std::is_trivially_copyable<T>::value, "[PIBinaryStream] Error: using undeclared operator << for complex type!");
return s;
}
template<typename P, typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, T & ) {
static_assert(std::is_trivially_copyable<T>::value, "[PIBinaryStream] Error: using undeclared operator >> for complex type!");
return s;
}
#endif

View File

@@ -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 <typename P>
friend PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIBitArray & v);
template <typename P>
friend PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIBitArray & v);
public:
PIBitArray(const int & size = 0) {resize(size);}
PIBitArray(uchar val) {resize(sizeof(val) * 8); data_[0] = val;}

View File

@@ -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;
}

View File

@@ -27,9 +27,7 @@
#define PIBYTEARRAY_H
#include "pichar.h"
#include "pibitarray.h"
#include "pimap.h"
#include "pivector2d.h"
#include "pibinarystream.h"
#include <stdio.h>
class PIString;
@@ -40,9 +38,10 @@ class PIByteArray;
//! \~\brief
//! \~english The %PIByteArray class provides an array of bytes.
//! \~russian Класс %PIByteArray представляет собой массив байтов.
class PIP_EXPORT PIByteArray: public PIDeque<uchar>
class PIP_EXPORT PIByteArray: public PIDeque<uchar>, public PIBinaryStream<PIByteArray>
{
public:
typedef ::PIMemoryBlock RawData DEPRECATEDM("use PIMemoryBlock instead");
//! \~english Constructs an empty byte array
//! \~russian Создает пустой байтовый массив
@@ -71,25 +70,6 @@ public:
PIByteArray(const uint size, uchar t): PIDeque<uchar>(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<void * >(data); s = size;}
RawData & operator =(const RawData & o) {d = o.d; s = o.s; return *this;}
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;}
@@ -170,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;
}
};
@@ -235,443 +219,14 @@ 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<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();
s.enlarge(sizeof(v));
memcpy(s.data(os), &v, sizeof(v));
BINARY_STREAM_WRITE(PIByteArray) {
s.binaryStreamAppend((int)v.size_s());
s.binaryStreamAppend(v.data(), v.size());
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
s << int(v.size_s());
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator <<(PIByteArray & s, const PIVector<T> & v) {
s << int(v.size_s());
for (uint i = 0; i < v.size(); ++i) s << v[i];
return s;
}
//! \relatesalso PIByteArray
//! \~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>
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & 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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & v) {
s << int(v.size_s());
for (uint i = 0; i < v.size(); ++i) s << v[i];
return s;
}
//! \relatesalso PIByteArray
//! \~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>
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & 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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {
s << int(v.rows()) << int(v.cols()) << v.toPlainVector();
return s;
}
//! \relatesalso PIByteArray
//! \~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<typename Type0, typename Type1>
inline PIByteArray & operator <<(PIByteArray & s, const PIPair<Type0, Type1> & 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<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)) {
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & v) {
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if< std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
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<typename T,
typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0,
typename std::enable_if<!std::is_same<decltype(std::declval<PIByteArray&>() << std::declval<const T &>()), PIByteArray::StreamRef>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {
if (s.size_s() < 8) {
printf("error with PIVecto2Dr<%s>\n", __PIP_TYPENAME__(T));
assert(s.size_s() >= 8);
}
int r,c;
PIVector<T> tmp;
s >> r >> c >> tmp;
v = PIVector2D<T>(r, c, tmp);
return s;
}
//! \relatesalso PIByteArray
//! \~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<typename Type0, typename Type1>
inline PIByteArray & operator >>(PIByteArray & s, PIPair<Type0, Type1> & 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<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());
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<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());
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<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();
return s;
}
// restore operators for complex types
//! \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) {
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<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) {
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<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) {
printf("error with PIVecto2Dr<%s>\n", __PIP_TYPENAME__(T));
assert(s.size_s() >= 8);
}
int r,c;
PIVector<T> tmp;
s >> r >> c >> tmp;
v = PIVector2D<T>(r, c, tmp);
return s;
}
// 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());
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 <typename Key, typename T>
inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & 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<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIByteArray & operator <<(PIByteArray & s, const T & ) {
static_assert(std::is_trivially_copyable<T>::value, "[PIByteArray] Error: using undeclared operator << for complex type!");
return s;
}
template<typename T, typename std::enable_if<!std::is_trivially_copyable<T>::value, int>::type = 0>
inline PIByteArray & operator >>(PIByteArray & s, T & ) {
static_assert(std::is_trivially_copyable<T>::value, "[PIByteArray] Error: using undeclared operator >> for complex type!");
BINARY_STREAM_READ(PIByteArray) {
v.resize(s.binaryStreamTakeInt());
s.binaryStreamTake(v.data(), v.size());
return s;
}

View File

@@ -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;
}

View File

@@ -124,7 +124,7 @@ public:
//! \~english Returns value of last readed chunk
//! \~russian Возвращает значение последнего прочитанного чанка
template <typename T>
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\"

View File

@@ -42,6 +42,13 @@
//!
bool PIConstChars::contains(char c) const {
for (int i = 0; i < (int)len; ++i)
if (str[i] == c) return true;
return false;
}
bool PIConstChars::startsWith(const PIConstChars & str) const {
if (size() < str.size()) return false;
return str == left(str.size());

View File

@@ -86,6 +86,10 @@ public:
//! \~russian Возвращает \c true если строка непустая, т.е. длина > 0.
inline bool isNotEmpty() const {return len > 0;}
//! \~english Returns \c true if string contains character "c".
//! \~russian Возвращает \c true если строка содержит символ "c".
bool contains(char c) const;
//! \~english Returns characters length of string.
//! \~russian Возвращает длину строки в символах.
inline size_t length() const {return len;}

View File

@@ -320,10 +320,10 @@ PICout PICout::operator <<(const PIFlags<PICoutManipulators::PICoutFormat> & v)
#define PICOUTTOTARGET(v) { \
if (buffer_) {\
(*buffer_) << (v);\
(*buffer_) += (v);\
} else {\
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v);\
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() << (v);\
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += (v);\
}\
}
@@ -386,52 +386,52 @@ PICout PICout::operator <<(const PICoutSpecialChar v) {
switch (v) {
case Null:
if (buffer_) {
(*buffer_) << PIChar();
(*buffer_) += PIChar();
} else {
if (isOutputDeviceActive(StdOut)) std::cout << char(0);
if (isOutputDeviceActive(Buffer)) PICout::__string__() << PIChar();
if (isOutputDeviceActive(Buffer)) PICout::__string__() += PIChar();
}
break;
case NewLine:
if (buffer_) {
(*buffer_) << "\n";
(*buffer_) += "\n";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << '\n';
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\n";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\n";
}
fo_ = true;
break;
case Tab:
if (buffer_) {
(*buffer_) << "\t";
(*buffer_) += "\t";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << '\t';
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\t";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\t";
}
break;
case Esc:
#ifdef CC_VC
if (buffer_) {
(*buffer_) << PIChar(27);
(*buffer_) += PIChar(27);
} else {
if (isOutputDeviceActive(StdOut)) std::cout << char(27);
if (isOutputDeviceActive(Buffer)) PICout::__string__() << PIChar(27);
if (isOutputDeviceActive(Buffer)) PICout::__string__() += PIChar(27);
}
#else
if (buffer_) {
(*buffer_) << "\e";
(*buffer_) += "\e";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << '\e';
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\e";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\e";
}
#endif
break;
case Quote:
if (buffer_) {
(*buffer_) << "\"";
(*buffer_) += "\"";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << '"';
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\"";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\"";
}
break;
};
@@ -469,10 +469,10 @@ PICout & PICout::space() {
if (!act_) return *this;
if (!fo_ && co_[AddSpaces]) {
if (buffer_) {
(*buffer_) << " ";
(*buffer_) += " ";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << ' ';
if (isOutputDeviceActive(Buffer)) PICout::__string__() << " ";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += " ";
}
}
fo_ = false;
@@ -489,10 +489,10 @@ PICout & PICout::quote() {
if (!act_) return *this;
if (co_[AddQuotes]) {
if (buffer_) {
(*buffer_) << "\"";
(*buffer_) += "\"";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << '"';
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\"";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\"";
}
}
fo_ = false;
@@ -509,10 +509,10 @@ PICout & PICout::newLine() {
if (!act_) return *this;
if (co_[AddNewLine]) {
if (buffer_) {
(*buffer_) << "\n";
(*buffer_) += "\n";
} else {
if (isOutputDeviceActive(StdOut)) std::cout << std::endl;
if (isOutputDeviceActive(Buffer)) PICout::__string__() << "\n";
if (isOutputDeviceActive(Buffer)) PICout::__string__() += "\n";
}
}
fo_ = false;

View File

@@ -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

View File

@@ -38,6 +38,7 @@ class PIMutexLocker;
class PIObject;
class PIString;
class PIByteArray;
template <typename P> class PIBinaryStream;
#ifndef MICRO_PIP
class PIInit;
#endif

View File

@@ -0,0 +1,63 @@
/*! \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 <http://www.gnu.org/licenses/>.
*/
#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<void * >(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;
};
template<typename T>
PIMemoryBlock createMemoryBlock(const T * ptr) {return PIMemoryBlock(ptr, sizeof(T));}
#endif // PIMEMORYBLOCK_H

View File

@@ -23,6 +23,7 @@
#ifndef MICRO_PIP
# include "pisysteminfo.h"
# include "pifile.h"
# include "piiostream.h"
#endif
@@ -753,7 +754,8 @@ bool dumpApplicationToFile(const PIString & path, bool with_objects) {
bool ba = PICout::isBufferActive();
PICout::setBufferActive(true, true);
dumpApplication(with_objects);
f << PICout::buffer();
PIIOTextStream ts(&f);
ts << PICout::buffer();
f.close();
PICout::setBufferActive(ba, true);
PIFile::rename(path + "_tmp", path);

View File

@@ -271,10 +271,11 @@ 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;}
BINARY_STREAM_WRITE(PIPropertyStorage::Property) {s << v.name << v.value << v.comment << v.flags; return s;}
BINARY_STREAM_READ (PIPropertyStorage::Property) {s >> v.name >> v.value >> v.comment >> v.flags; return s;}
BINARY_STREAM_WRITE(PIPropertyStorage) {s << v.properties(); return s;}
BINARY_STREAM_READ (PIPropertyStorage) {s >> v.properties(); 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;}
#endif // PIPROPERTYSTORAGE_H

View File

@@ -215,6 +215,13 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
}
PIString PIString::fromConsole(const PIByteArray & ba) {
PIString ret;
if (ba.isNotEmpty()) ret.appendFromChars((const char*)ba.data(), ba.size(), __sysoemname__);
return ret;
}
PIString PIString::fromConsole(const char * s) {
PIString ret;
if (!s) return ret;
@@ -224,6 +231,13 @@ PIString PIString::fromConsole(const char * s) {
}
PIString PIString::fromSystem(const PIByteArray & ba) {
PIString ret;
if (ba.isNotEmpty()) ret.appendFromChars((const char*)ba.data(), ba.size(), __syslocname__);
return ret;
}
PIString PIString::fromSystem(const char * s) {
PIString ret;
if (!s) return ret;
@@ -361,6 +375,13 @@ uint PIString::hash() const {
}
PIByteArray PIString::toSystem() const {
if (isEmpty()) return PIByteArray();
buildData(__syslocname__);
return PIByteArray(data_, strlen(data_));
}
PIByteArray PIString::toUTF8() const {
if (isEmpty()) return PIByteArray();
buildData(__utf8name__);

View File

@@ -40,8 +40,7 @@ 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<PIChar>::iterator iterator;
typedef PIDeque<PIChar>::const_iterator const_iterator;
@@ -242,94 +241,6 @@ public:
//! \~russian Оператор сравнения.
bool operator >=(const char * str) const {return *this >= PIString(str);}
//! \~english Append string "str" at the end of string.
//! \~russian Добавляет в конец строку "str".
//! \~\details
//! \~\code
//! PIString s("this"), s1(" is"), s2(" string");
//! s << s1 << s2; // s = "this is string"
//! \endcode
PIString & operator <<(const PIString & str) {*this += str; return *this;}
//! \~english Append character "c" at the end of string.
//! \~russian Добавляет в конец символ "c".
//! \~\details
//! \~\code
//! PIString s("stri");
//! s << PIChar('n') << PIChar('g'); // s = "string"
//! \endcode
PIString & operator <<(const PIChar c) {d.append(c); return *this;}
//! \~english Append character `c` at the end of string.
//! \~russian Добавляет в конец символ `c`.
//! \~\details
//! \~\code
//! PIString s("stri");
//! s << 'n' << 'g'; // s = "string"
//! \endcode
PIString & operator <<(const char c) {d.append(PIChar(c)); return *this;}
//! \~english Append С-string "str" at the end of string.
//! \~russian Добавляет в конец C-строку "str".
//! \~\details
//! \~\code
//! PIString s("this");
//! s << " is" << " string"; // s = "this is string"
//! \endcode
PIString & operator <<(const char * str) {*this += str; return *this;}
//! \~english Append \c wchar_t C-string "str" at the end of string.
//! \~russian Добавляет в конец \c wchar_t C-строку "str".
//! \~\details
//! \~\code
//! PIString s;
//! s << L"№ -" << " number"; // s = "№ - number"
//! \endcode
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
PIString & operator <<(const PIConstChars & str) {*this += str; return *this;}
//! \~english Append string representation of "num" at the end of string.
//! \~russian Добавляет в конец строковое представление "num".
//! \~\details
//! \~\code
//! PIString s("ten - ");
//! s << 10; // s = "ten - 10"
//! \endcode
PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const uint & num) {*this += PIString::fromNumber(num); return *this;}
//! \~english Append string representation of "num" at the end of string.
//! \~russian Добавляет в конец строковое представление "num".
//! \~\details
//! \~\code
//! PIString s("ten - ");
//! s << 10; // s = "ten - 10"
//! \endcode
PIString & operator <<(const long & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const ulong & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const llong & num) {*this += PIString::fromNumber(num); return *this;}
PIString & operator <<(const ullong & num) {*this += PIString::fromNumber(num); return *this;}
//! \~english Append string representation of "num" at the end of string.
//! \~russian Добавляет в конец строковое представление "num".
//! \~\details
//! \~\code
//! PIString s("1/10 - ");
//! s << 0.1; // s = "1/10 - 0.1"
//! \endcode
PIString & operator <<(const float & num) {*this += PIString::fromNumber(num); return *this;}
//! \~english Append string representation of "num" at the end of string.
//! \~russian Добавляет в конец строковое представление "num".
//! \~\details
//! \~\code
//! PIString s("1/10 - ");
//! s << 0.1; // s = "1/10 - 0.1"
//! \endcode
PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
//! \~english Iterator to the first element.
//! \~russian Итератор на первый элемент.
//! \~\details
@@ -909,6 +820,10 @@ public:
//! \~russian Тоже самое, что \a toUTF8().
PIByteArray toByteArray() const {return toUTF8();}
//! \~english Returns \a PIByteArray contains \a data() of this string without terminating null-char.
//! \~russian Возвращает \a PIByteArray содержащий \a data() строки без завершающего нулевого байта.
PIByteArray toSystem() const;
//! \~english Returns \a PIByteArray contains \a dataUTF8() of this string without terminating null-char.
//! \~russian Возвращает \a PIByteArray содержащий \a dataUTF8() строки без завершающего нулевого байта.
PIByteArray toUTF8() const;
@@ -1507,10 +1422,18 @@ public:
//! \~english Returns "true" or "false"
//! \~russian Возвращает "true" или "false"
static PIString fromBool(const bool value) {return PIString(value ? PIStringAscii("true") : PIStringAscii("false"));}
//! \~english Returns string constructed from terminal codepage.
//! \~russian Возвращает строку созданную из кодировки консоли.
static PIString fromConsole(const PIByteArray & s);
//! \~english Returns string constructed from terminal codepage.
//! \~russian Возвращает строку созданную из кодировки консоли.
static PIString fromConsole(const char * s);
//! \~english Returns string constructed from system codepage.
//! \~russian Возвращает строку созданную из кодировки системы.
static PIString fromSystem(const PIByteArray & s);
//! \~english Returns string constructed from system codepage.
//! \~russian Возвращает строку созданную из кодировки системы.
@@ -1583,12 +1506,12 @@ 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_WRITE(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_READ(PIString) {v.d.clear(); s >> v.d; return s;}
//! \~english Returns concatenated string.

View File

@@ -126,15 +126,19 @@ 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;}
BINARY_STREAM_WRITE(PIStringList) {
s.binaryStreamAppend(v.size());
for (int i = 0; i < v.size_s(); ++i)
s << v[i];
return s;
}
BINARY_STREAM_READ(PIStringList) {
v.resize(s.binaryStreamTakeInt());
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;}
//! \relatesalso PICout
//! \~english Output operator to \a PICout

View File

@@ -0,0 +1,341 @@
/*! \file pitextstream.h
* \ingroup Core
* \~\brief
* \~english Text serialization functionality over PIBinaryStream
* \~russian Функциональность текстовой сериализации поверх PIBinaryStream
*/
/*
PIP - Platform Independent Primitives
Text serialization functionality over PIBinaryStream
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 <http://www.gnu.org/licenses/>.
*/
#ifndef PITEXTSTREAM_H
#define PITEXTSTREAM_H
#include "pistring.h"
//! \ingroup Core
//! \~\brief
//! \~english Text serialization functionality over PIBinaryStream.
//! \~russian Функциональность текстовой сериализации поверх PIBinaryStream.
template<typename P>
class PITextStream {
public:
//! \~english Floating-point numbers write format
//! \~russian Формат записи чисел с плавающей точкой
enum FloatFormat {
DecimalFormat /** \~english Decimal format, "*.*" \~russian Десятичный формат, "*.*" */ = 'f',
ExponentFormat /** \~english Exponential format, "*e+-<E>" \~russian Экспонентный формат, "*e+-<E>" */ = 'e'
};
//! \~english String encoding
//! \~russian Кодировка строк
enum Encoding {
System /** \~english System encoding \~russian Системная кодировка */,
UTF8 /** \~english UTF-8 encoding \~russian Кодировка UTF-8 */,
};
//! \~english Construct text stream binded to "stream_"
//! \~russian Возвращает привязанный к "stream_" текстовый поток
PITextStream(PIBinaryStream<P> * stream_) {setStream(stream_);}
//! \~english Returns binded PIBinaryStream
//! \~russian Возвращает привязанный PIBinaryStream
PIBinaryStream<P> * stream() const {return s;}
void setStream(PIBinaryStream<P> * stream_) {
s = stream_;
is_end = false;
}
//! \~english Returns if end of stream reached
//! \~russian Возвращает достигнут ли конец потока
bool isEnd() const {return is_end;}
//! \~english Returns read/write encoding
//! \~russian Возвращает кодировку чтения/записи
Encoding encoding() const {return enc;}
//! \~english Set read/write encoding, default UTF8
//! \~russian Устанавливает кодировку чтения/записи, по умолчанию UTF8
void setEncoding(Encoding e) {enc = e;}
//! \~english Returns float numbers write format
//! \~russian Возвращает формат записи чисел с плавающей точкой
FloatFormat floatFormat() const {return format_;}
//! \~english Set float numbers write format, default DecimalFormat
//! \~russian Устанавливает формат записи чисел с плавающей точкой, по умолчанию DecimalFormat
void setFloatFormat(FloatFormat format) {format_ = format;}
//! \~english Returns float numbers write precision
//! \~russian Возвращает точность записи чисел с плавающей точкой
int floatPrecision() const {return prec_;}
//! \~english Set float numbers write precision to "prec_" digits, default 5
//! \~russian Устанавливает точность записи чисел с плавающей точкой, по умолчанию 5
void setFloatPrecision(int prec) {prec_ = prec;}
//! \~english Append space
//! \~russian Добавляет пробел
PITextStream<P> & space() {s->binaryStreamAppend(' '); return *this;}
//! \~english Append new line
//! \~russian Добавляет новую строку
PITextStream<P> & newLine() {s->binaryStreamAppend('\n'); return *this;}
//! \~english Append "v" string
//! \~russian Добавляет строку "v"
void append(const PIString & v) {
if (v.isEmpty()) return;
PIByteArray d;
switch (enc) {
case System: d = v.toSystem(); break;
case UTF8 : d = v.toUTF8(); break;
}
s->binaryStreamAppend(d.data(), d.size());
}
//! \~english Append "v" as ASCII
//! \~russian Добавляет "v" как ASCII
void append(const PIConstChars & v) {if (!v.isEmpty()) s->binaryStreamAppend(v.data(), v.size());}
//! \~english Append "v" char as character
//! \~russian Добавляет "v" как символ
void append(char v) {s->binaryStreamAppend(v);}
//! \~english Append "v" as ASCII
//! \~russian Добавляет "v" как ASCII
void append(const char * v) {append(PIConstChars(v));}
//! \~english Append boolean, "true" of "false"
//! \~russian Добавляет логическое, "true" of "false"
void append(bool v) {append(v ? "true" : "false");}
//! \~english Append integer
//! \~russian Добавляет целое
void append(int v) {append(PIString::fromNumber(v));}
//! \~english Append integer
//! \~russian Добавляет целое
void append(llong v) {append(PIString::fromNumber(v));}
//! \~english Append floating-point number, using \a floatFormat() and \a floatPrecision()
//! \~russian Добавляет число с плавающей точкой, используя \a floatFormat() и \a floatPrecision()
void append(float v) {append(PIString::fromNumber(v, (char)format_, prec_));}
//! \~english Append floating-point number, using \a floatFormat() and \a floatPrecision()
//! \~russian Добавляет число с плавающей точкой, используя \a floatFormat() и \a floatPrecision()
void append(double v) {append(PIString::fromNumber(v, (char)format_, prec_));}
//! \~english Read character
//! \~russian Читает символ
char takeChar(bool * rok) {
bool ok = true;
char ret = (char)s->binaryStreamTakeByte(&ok);
if (!ok) is_end = true;
if (rok) *rok = ok;
return ret;
}
//! \~english Read line
//! \~russian Читает строку
PIString takeLine() {
PIByteArray ret;
bool ok = true;
for (;;) {
char b = takeChar(&ok);
if (!ok || b == '\n') break;
if (b != '\r')
ret.append((uchar)b);
}
return fromBytes(ret);
}
//! \~english Read word, skip leading whitespaces, until next whitespace
//! \~russian Читает слово, пропуская начальные пробельные символы, до следующего пробельного символа
PIString takeWord() {
static PIConstChars spaces(" \t\n\r");
return takeUntil(spaces);
}
//! \~english
//! \~russian
PIString takeCWord() {
static PIConstChars chars(" \t\n\r:;%$&#@!?~/*-+=.,\\\"'`[](){}<>");
return takeUntil(chars);
}
private:
PIString fromBytes(const PIByteArray & ba) {
switch (enc) {
case System: return PIString::fromSystem(ba);
case UTF8 : return PIString::fromUTF8(ba);
}
return PIString();
}
PIString takeUntil(const PIConstChars & chars) {
//static PIConstChars spaces(" \t\n\r");
bool ok = true;
char c = skipWhile(chars, &ok);
if (!ok) return PIString();
PIByteArray ret;
ret.append((uchar)c);
for (;;) {
c = takeChar(&ok);
if (!ok || chars.contains(c)) break;
ret.append((uchar)c);
}
return fromBytes(ret);
}
// returns first non-"chars" char
char skipWhile(const PIConstChars & chars, bool * rok) {
bool ok = true;
char c = 0;
for (;;) {
c = takeChar(&ok);
if (!ok || !chars.contains(c)) break;
}
if (rok) *rok = ok;
return c;
}
PIBinaryStream<P> * s;
Encoding enc = UTF8;
FloatFormat format_ = DecimalFormat;
bool is_end = false;
int prec_ = 5;
};
//! \~english Returns PITextStream for binary stream "stream"
//! \~russian Возвращает PITextStream для бинарного потока "stream"
template<typename P>
inline PITextStream<P> createPITextStream(PIBinaryStream<P> * stream) {return PITextStream<P>(stream);}
//! \~english Append boolean
//! \~russian Добавляет логическое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, bool v) {s.append(v); return s;}
//! \~english Append character
//! \~russian Добавляет символ
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, char v) {s.append(v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, uchar v) {s.append((int)v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, short v) {s.append((int)v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, ushort v) {s.append((int)v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, int v) {s.append((int)v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, uint v) {s.append((int)v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, llong v) {s.append((llong)v); return s;}
//! \~english Append integer
//! \~russian Добавляет целое
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, ullong v) {s.append((llong)v); return s;}
//! \~english Append floating-point number
//! \~russian Добавляет число с плавающей точкой
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, float v) {s.append(v); return s;}
//! \~english Append floating-point number
//! \~russian Добавляет число с плавающей точкой
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, double v) {s.append(v); return s;}
//! \~english Append string
//! \~russian Добавляет строку
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const char * v) {s.append(v); return s;}
//! \~english Append string
//! \~russian Добавляет строку
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const PIConstChars & v) {s.append(v); return s;}
//! \~english Append string
//! \~russian Добавляет строку
template<typename P> inline PITextStream<P> & operator <<(PITextStream<P> & s, const PIString & v) {s.append(v); return s;}
//! \~english Read word as bool
//! \~russian Читает слово как логическое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, bool & v) {v = s.takeWord().toBool(); return s;}
//! \~english Read character
//! \~russian Читает символ
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, char & v) {v = s.takeChar(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uchar & v) {v = s.takeWord().toUInt(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, short & v) {v = s.takeWord().toInt(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ushort & v) {v = s.takeWord().toUInt(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, int & v) {v = s.takeWord().toInt(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, uint & v) {v = s.takeWord().toUInt(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, llong & v) {v = s.takeWord().toLLong(); return s;}
//! \~english Read word as integer
//! \~russian Читает слово как целое
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, ullong & v) {v = s.takeWord().toULLong(); return s;}
//! \~english Read word as floating-point number
//! \~russian Читает слово как число с плавающей точкой
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, float & v) {v = s.takeWord().toFloat(); return s;}
//! \~english Read word as floating-point number
//! \~russian Читает слово как число с плавающей точкой
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, double & v) {v = s.takeWord().toDouble(); return s;}
//! \~english Read word
//! \~russian Читает слово
template<typename P> inline PITextStream<P> & operator >>(PITextStream<P> & s, PIString & v) {v = s.takeWord(); return s;}
#endif

View File

@@ -206,8 +206,7 @@ classname_to __PIVariantFunctions__<classname_from>::castVariant<classname_to>(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,8 +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);
BINARY_STREAM_WRITE(PIVariant) {
s << v._content << v._type;
if (v._type == PIVariant::pivCustom) {
#ifdef CUSTOM_PIVARIANT
if (v._info) {
@@ -788,10 +788,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVariant & v) {
}
return s;
}
inline PIByteArray & operator >>(PIByteArray & s, PIVariant & v) {
int t(0);
s >> v._content >> t;
v._type = (PIVariant::Type)t;
BINARY_STREAM_READ(PIVariant) {
s >> v._content >> v._type;
if (v._type == PIVariant::pivCustom) {
PIString tn;
s >> tn;

View File

@@ -110,25 +110,25 @@ PIPropertyStorage PIVariantTypes::IODevice::get() const {
PIString PIVariantTypes::IODevice::toPICout() const {
PIString s;
s << "IODevice(" << prefix << ", mode=";
s += "IODevice(" + prefix + ", mode=";
int rwc = 0;
if (mode & 1) {s << "r"; ++rwc;}
if (mode & 2) {s << "w"; ++rwc;}
if (rwc == 1) s << "o";
s << ", flags=";
if (mode & 1) {s += "r"; ++rwc;}
if (mode & 2) {s += "w"; ++rwc;}
if (rwc == 1) s += "o";
s += ", flags=";
#ifndef MICRO_PIP // TODO: PIIODevice for MICRO PIP
if (options != 0) {
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead])
s << " br";
s += " br";
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite])
s << " bw";
s += " bw";
}
#endif // MICRO_PIP
PIPropertyStorage ps = get();
piForeachC (PIPropertyStorage::Property & p, ps) {
s << ", " << p.name << "=\"" << p.value.toString() << "\"";
s += ", " + p.name + "=\"" + p.value.toString() + "\"";
}
s << ")";
s += ")";
return s;
}

View File

@@ -164,28 +164,34 @@ 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_WRITE(PIVariantTypes::Enumerator) {s << v.value << v.name; return s;}
BINARY_STREAM_READ (PIVariantTypes::Enumerator) {s >> v.value >> v.name; return s;}
BINARY_STREAM_WRITE(PIVariantTypes::Enum) {s << v.enum_name << v.selected << v.enum_list; return s;}
BINARY_STREAM_READ (PIVariantTypes::Enum) {s >> v.enum_name >> v.selected >> v.enum_list; return s;}
BINARY_STREAM_WRITE(PIVariantTypes::File) {s << v.file << v.filter << uchar((v.is_abs ? 1 : 0) + (v.is_save ? 2 : 0)); return s;}
BINARY_STREAM_READ (PIVariantTypes::File) {uchar f(0); s >> v.file >> v.filter >> f; v.is_abs = ((f & 1) == 1); v.is_save = ((f & 2) == 2); return s;}
BINARY_STREAM_WRITE(PIVariantTypes::Dir) {s << v.dir << v.is_abs; return s;}
BINARY_STREAM_READ (PIVariantTypes::Dir) {s >> v.dir >> v.is_abs; return s;}
BINARY_STREAM_WRITE(PIVariantTypes::Color) {s << v.rgba; return s;}
BINARY_STREAM_READ (PIVariantTypes::Color) {s >> v.rgba; return s;}
BINARY_STREAM_WRITE(PIVariantTypes::IODevice) {s << v.prefix << v.mode << v.options << v.props; return s;}
BINARY_STREAM_READ (PIVariantTypes::IODevice) {s >> v.prefix >> v.mode >> v.options >> v.props; return s;}
#endif // PIVARIANTYPES_H

View File

@@ -96,15 +96,3 @@ PIVector<PIIntrospectionContainers::TypeInfo> 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;
}

View File

@@ -65,7 +65,14 @@ 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_WRITE(PIIntrospectionContainers::TypeInfo) {
s << PIMemoryBlock(&v, sizeof(PIIntrospectionContainers::_Type)) << v.name;
return s;
}
BINARY_STREAM_READ(PIIntrospectionContainers::TypeInfo) {
s >> PIMemoryBlock(&v, sizeof(PIIntrospectionContainers::_Type)) >> v.name;
return s;
}
#endif // PIINTROSPECTION_CONTAINERS_P_H

View File

@@ -77,82 +77,6 @@ PIVector<PIIntrospection::ObjectInfo> 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() {

View File

@@ -24,6 +24,7 @@
#include "piintrospection_containers_p.h"
#include "piintrospection_threads.h"
#include "piintrospection_threads_p.h"
#include "pichunkstream.h"
#include "pisystemmonitor.h"
@@ -91,13 +92,72 @@ 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);
BINARY_STREAM_WRITE(PIIntrospection::RequiredInfo) {
PIChunkStream cs;
cs.add(1, v.types);
s << cs.data();
return s;
}
BINARY_STREAM_READ(PIIntrospection::RequiredInfo) {
PIByteArray csba; s >> csba;
PIChunkStream cs(csba);
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: cs.get(v.types); break;
default: break;
}
}
return s;
}
PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v);
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v);
BINARY_STREAM_WRITE(PIIntrospection::ProcessInfo) {
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);
s << cs.data();
return s;
}
BINARY_STREAM_READ(PIIntrospection::ProcessInfo) {
PIByteArray csba; s >> 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 s;
}
BINARY_STREAM_WRITE(PIIntrospection::ObjectInfo) {
PIChunkStream cs;
cs.add(1, v.classname).add(2, v.name).add(3, v.parents).add(4, v.properties).add(5, v.queued_events);
s << cs.data();
return s;
}
BINARY_STREAM_READ(PIIntrospection::ObjectInfo) {
PIByteArray csba; s >> 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 s;
}
#endif // PIINTROSPECTION_SERVER_P_H

View File

@@ -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;
}

View File

@@ -57,7 +57,14 @@ public:
};
PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v);
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v);
BINARY_STREAM_WRITE(PIIntrospectionThreads::ThreadInfo) {
s << v.classname << v.name << v.id << v.state << v.priority << v.delay << v.run_us << v.run_count;
return s;
}
BINARY_STREAM_READ(PIIntrospectionThreads::ThreadInfo) {
s >> v.classname >> v.name >> v.id >> v.state >> v.priority >> v.delay >> v.run_us >> v.run_count;
return s;
}
#endif // PIINTROSPECTION_THREADS_P_H

View File

@@ -148,7 +148,7 @@ int PICAN::readedCANID() const {
PIString PICAN::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << PIString::fromNumber(CANID(),16);
ret += path() + ":" + PIString::fromNumber(CANID(), 16);
return ret;
}

View File

@@ -400,7 +400,7 @@ PIString PIConfig::_readLineDev() {
void PIConfig::_writeDev(const PIString & l) {
//piCout << "write \"" << l << "\"";
if (!dev) return;
if (PIString(dev->className()) == "PIFile") {*((PIFile*)dev) << (l); return;}
if (PIString(dev->className()) == "PIFile") {((PIFile*)dev)->write(l.toUTF8()); return;}
if (PIString(dev->className()) == "PIIOString") {((PIIOString*)dev)->writeString(l); return;}
dev->write(l.toByteArray());
}

View File

@@ -116,9 +116,9 @@ PIEthernet::Address::Address(const PIString & _ip, ushort _port) {
PIString PIEthernet::Address::ipString() const {
PIString ret = PIString::fromNumber(ip_b[0]);
ret << "." << PIString::fromNumber(ip_b[1]);
ret << "." << PIString::fromNumber(ip_b[2]);
ret << "." << PIString::fromNumber(ip_b[3]);
ret += "." + PIString::fromNumber(ip_b[1]);
ret += "." + PIString::fromNumber(ip_b[2]);
ret += "." + PIString::fromNumber(ip_b[3]);
return ret;
}
@@ -930,11 +930,12 @@ void PIEthernet::propertyChanged(const char * name) {
PIString PIEthernet::constructFullPathDevice() const {
PIString ret;
ret << (type() == PIEthernet::UDP ? "UDP" : "TCP") << ":" << readIP() << ":" << readPort();
ret += (type() == PIEthernet::UDP ? "UDP" : "TCP");
ret += ":" + readIP() + ":" + PIString::fromNumber(readPort());
if (type() == PIEthernet::UDP) {
ret << ":" << sendIP() << ":" << sendPort();
ret += ":" + sendIP() + ":" + PIString::fromNumber(sendPort());
piForeachC (PIString & m, multicastGroups())
ret << ":mcast:" << m;
ret += ":mcast:" + m;
}
return ret;
}

View File

@@ -452,7 +452,8 @@ void PIFile::setPrecision(int prec) {
PIFile & PIFile::put(const PIByteArray & v) {
writeBinary((int)v.size_s());
int sz = (int)v.size_s();
write(createMemoryBlock(&sz));
write(v);
return *this;
}
@@ -461,7 +462,7 @@ PIFile & PIFile::put(const PIByteArray & v) {
PIByteArray PIFile::get() {
PIByteArray ret;
int sz(0);
read(&sz, sizeof(sz));
read(createMemoryBlock(&sz));
if (sz > 0) {
ret.resize(sz);
read(ret.data(), sz);
@@ -470,156 +471,6 @@ PIByteArray PIFile::get() {
}
PIFile &PIFile::operator <<(double v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v);
return *this;
}
PIFile &PIFile::operator >>(double & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lf", &v);
return *this;
}
PIFile &PIFile::operator >>(float & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%f", &v);
return *this;
}
PIFile &PIFile::operator >>(ullong & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
return *this;
}
PIFile &PIFile::operator >>(ulong & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
return *this;
}
PIFile &PIFile::operator >>(uint & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
return *this;
}
PIFile &PIFile::operator >>(ushort & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
return *this;
}
PIFile &PIFile::operator >>(uchar & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
return *this;
}
PIFile &PIFile::operator >>(llong & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%lln", &v);
return *this;
}
PIFile &PIFile::operator >>(long & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%ln", &v);
return *this;
}
PIFile &PIFile::operator >>(int & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%n", &v);
return *this;
}
PIFile &PIFile::operator >>(short & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hn", &v);
return *this;
}
PIFile &PIFile::operator >>(char & v) {
if (canRead() && PRIVATE->fd != 0) ret = fscanf(PRIVATE->fd, "%hhn", &v);
return *this;
}
PIFile &PIFile::operator <<(float v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "f").data(), v);
return *this;
}
PIFile &PIFile::operator <<(ullong v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%llu", v);
return *this;
}
PIFile &PIFile::operator <<(ulong v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lu", v);
return *this;
}
PIFile &PIFile::operator <<(uint v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", v);
return *this;
}
PIFile &PIFile::operator <<(ushort v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hu", v);
return *this;
}
PIFile &PIFile::operator <<(uchar v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%u", int(v));
return *this;
}
PIFile &PIFile::operator <<(llong v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%lld", v);
return *this;
}
PIFile &PIFile::operator <<(long v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%ld", v);
return *this;
}
PIFile &PIFile::operator <<(int v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%d", v);
return *this;
}
PIFile &PIFile::operator <<(short v) {
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, "%hd", v);
return *this;
}
PIFile &PIFile::operator <<(const PIByteArray & v) {
if (canWrite() && PRIVATE->fd != 0) write(v.data(), v.size());
return *this;
}
PIFile &PIFile::operator <<(const char v) {
if (canWrite() && PRIVATE->fd != 0) write(&v, 1);
return *this;
}
int PIFile::readDevice(void * read_to, int max_size) {
if (!canRead() || PRIVATE->fd == 0) return -1;
return fread(read_to, 1, max_size, PRIVATE->fd);
@@ -632,13 +483,6 @@ int PIFile::writeDevice(const void * data, int max_size) {
}
PIFile &PIFile::operator <<(const PIString & v) {
if (canWrite() && v.isNotEmpty() && PRIVATE->fd != 0)
*this << v.toCharset(defaultCharset());
return *this;
}
void PIFile::clear() {
close();
PRIVATE->fd = fopen(path().data(), "w");

View File

@@ -260,161 +260,6 @@ public:
//! \~russian Читает из файла размер байтового массива и его содержимое (десериализация)
PIByteArray get();
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const short v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const int v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const long v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const llong v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const uchar v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const ushort v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const uint v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const ulong v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const ullong v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const float v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file binary content of "v"
//! \~russian Пишет в файл байтовое содержимое "v"
PIFile & writeBinary(const double v) {write(&v, sizeof(v)); return *this;}
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(const char v);
//! \~english Write to file string "v"
//! \~russian Пишет в файл строку "v"
PIFile & operator <<(const PIString & v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(const PIByteArray & v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(short v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(int v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(long v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(llong v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(uchar v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(ushort v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(uint v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(ulong v);
//! \~english Write to file text representation of "v"
//! \~russian Пишет в файл текстовое представление "v"
PIFile & operator <<(ullong v);
//! \~english Write to file text representation of "v" with precision \a precision()
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
PIFile & operator <<(float v);
//! \~english Write to file text representation of "v" with precision \a precision()
//! \~russian Пишет в файл текстовое представление "v" с точностью \a precision()
PIFile & operator <<(double v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(char & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(short & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(int & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(long & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(llong & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(uchar & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(ushort & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(uint & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(ulong & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(ullong & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(float & v);
//! \~english Read from file text representation of "v"
//! \~russian Читает из файла текстовое представление "v"
PIFile & operator >>(double & v);
EVENT_HANDLER(void, clear);
EVENT_HANDLER(void, remove);
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
@@ -518,14 +363,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_WRITE(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_READ(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

View File

@@ -276,6 +276,10 @@ public:
//! \~russian Читает из устройства не более "max_size" байт в "read_to"
int read(void * read_to, int max_size) {return readDevice(read_to, max_size);}
//! \~english Read from device to memory block "mb"
//! \~russian Читает из устройства в блок памяти "mb"
int read(PIMemoryBlock mb) {return readDevice(mb.data(), mb.size());}
//! \~english Read from device maximum "max_size" bytes and returns them as PIByteArray
//! \~russian Читает из устройства не более "max_size" байт и возвращает данные как PIByteArray
PIByteArray read(int max_size);
@@ -357,6 +361,10 @@ public:
EVENT_HANDLER(bool, close);
EVENT_HANDLER1(int, write, PIByteArray, data);
//! \~english Write memory block "mb" to device
//! \~russian Пишет в устройство блок памяти "mb"
int write(const PIMemoryBlock & mb) {return write(mb.data(), mb.size());}
EVENT_VHANDLER(void, flush) {;}
EVENT(opened)

View File

@@ -0,0 +1,99 @@
/*! \file piiostream.h
* \ingroup IO
* \~\brief
* \~english PIBinaryStream functionality for PIIODevice
* \~russian Функциональность PIBinaryStream для PIIODevice
*/
/*
PIP - Platform Independent Primitives
PIBinaryStream functionality for PIIODevice
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 <http://www.gnu.org/licenses/>.
*/
#ifndef PIIOSTREAM_H
#define PIIOSTREAM_H
#include "piiostring.h"
#include "pitextstream.h"
//! \ingroup IO
//! \~\brief
//! \~english PIBinaryStream functionality for PIIODevice.
//! \~russian Функциональность PIBinaryStream для PIIODevice.
class PIP_EXPORT PIIOBinaryStream: public PIBinaryStream<PIIOBinaryStream> {
public:
//! \~english Contructs %PIIOBinaryStream for "device" device
//! \~russian Создает %PIIOBinaryStream для устройства "device"
PIIOBinaryStream(PIIODevice * device = nullptr): dev(device) {}
//! \~english Assign "device" device
//! \~russian Назначает устройство "device"
void setDevice(PIIODevice * device) {dev = device;}
bool binaryStreamAppendImp(const void * d, size_t s) {
if (!dev) return false;
return dev->write(d, s);
}
bool binaryStreamTakeImp(void * d, size_t s) {
if (!dev) return false;
return dev->read(d, s);
}
private:
PIIODevice * dev;
};
//! \ingroup IO
//! \~\brief
//! \~english PITextStream functionality for PIIODevice.
//! \~russian Функциональность PITextStream для PIIODevice.
class PIP_EXPORT PIIOTextStream: public PITextStream<PIIOBinaryStream> {
public:
//! \~english Contructs %PIIOTextStream for "device" device
//! \~russian Создает %PIIOTextStream для устройства "device"
PIIOTextStream(PIIODevice * device): PITextStream<PIIOBinaryStream>(&bin_stream), bin_stream(device) {}
//! \~english Contructs %PIIOTextStream for "string" string
//! \~russian Создает %PIIOTextStream для строки "string"
PIIOTextStream(PIString * string): PITextStream<PIIOBinaryStream>(&bin_stream) {
io_string = new PIIOString(string);
bin_stream.setDevice(io_string);
}
~PIIOTextStream() {
if (io_string)
delete io_string;
}
void setDevice(PIIODevice * device) {
bin_stream = PIIOBinaryStream(device);
setStream(&bin_stream);
}
private:
PIIOString * io_string = nullptr;
PIIOBinaryStream bin_stream;
};
#endif // PIIOSTREAM_H

View File

@@ -573,7 +573,7 @@ bool PIPeer::mbcastRead(uchar * data, int size) {
if (type <= 0 || type >= 4) return true;
PeerInfo pi;
ba >> pi.name;
// piCoutObj << "received mb from" << pi.name << "packet" << type;
//piCout << "received mb from" << pi.name << "packet" << type;
if (pi.name == self_info.name) return true;
PIMutexLocker locker(mc_mutex);
diag_s.received(size);
@@ -789,6 +789,7 @@ void PIPeer::sendPeerInfo(const PeerInfo & info) {
void PIPeer::sendPeerRemove(const PIString & peer) {
//piCout << name() << "sendPeerRemove" << peer;
PIByteArray ba;
ba << int(2) << peer;
sendMBcast(ba);
@@ -858,7 +859,7 @@ void PIPeer::syncPeers() {
PeerInfo & cp(peers[i]);
if (cp.sync > 3) {
pn = cp.name;
//piCoutObj << "sync: remove " << pn;
//piCout << "sync: remove " << pn;
cp.destroy();
addToRemoved(cp);
peers.remove(i);
@@ -967,7 +968,7 @@ void PIPeer::newTcpClient(PIEthernet *client) {
PIString PIPeer::constructFullPathDevice() const {
PIString ret;
ret << self_info.name << ":" << trustPeerName();
ret += self_info.name + ":" + trustPeerName();
return ret;
}

View File

@@ -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_WRITE(PIPeer::PeerInfo::PeerAddress) {s << v.address << v.netmask << v.ping; return s;}
BINARY_STREAM_READ (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_WRITE(PIPeer::PeerInfo) {s << v.name << v.addresses << v.dist << v.neighbours << v.cnt << v.time; return s;}
BINARY_STREAM_READ (PIPeer::PeerInfo) {s >> v.name >> v.addresses >> v.dist >> v.neighbours >> v.cnt >> v.time; return s;}
#endif // PIPEER_H

View File

@@ -521,14 +521,14 @@ PIString PISerial::readString(int size, double timeout_ms) {
while (tm_.elapsed_m() < timeout_ms) {
ret = readDevice(td, 1024);
if (ret <= 0) piMinSleep();
else str << PIString((char*)td, ret);
else str += PIString((char*)td, ret);
}
} else {
while (all < size && tm_.elapsed_m() < timeout_ms) {
ret = readDevice(td, size - all);
if (ret <= 0) piMinSleep();
else {
str << PIString((char*)td, ret);
str += PIString((char*)td, ret);
all += ret;
}
}
@@ -537,12 +537,12 @@ PIString PISerial::readString(int size, double timeout_ms) {
} else {
bool br = setOption(BlockingRead, true);
all = readDevice(td, 1);
str << PIString((char*)td, all);
str += PIString((char*)td, all);
while (all < size) {
ret = readDevice(td, size - all);
if (ret <= 0) piMinSleep();
else {
str << PIString((char*)td, ret);
str += PIString((char*)td, ret);
all += ret;
}
}
@@ -862,13 +862,13 @@ bool PISerial::configureDevice(const void * e_main, const void * e_parent) {
PIString PISerial::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << int(inSpeed()) << ":" << dataBitsCount();
ret += path() + ":" + PIString::fromNumber(int(inSpeed())) + ":" + PIString::fromNumber(dataBitsCount());
if (parameters()[ParityControl]) {
if (parameters()[ParityOdd]) ret << ":O";
else ret << ":E";
} else ret << ":N";
if (parameters()[TwoStopBits]) ret << ":2";
else ret << ":1";
if (parameters()[ParityOdd]) ret += ":O";
else ret += ":E";
} else ret += ":N";
if (parameters()[TwoStopBits]) ret += ":2";
else ret += ":1";
return ret;
}

View File

@@ -336,12 +336,12 @@ inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceI
//! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
inline PIByteArray & operator <<(PIByteArray & s, const PISerial::DeviceInfo & v) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
BINARY_STREAM_WRITE(PISerial::DeviceInfo) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
//! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
inline PIByteArray & operator >>(PIByteArray & s, PISerial::DeviceInfo & v) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
BINARY_STREAM_READ (PISerial::DeviceInfo) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
#endif // PISERIAL_H

View File

@@ -170,7 +170,7 @@ bool PISharedMemory::closeDevice() {
PIString PISharedMemory::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << dsize;
ret += path() + ":" + PIString::fromNumber(dsize);
return ret;
}

View File

@@ -157,7 +157,7 @@ int PISPI::writeDevice(const void * data, int max_size) {
PIString PISPI::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << int(speed()) << ":" << int(bits()) << ":" << (int)parameters();
ret += path() + ":" + PIString::fromNumber((int)speed()) + ":" + PIString::fromNumber((int)bits()) + ":" + PIString::fromNumber((int)parameters());
return ret;
}

View File

@@ -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_WRITE(PIBaseTransfer::PacketHeader) {s << v.sig << v.type << v.session_id << v.id << v.crc; return s;}
BINARY_STREAM_READ (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_WRITE(PIBaseTransfer::Part) {s << v.id << v.size << v.start; return s;}
BINARY_STREAM_READ (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_WRITE(PIBaseTransfer::StartRequest) {s << v.packets << v.size; return s;}
BINARY_STREAM_READ (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;}

View File

@@ -19,6 +19,7 @@
#include "piconnection.h"
#include "piconfig.h"
#include "piiostream.h"
/** \class PIConnection
* \brief Complex Input/Output point
@@ -259,18 +260,19 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
PIString PIConnection::makeConfig() const {
PIString ret;
ret << "[" << name() << "]\n";
PIIOTextStream ts(&ret);
ts << "[" << name() << "]\n";
PIVector<PIIODevice * > devs(boundedDevices());
int dn(-1);
piForeachC (PIIODevice * d, devs) {
PIStringList dnl(deviceNames(d));
if (dnl.isEmpty()) dnl << PIString::fromNumber(++dn);
piForeachC (PIString & dname, dnl) {
ret << "device." << dname << " = " << d->constructFullPath() << " #s\n";
ret << "device." << dname << ".bufferSize = " << d->threadedReadBufferSize() << " #n\n";
ts << "device." << dname << " = " << d->constructFullPath() << " #s\n";
ts << "device." << dname << ".bufferSize = " << d->threadedReadBufferSize() << " #n\n";
PIDiagnostics * diag = diags_.value(const_cast<PIIODevice * >(d), 0);
if (diag != 0)
ret << "device." << dname << ".disconnectTimeout = " << diag->disconnectTimeout() << " #f\n";
ts << "device." << dname << ".disconnectTimeout = " << diag->disconnectTimeout() << " #f\n";
}
}
piForeachC (PEPair & f, extractors) {
@@ -280,27 +282,27 @@ PIString PIConnection::makeConfig() const {
for (int i = 0; i < f.second->devices.size_s(); ++i) {
PIString dname = device_names.key(f.second->devices[i]);
if (dname.isEmpty()) dname = devPath(f.second->devices[i]);
ret << prefix << ".device." << i << " = " << dname << " #s\n";
ts << prefix << ".device." << i << " = " << dname << " #s\n";
}
PIDiagnostics * diag = diags_.value(f.second->extractor, 0);
ret << prefix << ".bufferSize = " << f.second->extractor->bufferSize() << " #n\n";
ts << prefix << ".bufferSize = " << f.second->extractor->bufferSize() << " #n\n";
if (diag != 0)
ret << prefix << ".disconnectTimeout = " << diag->disconnectTimeout() << " #f\n";
ret << prefix << ".splitMode = ";
ts << prefix << ".disconnectTimeout = " << diag->disconnectTimeout() << " #f\n";
ts << prefix << ".splitMode = ";
switch (f.second->extractor->splitMode()) {
case PIPacketExtractor::None: ret << "none"; break;
case PIPacketExtractor::Header: ret << "header"; break;
case PIPacketExtractor::Footer: ret << "footer"; break;
case PIPacketExtractor::HeaderAndFooter: ret << "header & footer"; break;
case PIPacketExtractor::Size: ret << "size"; break;
case PIPacketExtractor::Timeout: ret << "timeout"; break;
case PIPacketExtractor::None: ts << "none"; break;
case PIPacketExtractor::Header: ts << "header"; break;
case PIPacketExtractor::Footer: ts << "footer"; break;
case PIPacketExtractor::HeaderAndFooter: ts << "header & footer"; break;
case PIPacketExtractor::Size: ts << "size"; break;
case PIPacketExtractor::Timeout: ts << "timeout"; break;
}
ret << " #s\n";
ret << prefix << ".payloadSize = " << f.second->extractor->payloadSize() << " #n\n";
ret << prefix << ".packetSize = " << f.second->extractor->packetSize() << " #n\n";
ret << prefix << ".timeout = " << f.second->extractor->timeout() << " #f\n";
ret << prefix << ".header = " << f.second->extractor->header().toString() << " #s\n";
ret << prefix << ".footer = " << f.second->extractor->footer().toString() << " #s\n";
ts << " #s\n";
ts << prefix << ".payloadSize = " << f.second->extractor->payloadSize() << " #n\n";
ts << prefix << ".packetSize = " << f.second->extractor->packetSize() << " #n\n";
ts << prefix << ".timeout = " << f.second->extractor->timeout() << " #f\n";
ts << prefix << ".header = " << f.second->extractor->header().toString() << " #s\n";
ts << prefix << ".footer = " << f.second->extractor->footer().toString() << " #s\n";
}
dn = 0;
piForeachC (CPair & c, channels_) {
@@ -308,10 +310,10 @@ PIString PIConnection::makeConfig() const {
PIString prefix = "channel." + PIString::fromNumber(dn); ++dn;
PIString dname = device_names.key(c.first);
if (dname.isEmpty()) dname = devPath(c.first);
ret << prefix << ".from = " << dname << " #s\n";
ts << prefix << ".from = " << dname << " #s\n";
dname = device_names.key(const_cast<PIIODevice *>(d));
if (dname.isEmpty()) dname = devPath(d);
ret << prefix << ".to = " << dname << " #s\n";
ts << prefix << ".to = " << dname << " #s\n";
}
}
piForeachC (SPair & s, senders) {
@@ -320,15 +322,15 @@ PIString PIConnection::makeConfig() const {
for (int i = 0; i < s.second->devices.size_s(); ++i) {
PIString dname = device_names.key(s.second->devices[i]);
if (dname.isEmpty()) dname = devPath(s.second->devices[i]);
ret << prefix << ".device." << i << " = " << dname << " #s\n";
ts << prefix << ".device." << i << " = " << dname << " #s\n";
}
double int_ = s.second->int_;
if (int_ > 0.)
ret << prefix << ".frequency = " << (1000. / int_) << " #f\n";
ts << prefix << ".frequency = " << (1000. / int_) << " #f\n";
if (!s.second->sdata.isEmpty())
ret << prefix << ".fixedData = " << s.second->sdata.toString() << " #s\n";
ts << prefix << ".fixedData = " << s.second->sdata.toString() << " #s\n";
}
ret << "[]\n";
ts << "[]\n";
return ret;
}

View File

@@ -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_WRITE(PIFileTransfer::PFTHeader) {s << v.raw_sig << v.step << v.session_id; return s;}
BINARY_STREAM_READ (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_WRITE(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_READ (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);

View File

@@ -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_WRITE(PIEvaluatorTypes::Instruction) {s << PIMemoryBlock(&v, sizeof(v) - sizeof(v.operators)) << v.operators; return s;}
BINARY_STREAM_READ (PIEvaluatorTypes::Instruction) {s >> PIMemoryBlock(&v, sizeof(v) - sizeof(v.operators)) >> v.operators; return s;}
BINARY_STREAM_WRITE(PIEvaluatorTypes::Element) {s << createMemoryBlock(&v); return s;}
BINARY_STREAM_READ (PIEvaluatorTypes::Element) {s >> createMemoryBlock(&v); return s;}
BINARY_STREAM_WRITE(PIEvaluatorTypes::Variable) {s << v.name << v.value; return s;}
BINARY_STREAM_READ (PIEvaluatorTypes::Variable) {s >> v.name >> v.value; return s;}
BINARY_STREAM_WRITE(PIEvaluatorContent) {s << v.variables << v.cv_count; return s;}
BINARY_STREAM_READ (PIEvaluatorContent) {s >> v.variables >> v.cv_count; return s;}
#endif // PIEVALUATOR_H

View File

@@ -1172,9 +1172,9 @@ inline PICout operator<<(PICout s, const PIMathMatrix<Type> &m) {
* @param v PIMathMatrix type
* @return PIBiteArray serialized PIMathMatrix
*/
template<typename Type>
inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix<Type> &v) {
s << (const PIVector2D<Type> &) v;
template <typename P, typename T>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMathMatrix<T> & v) {
s << (const PIVector2D<T> &) v;
return s;
}
@@ -1185,9 +1185,9 @@ inline PIByteArray &operator<<(PIByteArray &s, const PIMathMatrix<Type> &v) {
* @param v PIMathMatrix type
* @return PIMathMatrix deserialized from PIByteArray
*/
template<typename Type>
inline PIByteArray &operator>>(PIByteArray &s, PIMathMatrix<Type> &v) {
s >> (PIVector2D<Type> &) v;
template <typename P, typename T>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIMathMatrix<T> & v) {
s >> (PIVector2D<T> &) v;
return s;
}

View File

@@ -258,8 +258,10 @@ typedef PIMathVectorT<4u, double> PIMathVectorT4d;
template<typename Type>
class PIP_EXPORT PIMathVector {
typedef PIMathVector<Type> _CVector;
template<typename TypeOp> friend PIByteArray & operator <<(PIByteArray & s, const PIMathVector<TypeOp> & v);
template<typename TypeOp> friend PIByteArray & operator >>(PIByteArray & s, PIMathVector<TypeOp> & v);
template <typename P, typename Type1>
friend PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMathVector<Type1> & v);
template <typename P, typename Type1>
friend PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIMathVector<Type1> & v);
public:
PIMathVector(const uint size = 0, const Type & new_value = Type()) {c.resize(size, new_value);}
PIMathVector(const PIVector<Type> & val) {c = val;}
@@ -510,10 +512,10 @@ inline std::ostream & operator <<(std::ostream & s, const PIMathVector<Type> & v
template<typename Type>
inline PICout operator <<(PICout s, const PIMathVector<Type> & v) {s << "Vector{"; for (uint i = 0; i < v.size(); ++i) {s << v[i]; if (i < v.size() - 1) s << ", ";} s << "}"; return s;}
template<typename Type>
inline PIByteArray & operator <<(PIByteArray & s, const PIMathVector<Type> & v) {s << v.c; return s;}
template<typename Type>
inline PIByteArray & operator >>(PIByteArray & s, PIMathVector<Type> & v) {s >> v.c; return s;}
template <typename P, typename T>
inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const PIMathVector<T> & v) {s << v.c; return s;}
template <typename P, typename T>
inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, PIMathVector<T> & v) {s >> v.c; return s;}
typedef PIMathVector<int> PIMathVectori;

View File

@@ -43,7 +43,7 @@ void PIResources::dump() {
auto fi = si.value()->entries.makeIterator();
while (fi.next()) {
PIString s = fi.key() + ": ";
s << (fi.value() ? fi.value()->size_s() : 0) << " b";
s += PIString::fromNumber(fi.value() ? fi.value()->size_s() : 0) + " b";
piCout << " " << s;
}
}

View File

@@ -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;
}

View File

@@ -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_WRITE(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_READ (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

View File

@@ -468,7 +468,7 @@ PIStringList PIPluginLoader::pluginsDirectories(const PIString & name) {
piForeachC (PIString d, dl) {
PIString dp = d + "/" + name;
if (PIDir::isExists(dp))
ret << dp;
ret += dp;
}
return ret;
}

View File

@@ -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;
}

View File

@@ -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_WRITE(PISystemMonitor::ProcessStats) {
s << PIMemoryBlock(&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_READ (PISystemMonitor::ProcessStats) {
s >> PIMemoryBlock(&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_WRITE(PISystemMonitor::ThreadStats) {
s << PIMemoryBlock(&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_READ (PISystemMonitor::ThreadStats) {
s >> PIMemoryBlock(&v, sizeof(PISystemMonitor::ThreadStatsFixed))
>> v.name;
return s;
}
#endif // PISYSTEMMONITOR_H