mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Fix and simplify game saving / loading
This commit is contained in:
@@ -10,31 +10,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "BinarySerializer.h"
|
||||
#include "CSerializer.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class DLL_LINKAGE CSaveFile : public IBinaryWriter
|
||||
class DLL_LINKAGE CSaveFile final : public IBinaryWriter
|
||||
{
|
||||
public:
|
||||
BinarySerializer serializer;
|
||||
|
||||
boost::filesystem::path fName;
|
||||
std::unique_ptr<std::fstream> sfile;
|
||||
std::fstream sfile;
|
||||
|
||||
CSaveFile(const boost::filesystem::path &fname); //throws!
|
||||
~CSaveFile();
|
||||
int write(const std::byte * data, unsigned size) override;
|
||||
int write(const std::byte * data, unsigned size) final;
|
||||
|
||||
void openNextFile(const boost::filesystem::path &fname); //throws!
|
||||
void clear();
|
||||
|
||||
void putMagicBytes(const std::string &text);
|
||||
public:
|
||||
explicit CSaveFile(const boost::filesystem::path & fname); //throws!
|
||||
|
||||
template<class T>
|
||||
CSaveFile & operator<<(const T &t)
|
||||
void save(const T & data)
|
||||
{
|
||||
serializer & t;
|
||||
return * this;
|
||||
static_assert(is_serializeable<BinarySerializer, T>::value, "This class can't be serialized (possible pointer?)");
|
||||
serializer & data;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user