code clean
This commit is contained in:
@@ -401,3 +401,14 @@ PIByteArray & operator >>(PIByteArray & s, PIByteArray & v) {
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {
|
||||
s << int(v.size_s());
|
||||
int os = s.size_s();
|
||||
if (v.size_s() > 0) {
|
||||
s.enlarge(v.size_s());
|
||||
memcpy(s.data(os), v.data(), v.size());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -175,27 +175,18 @@ inline PIByteArray & operator <<(PIByteArray & s, const char v) {s.push_back(v);
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const uchar v) {s.push_back(v); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIChar & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
template<typename T> inline PIByteArray & operator <<(PIByteArray & s, const PIFlags<T> & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator for any trivial copyable type
|
||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const T & v) {int os = s.size_s(); s.enlarge(sizeof(v)); memcpy(s.data(os), &v, sizeof(v)); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v) {
|
||||
s << int(v.size_s());
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const T & v) {
|
||||
int os = s.size_s();
|
||||
if (v.size_s() > 0) {
|
||||
s.enlarge(v.size_s());
|
||||
memcpy(s.data(os), v.data(), v.size());
|
||||
}
|
||||
s.enlarge(sizeof(v));
|
||||
memcpy(s.data(os), &v, sizeof(v));
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
|
||||
PIP_EXPORT PIByteArray & operator <<(PIByteArray & s, const PIByteArray & v);
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator, see \ref PIByteArray_sec1 for details
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v) {
|
||||
int os = s.size_s();
|
||||
@@ -264,15 +255,14 @@ inline PIByteArray & operator >>(PIByteArray & s, char & v) {assert(s.size() >=
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
inline PIByteArray & operator >>(PIByteArray & s, uchar & v) {assert(s.size() >= 1u); v = s.take_front(); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIChar & v) {assert(s.size() >= sizeof(v)); memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator for any trivial copyable type
|
||||
template<typename T, typename std::enable_if< std::is_trivially_copyable<T>::value, int>::type = 0>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, T & v) {assert(s.size() >= sizeof(v)); memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
template<typename T> inline PIByteArray & operator >>(PIByteArray & s, PIFlags<T> & v) {memcpy((void*)(&v), s.data(), sizeof(v)); s.remove(0, sizeof(v)); return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, T & v) {
|
||||
assert(s.size() >= sizeof(v));
|
||||
memcpy((void*)(&v), s.data(), sizeof(v));
|
||||
s.remove(0, sizeof(v));
|
||||
return s;
|
||||
}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator, see \ref PIByteArray_sec1 for details
|
||||
PIP_EXPORT PIByteArray & operator >>(PIByteArray & s, PIByteArray & v);
|
||||
|
||||
@@ -32,8 +32,6 @@ extern PIP_EXPORT char * __utf8name__;
|
||||
class PIP_EXPORT PIChar
|
||||
{
|
||||
friend class PIString;
|
||||
friend PIByteArray & operator <<(PIByteArray & s, const PIChar & v);
|
||||
friend PIByteArray & operator >>(PIByteArray & s, PIChar & v);
|
||||
friend PICout PIP_EXPORT operator <<(PICout s, const PIChar & v);
|
||||
public:
|
||||
//! Contructs ascii symbol
|
||||
|
||||
@@ -38,8 +38,6 @@ public:
|
||||
PIFlags(): flags(0) {;}
|
||||
//! Constructor with flags = Enum "e"
|
||||
PIFlags(Enum e): flags(e) {;}
|
||||
//! Constructor with flags = PIFlags "f"
|
||||
PIFlags(const PIFlags & f): flags(f.flags) {;}
|
||||
//! Constructor with flags = int "i"
|
||||
PIFlags(const int i): flags(i) {;}
|
||||
//! Set flags "f" to value "on"
|
||||
@@ -49,8 +47,6 @@ public:
|
||||
//! Set flag "i" to value "on"
|
||||
PIFlags & setFlag(const int & i, bool on = true) {if (on) flags |= i; else flags &= ~i; return *this;}
|
||||
//! copy operator
|
||||
void operator =(const PIFlags & f) {flags = f.flags;}
|
||||
//! copy operator
|
||||
void operator =(const Enum & e) {flags = e;}
|
||||
//! copy operator
|
||||
void operator =(const int & i) {flags = i;}
|
||||
|
||||
@@ -60,8 +60,6 @@ public:
|
||||
//! Contructs system time with s = "s" and ns = "ns"
|
||||
PISystemTime(int s, int ns) {seconds = s; nanoseconds = ns; checkOverflows();}
|
||||
|
||||
//! Contructs system time from another
|
||||
PISystemTime(const PISystemTime & t) {seconds = t.seconds; nanoseconds = t.nanoseconds;}
|
||||
|
||||
//! Returns stored system time value in seconds
|
||||
double toSeconds() const {return double(seconds) + nanoseconds / 1.e+9;}
|
||||
@@ -172,13 +170,6 @@ private:
|
||||
//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout
|
||||
inline PICout operator <<(PICout s, const PISystemTime & v) {s.space(); s.setControl(0, true); s << "(" << v.seconds << " s, " << v.nanoseconds << " ns)"; s.restoreControl(); return s;}
|
||||
|
||||
//! \relatesalso PISystemTime \relatesalso PIByteArray \brief Output operator to PIByteArray
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PISystemTime & v) {s << v.seconds << v.nanoseconds; return s;}
|
||||
|
||||
//! \relatesalso PISystemTime \relatesalso PIByteArray \brief Input operator from PIByteArray
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PISystemTime & v) {s >> v.seconds >> v.nanoseconds; return s;}
|
||||
|
||||
|
||||
|
||||
|
||||
struct PIP_EXPORT PITime {
|
||||
@@ -199,8 +190,6 @@ PIP_EXPORT bool operator >(const PITime & t0, const PITime & t1);
|
||||
inline bool operator !=(const PITime & t0, const PITime & t1) {return !(t0 == t1);}
|
||||
inline bool operator <=(const PITime & t0, const PITime & t1) {return !(t0 > t1);}
|
||||
inline bool operator >=(const PITime & t0, const PITime & t1) {return !(t0 < t1);}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PITime & v) {s << v.hours << v.minutes << v.seconds << v.milliseconds; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PITime & v) {s >> v.hours >> v.minutes >> v.seconds >> v.milliseconds; return s;}
|
||||
|
||||
//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout
|
||||
PIP_EXPORT PICout operator <<(PICout s, const PITime & v);
|
||||
@@ -223,8 +212,6 @@ PIP_EXPORT bool operator >(const PIDate & t0, const PIDate & t1);
|
||||
inline bool operator !=(const PIDate & t0, const PIDate & t1) {return !(t0 == t1);}
|
||||
inline bool operator <=(const PIDate & t0, const PIDate & t1) {return !(t0 > t1);}
|
||||
inline bool operator >=(const PIDate & t0, const PIDate & t1) {return !(t0 < t1);}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIDate & v) {s << v.year << v.month << v.day; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIDate & v) {s >> v.year >> v.month >> v.day; return s;}
|
||||
|
||||
//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout
|
||||
PIP_EXPORT PICout operator <<(PICout s, const PIDate & v);
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
virtual void deleteT(void *& ptr) {;}
|
||||
//virtual PIByteArray toData(const void * ptr) const {return PIByteArray();}
|
||||
//virtual void fromData(void *& ptr, PIByteArray ba) {;}
|
||||
static PIMap<uint, __VariantFunctionsBase__*> & registered() {static PIMap<uint, __VariantFunctionsBase__*> ret; return ret;}
|
||||
//static PIMap<uint, __VariantFunctionsBase__*> & registered() {static PIMap<uint, __VariantFunctionsBase__*> ret; return ret;}
|
||||
};
|
||||
|
||||
|
||||
@@ -146,13 +146,13 @@ private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
#define REGISTER_PIVARIANTSIMPLE_STREAM(Type) \
|
||||
STATIC_INITIALIZER_BEGIN() \
|
||||
__VariantFunctionsBase__ * f = __VariantFunctions__<Type>().instance(); \
|
||||
__VariantFunctionsBase__::registered()[f->hash()] = f; \
|
||||
STATIC_INITIALIZER_END()
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif // PIVARIANTSIMPLE_H
|
||||
|
||||
@@ -65,8 +65,6 @@ public:
|
||||
//! \brief IPv4 network address, IP and port
|
||||
class PIP_EXPORT Address {
|
||||
friend class PIEthernet;
|
||||
friend inline PIByteArray & operator <<(PIByteArray & s, const PIEthernet::Address & v);
|
||||
friend inline PIByteArray & operator >>(PIByteArray & s, PIEthernet::Address & v);
|
||||
public:
|
||||
|
||||
//! Contructs %Address with binary representation of IP and port
|
||||
@@ -519,7 +517,5 @@ inline PICout operator <<(PICout s, const PIEthernet::Address & v) {s.space(); s
|
||||
|
||||
inline bool operator ==(const PIEthernet::Address & v0, const PIEthernet::Address & v1) {return (v0.ip() == v1.ip() && v0.port() == v1.port());}
|
||||
inline bool operator !=(const PIEthernet::Address & v0, const PIEthernet::Address & v1) {return (v0.ip() != v1.ip() || v0.port() != v1.port());}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIEthernet::Address & v) {s << v.ip_ << v.port_; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIEthernet::Address & v) {s >> v.ip_ >> v.port_; return s;}
|
||||
|
||||
#endif // PIETHERNET_H
|
||||
|
||||
@@ -59,12 +59,6 @@ public:
|
||||
template<typename Type>
|
||||
PICout operator <<(PICout & s, const PIPoint<Type> & v) {s.setControl(0, true); s << "Point{" << v.x << ", " << v.y << "}"; s.restoreControl(); return s;}
|
||||
|
||||
template<typename Type>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIPoint<Type> & v) {s << v.x << v.y; return s;}
|
||||
|
||||
template<typename Type>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIPoint<Type> & v) {s >> v.x >> v.y; return s;}
|
||||
|
||||
|
||||
typedef PIPoint<int> PIPointi;
|
||||
typedef PIPoint<uint> PIPointu;
|
||||
@@ -145,12 +139,6 @@ public:
|
||||
template<typename Type>
|
||||
PICout operator <<(PICout & s, const PIRect<Type> & v) {s.setControl(0, true); s << "Rect{" << v.x0 << ", " << v.y0 << "; " << v.x1 - v.x0 << ", " << v.y1 - v.y0 << "}"; s.restoreControl(); return s;}
|
||||
|
||||
template<typename Type>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIRect<Type> & v) {s << v.x0 << v.x1 << v.y0 << v.y1; return s;}
|
||||
|
||||
template<typename Type>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIRect<Type> & v) {s >> v.x0 >> v.x1 >> v.y0 >> v.y1; return s;}
|
||||
|
||||
|
||||
typedef PIRect<int> PIRecti;
|
||||
typedef PIRect<uint> PIRectu;
|
||||
|
||||
@@ -69,20 +69,6 @@ inline complexd log10(const complexd & c) {return log(c) / M_LN10;}
|
||||
template<typename T>
|
||||
inline PICout operator <<(PICout s, const complex<T> & v) {s.space(); s.setControl(0, true); s << "(" << v.real() << "; " << v.imag() << ")"; s.restoreControl(); return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
inline PIByteArray & operator <<(PIByteArray & s, complexf v) {float t; t = v.real(); s << t; t = v.imag(); s << t; return s;}
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
inline PIByteArray & operator <<(PIByteArray & s, complexd v) {double t; t = v.real(); s << t; t = v.imag(); s << t; return s;}
|
||||
//! \relatesalso PIByteArray \brief Store operator
|
||||
inline PIByteArray & operator <<(PIByteArray & s, complexld v) {ldouble t; t = v.real(); s << t; t = v.imag(); s << t; return s;}
|
||||
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
inline PIByteArray & operator >>(PIByteArray & s, complexf & v) {float t0, t1; s >> t0; s >> t1; v = complexf(t0, t1); return s;}
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
inline PIByteArray & operator >>(PIByteArray & s, complexd & v) {double t0, t1; s >> t0; s >> t1; v = complexd(t0, t1); return s;}
|
||||
//! \relatesalso PIByteArray \brief Restore operator
|
||||
inline PIByteArray & operator >>(PIByteArray & s, complexld & v) {ldouble t0, t1; s >> t0; s >> t1; v = complexld(t0, t1); return s;}
|
||||
|
||||
|
||||
inline PIVector<double> abs(const PIVector<complexd> & v) {
|
||||
PIVector<double> result;
|
||||
|
||||
@@ -125,10 +125,6 @@ inline PIMathVectorT<Size, Type> sqrt(const PIMathVectorT<Size, Type> & v) {PIMa
|
||||
template<uint Size, typename Type>
|
||||
inline PIMathVectorT<Size, Type> sqr(const PIMathVectorT<Size, Type> & v) {PIMathVectorT<Size, Type> ret; PIMV_FOR(i, 0) {ret[i] = sqr(v[i]);} return ret;}
|
||||
|
||||
template<uint Size, typename Type>
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s << v[i]; return s;}
|
||||
template<uint Size, typename Type>
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PIMathVectorT<Size, Type> & v) {for (uint i = 0; i < Size; ++i) s >> v[i]; return s;}
|
||||
|
||||
template<typename T>
|
||||
inline PIMathVectorT<2u, T> createVectorT2(T x, T y) {return PIMathVectorT<2u, T>(PIVector<T>() << x << y);}
|
||||
|
||||
14
main.cpp
14
main.cpp
@@ -74,6 +74,14 @@ inline PICout operator <<(PICout c, const SwitchChannel & v) {
|
||||
|
||||
int Acnt = 0;
|
||||
|
||||
struct MM {
|
||||
int x;
|
||||
double y;
|
||||
char c;
|
||||
PIPointd h;
|
||||
};
|
||||
|
||||
|
||||
class A {
|
||||
public:
|
||||
A() {moved = false; i = "constructor"; piCout << "A()"; ++Acnt;}
|
||||
@@ -86,10 +94,12 @@ public:
|
||||
A & operator =(A && a) {piSwap(i, a.i); a.moved = true; piCout << "= A&&)"; return *this;}
|
||||
PIString i;
|
||||
bool moved;
|
||||
MM m;
|
||||
static void F(int) {}
|
||||
};
|
||||
PIByteArray & operator <<(PIByteArray & ba, const A & v) {ba << v.i; return ba;}
|
||||
PIByteArray & operator >>(PIByteArray & ba, A & v) {ba >> v.i; return ba;}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & ba, const A & v) {ba << v.i << v.m; return ba;}
|
||||
inline PIByteArray & operator >>(PIByteArray & ba, A & v) {ba >> v.i >> v.m; return ba;}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
@@ -17,4 +17,3 @@ endmacro()
|
||||
# Concurrent tests
|
||||
pip_test(concurrent "")
|
||||
pip_test(math "")
|
||||
#pip_test(core "")
|
||||
|
||||
Reference in New Issue
Block a user