1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

* started making support for save/load options

This commit is contained in:
Michał W. Urbańczyk
2008-11-16 01:06:15 +00:00
parent bb5819f4df
commit 333e1d9878
12 changed files with 485 additions and 278 deletions

View File

@ -3,6 +3,7 @@
#include "Connection.h"
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <fstream>
using namespace boost;
using namespace boost::asio::ip;
@ -143,18 +144,24 @@ void CConnection::close()
socket = NULL;
}
}
template <>
void CConnection::saveSerializable<std::string>(const std::string &data)
CSaveFile::CSaveFile( const std::string &fname )
:sfile(new std::ofstream(fname.c_str()))
{
*this << ui32(data.size());
write(data.c_str(),data.size());
if(!(*sfile))
{
tlog1 << "Error: cannot open to write " << fname << std::endl;
sfile = NULL;
}
}
template <>
void CConnection::loadSerializable<std::string>(std::string &data)
CSaveFile::~CSaveFile()
{
ui32 l;
*this >> l;
data.resize(l);
read((void*)data.c_str(),l);
delete sfile;
}
int CSaveFile::write( const void * data, unsigned size )
{
sfile->write((char *)data,size);
return size;
}