diff --git a/libs/main/console/piscreentypes.h b/libs/main/console/piscreentypes.h index 05335ed1..cce0e6fd 100644 --- a/libs/main/console/piscreentypes.h +++ b/libs/main/console/piscreentypes.h @@ -140,8 +140,10 @@ namespace PIScreenTypes { inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::Cell & v) {s << v.format.raw_format << v.symbol; return s;} - inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::Cell & v) {s >> v.format.raw_format >> v.symbol; return s;} +inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::TileEvent & v) {s << v.type << v.data; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::TileEvent & v) {s >> v.type >> v.data; return s;} + #endif // PISCREENTYPES_H diff --git a/libs/main/core/pibytearray.h b/libs/main/core/pibytearray.h index ad00a8a1..dfeeab5d 100644 --- a/libs/main/core/pibytearray.h +++ b/libs/main/core/pibytearray.h @@ -197,8 +197,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIByteArray::RawData & v return s; } -//! \relatesalso PIByteArray \brief Store operator for PIVector of any trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Store operator for PIVector of any fundamental type +template::value, int>::type = 0> inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) { s << int(v.size_s()); int os = s.size_s(); @@ -209,8 +209,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) { return s; } -//! \relatesalso PIByteArray \brief Store operator for PIDeque of any trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Store operator for PIDeque of any fundamental type +template::value, int>::type = 0> inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) { s << int(v.size_s()); int os = s.size_s(); @@ -221,8 +221,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) { return s; } -//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any fundamental type +template::value, int>::type = 0> inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) { s << int(v.rows()) << int(v.cols()); int os = s.size_s(); @@ -277,8 +277,8 @@ inline PIByteArray & operator >>(PIByteArray & s, PIByteArray::RawData v) { return s; } -//! \relatesalso PIByteArray \brief Restore operator for PIVector of any trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Restore operator for PIVector of any fundamental type +template::value, int>::type = 0> inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { assert(s.size_s() >= 4); int sz; s >> sz; @@ -290,8 +290,8 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { return s; } -//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any fundamental type +template::value, int>::type = 0> inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { assert(s.size_s() >= 4); int sz; s >> sz; @@ -303,8 +303,8 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { return s; } -//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any fundamental type +template::value, int>::type = 0> inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) { assert(s.size_s() >= 8); int r, c; s >> r >> c; @@ -330,24 +330,24 @@ inline PIByteArray & operator >>(PIByteArray & s, PIPair & v) {s > // store operators for complex types -//! \relatesalso PIByteArray \brief Store operator for PIVector of any non-trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Store operator for PIVector of any compound type +template::value, int>::type = 0> inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) { s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s; } -//! \relatesalso PIByteArray \brief Store operator for PIDeque of any non-trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Store operator for PIDeque of any compound type +template::value, int>::type = 0> inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) { s << int(v.size_s()); for (uint i = 0; i < v.size(); ++i) s << v[i]; return s; } -//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any non-trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Store operator for PIVector2D of any compound type +template::value, int>::type = 0> inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) { s << int(v.rows()) << int(v.cols()) << v.toPlainVector(); return s; @@ -359,8 +359,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) { // restore operators for complex types -//! \relatesalso PIByteArray \brief Restore operator for PIVector of any non-trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Restore operator for PIVector of any compound type +template::value, int>::type = 0> inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { assert(s.size_s() >= 4); int sz; s >> sz; @@ -369,8 +369,8 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) { return s; } -//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any non-trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Restore operator for PIDeque of any compound type +template::value, int>::type = 0> inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { assert(s.size_s() >= 4); int sz; s >> sz; @@ -379,8 +379,8 @@ inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) { return s; } -//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any non-trivial copyable type -template::value, int>::type = 0> +//! \relatesalso PIByteArray \brief Restore operator for PIVector2D of any compound type +template::value, int>::type = 0> inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) { assert(s.size_s() >= 8); int r,c; diff --git a/libs/main/core/pivariantsimple.h b/libs/main/core/pivariantsimple.h index 017872c2..63130902 100644 --- a/libs/main/core/pivariantsimple.h +++ b/libs/main/core/pivariantsimple.h @@ -159,10 +159,10 @@ private: /* #define REGISTER_PIVARIANTSIMPLE_STREAM(Type) \ - STATIC_INITIALIZER_BEGIN() \ + STATIC_INITIALIZER_BEGIN \ __VariantFunctionsBase__ * f = __VariantFunctions__().instance(); \ __VariantFunctionsBase__::registered()[f->hash()] = f; \ - STATIC_INITIALIZER_END() + STATIC_INITIALIZER_END */ diff --git a/main.cpp b/main.cpp index 732d268d..96806c39 100644 --- a/main.cpp +++ b/main.cpp @@ -2,85 +2,22 @@ #include "pivariantsimple.h" -template -struct __VariantTypeInfo__ { - typedef T PureType; - typedef const T ConstPureType; - typedef T * PointerType; - typedef const T * ConstPointerType; - typedef T & ReferenceType; - typedef const T & ConstReferenceType; -}; - -#define __TYPEINFO_SINGLE(PT, T) \ - template<> struct __PIVariantTypeInfo__ { \ - typedef PT PureType; \ - typedef const PT ConstPureType; \ - typedef PT * PointerType; \ - typedef const PT * ConstPointerType; \ - typedef PT & ReferenceType; \ - typedef const PT & ConstReferenceType; \ - }; - -#define REGISTER_VARIANT_TYPEINFO(T) \ - __TYPEINFO_SINGLE(T, T &) \ - __TYPEINFO_SINGLE(T, const T) \ - __TYPEINFO_SINGLE(T, const T &) - - - -struct SwitchChannel { - SwitchChannel(bool on_ = true, float dur_ = 10.f, int m_count = 0, short unrely = -1) { - on = on_ ? 1 : 0; - duration = dur_; - max_count = m_count; - overload[0] = overload[1] = false; - unreliability = unrely; - } - uchar on; - short unreliability; - float duration; - int max_count; - bool overload[2]; -}; -/* -inline PIByteArray & operator <<(PIByteArray & ba, const SwitchChannel & v) { - PIChunkStream cs; - cs << cs.chunk(1, v.on) - << cs.chunk(2, v.duration) - << cs.chunk(3, v.max_count) - << cs.chunk(4, v.unreliability); - ba << cs.data(); - return ba; -} -inline PIByteArray & operator >>(PIByteArray & ba, SwitchChannel & v) { - PIByteArray src; ba >> src; PIChunkStream cs(src); - while (!cs.atEnd()) { - switch (cs.read()) { - case 1: cs.get(v.on); break; - case 2: cs.get(v.duration); break; - case 3: cs.get(v.max_count); break; - case 4: cs.get(v.unreliability); break; - } - } - return ba; -}*/ -inline PICout operator <<(PICout c, const SwitchChannel & v) { - c << v.on << v.duration << v.max_count << v.unreliability; - return c; -} - - - -int Acnt = 0; - +#pragma pack(push, 1) struct MM { int x; + int x2; double y; - char c; - PIPointd h; + char c[16]; + int e2; + int e; + //PIPointd h; }; +#pragma pack(pop) +inline PIByteArray & operator <<(PIByteArray & ba, const MM & v) {piCout << "xep1"; ba << v.x << v.y << v.c; return ba;} +inline PIByteArray & operator >>(PIByteArray & ba, MM & v) {piCout << "xep2"; ba >> v.x >> v.y >> v.c; return ba;} + +int Acnt = 0; class A { public: @@ -102,8 +39,59 @@ inline PIByteArray & operator <<(PIByteArray & ba, const A & v) {ba << v.i << v. inline PIByteArray & operator >>(PIByteArray & ba, A & v) {ba >> v.i >> v.m; return ba;} -int main() { - A a; - PIByteArray ba; - ba >> a; +/* +class HelperBase { +public: + virtual void bsl(PIByteArray & ba, void * o) = 0; +}; + + +template +class Helper : public HelperBase { +public: +void bsl(PIByteArray & ba, void * o) override { + ba << (*(X*)o); + piCout << ba.size(); + ba >> (*(X*)o); + piCout << ba.size(); } +}; + + +class TypeHelper { +public: + HelperBase * h; + template inline void regtype() { + h = new Helper(); + } +}; +*/ + + +int main() { + PIByteArray ba; +// TypeHelper th; +// th.regtype(); + MM m; + PIVector vm; + vm << m;; + ba << m; + piCout << ba.toHex(); + ba.clear(); + piCout << "==="; + ba << vm; + piCout << ba.toHex(); +// th.h->bsl(ba, &m); +// th.regtype(); +// CAN_Raw c; +// th.h->bsl(ba, &c); +// PIVariantSimple v; +// v.setValue(m); +// ba = v.save(); +// piCout << ba.toHex(); +// PIVariantSimple v2; +// v2.load(ba); +// piCout << v2.save().toHex(); + return 0; +} + diff --git a/tests/concurrent/testutil.h b/tests/concurrent/testutil.h index 7c3c15c7..2966862f 100644 --- a/tests/concurrent/testutil.h +++ b/tests/concurrent/testutil.h @@ -8,7 +8,7 @@ * Minimum wait thread start, switch context or another interthread communication action time. Increase it if tests * write "Start thread timeout reach!" message. You can reduce it if you want increase test performance. */ -const int WAIT_THREAD_TIME_MS = 40; +const int WAIT_THREAD_TIME_MS = 400; const int THREAD_COUNT = 5;