CSaveFile.h 819 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * CSaveFile.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. #include "BinarySerializer.h"
  12. #include "CSerializer.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class DLL_LINKAGE CSaveFile final : public IBinaryWriter
  15. {
  16. BinarySerializer serializer;
  17. boost::filesystem::path fName;
  18. std::fstream sfile;
  19. int write(const std::byte * data, unsigned size) final;
  20. public:
  21. explicit CSaveFile(const boost::filesystem::path & fname); //throws!
  22. template<class T>
  23. void save(const T & data)
  24. {
  25. static_assert(is_serializeable<BinarySerializer, T>::value, "This class can't be serialized (possible pointer?)");
  26. serializer & data;
  27. }
  28. };
  29. VCMI_LIB_NAMESPACE_END