CSerializer.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * CSerializer.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. const std::string SAVEGAME_MAGIC = "VCMISVG";
  13. /// Helper to detect classes with user-provided serialize(S&, int version) method
  14. template<class S, class T>
  15. struct is_serializeable
  16. {
  17. using Yes = char (&)[1];
  18. using No = char (&)[2];
  19. template<class U>
  20. static Yes test(U * data, S* arg1 = nullptr, typename std::enable_if_t<std::is_void_v<decltype(data->serialize(*arg1))>> * = nullptr);
  21. static No test(...);
  22. static const bool value = sizeof(Yes) == sizeof(is_serializeable::test((typename std::remove_reference_t<typename std::remove_cv_t<T>>*)nullptr));
  23. };
  24. /// Base class for deserializers
  25. class IBinaryReader
  26. {
  27. public:
  28. virtual ~IBinaryReader() = default;
  29. virtual int read(std::byte * data, unsigned size) = 0;
  30. virtual void reportState(vstd::CLoggerBase * out){};
  31. };
  32. /// Base class for serializers
  33. class IBinaryWriter
  34. {
  35. public:
  36. virtual ~IBinaryWriter() = default;
  37. virtual int write(const std::byte * data, unsigned size) = 0;
  38. };
  39. VCMI_LIB_NAMESPACE_END