#ifndef OPENMW_TEST_SUITE_SERIALIZATION_FORMAT_H #define OPENMW_TEST_SUITE_SERIALIZATION_FORMAT_H #include #include #include #include namespace SerializationTesting { struct Pod { int mInt = 42; double mDouble = 3.14; friend bool operator==(const Pod& l, const Pod& r) { const auto tuple = [](const Pod& v) { return std::tuple(v.mInt, v.mDouble); }; return tuple(l) == tuple(r); } }; enum Enum : std::int32_t { A, B, C, }; struct Composite { short mFloatArray[3] = { 0 }; std::vector mIntVector; std::vector mEnumVector; std::vector mPodVector; std::size_t mPodDataSize = 0; std::vector mPodBuffer; std::size_t mCharDataSize = 0; std::vector mCharBuffer; }; template struct TestFormat : Serialization::Format> { using Serialization::Format>::operator(); template auto operator()(Visitor&& visitor, T& value) const -> std::enable_if_t, Pod>> { visitor(*this, value.mInt); visitor(*this, value.mDouble); } template auto operator()(Visitor&& visitor, T& value) const -> std::enable_if_t, Composite>> { visitor(*this, value.mFloatArray); visitor(*this, value.mIntVector); visitor(*this, value.mEnumVector); visitor(*this, value.mPodVector); visitor(*this, value.mPodDataSize); if constexpr (mode == Serialization::Mode::Read) value.mPodBuffer.resize(value.mPodDataSize); visitor(*this, value.mPodBuffer.data(), value.mPodDataSize); visitor(*this, value.mCharDataSize); if constexpr (mode == Serialization::Mode::Read) value.mCharBuffer.resize(value.mCharDataSize); visitor(*this, value.mCharBuffer.data(), value.mCharDataSize); } }; } #endif