PIBinaryStream supports PISet

This commit is contained in:
2024-10-21 13:47:28 +03:00
parent 7209eec012
commit 7cd2f7a310
2 changed files with 45 additions and 0 deletions

View File

@@ -37,6 +37,10 @@
template<typename T> template<typename T>
class PISet: public PIMap<T, uchar> { class PISet: public PIMap<T, uchar> {
typedef PIMap<T, uchar> _CSet; typedef PIMap<T, uchar> _CSet;
template<typename P, typename T1>
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PISet<T1> & v);
template<typename P, typename T1>
friend PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PISet<T1> & v);
public: public:
//! Contructs an empty set //! Contructs an empty set

View File

@@ -29,6 +29,7 @@
#include "pibitarray.h" #include "pibitarray.h"
#include "pimap.h" #include "pimap.h"
#include "pimemoryblock.h" #include "pimemoryblock.h"
#include "piset.h"
#include "pivector2d.h" #include "pivector2d.h"
#define PIP_BINARY_STREAM #define PIP_BINARY_STREAM
@@ -655,6 +656,46 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIMap<Key, T> & v)
} }
//! \~english Store operator
//! \~russian Оператор сохранения
template<typename P, typename Key>
inline PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PISet<Key> & 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;
}
return s;
}
//! \~english Restore operator
//! \~russian Оператор извлечения
template<typename P, typename Key>
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PISet<Key> & v) {
int sz = s.binaryStreamTakeInt();
if (s.wasReadError()) {
fprintf(stderr, "error with PISet<%s>\n", __PIP_TYPENAME__(Key));
v.clear();
return s;
}
v.pim_index.resize(sz);
v.pim_content.resize(sz, 0);
int ind = 0;
for (int i = 0; i < sz; ++i) {
ind = s.binaryStreamTakeInt();
s >> v.pim_index[i].key;
if (s.wasReadError()) {
fprintf(stderr, "error with PISet<%s>\n", __PIP_TYPENAME__(Key));
v.clear();
return s;
}
v.pim_index[i].index = ind;
}
return s;
}
// non-defined complex types // non-defined complex types