1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-27 22:47:48 +02:00
vcmi/lib/serializer/CSaveFile.h

38 lines
819 B
C++
Raw Normal View History

2023-11-11 00:39:08 +02:00
/*
* CSaveFile.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "BinarySerializer.h"
2025-04-12 21:25:23 +03:00
#include "CSerializer.h"
2023-11-11 00:39:08 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2025-04-12 21:25:23 +03:00
class DLL_LINKAGE CSaveFile final : public IBinaryWriter
2023-11-11 00:39:08 +02:00
{
BinarySerializer serializer;
boost::filesystem::path fName;
2025-04-12 21:25:23 +03:00
std::fstream sfile;
2023-11-11 00:39:08 +02:00
2025-04-12 21:25:23 +03:00
int write(const std::byte * data, unsigned size) final;
2023-11-11 00:39:08 +02:00
2025-04-12 21:25:23 +03:00
public:
explicit CSaveFile(const boost::filesystem::path & fname); //throws!
2023-11-11 00:39:08 +02:00
template<class T>
2025-04-12 21:25:23 +03:00
void save(const T & data)
2023-11-11 00:39:08 +02:00
{
2025-04-12 21:25:23 +03:00
static_assert(is_serializeable<BinarySerializer, T>::value, "This class can't be serialized (possible pointer?)");
serializer & data;
2023-11-11 00:39:08 +02:00
}
};
VCMI_LIB_NAMESPACE_END