GOB: Add a FakeFileHandler

For temporarily storing save "files"

svn-id: r55528
This commit is contained in:
Sven Hesse 2011-01-25 12:14:05 +00:00
parent ff13458eb7
commit 0432ca6d0f
2 changed files with 63 additions and 1 deletions

View File

@ -489,4 +489,48 @@ bool NotesHandler::save(int16 dataVar, int32 size, int32 offset) {
return writer.writePart(0, &vars);
}
FakeFileHandler::FakeFileHandler(GobEngine *vm) : SaveHandler(vm) {
}
FakeFileHandler::~FakeFileHandler() {
}
int32 FakeFileHandler::getSize() {
if (_data.empty())
return -1;
return _data.size();
}
bool FakeFileHandler::load(int16 dataVar, int32 size, int32 offset) {
if (size <= 0)
return false;
if ((uint32)(offset + size) > _data.size())
return false;
_vm->_inter->_variables->copyFrom(dataVar, &_data[0] + offset, size);
return true;
}
bool FakeFileHandler::save(int16 dataVar, int32 size, int32 offset) {
if (size <= 0)
return false;
if ((uint32)(offset + size) > _data.size())
_data.resize(offset + size);
_vm->_inter->_variables->copyTo(dataVar, &_data[0] + offset, size);
return true;
}
bool FakeFileHandler::deleteFile() {
_data.clear();
return true;
}
} // End of namespace Gob

View File

@ -27,7 +27,9 @@
#define GOB_SAVE_SAVEHANDLER_H
#include "common/savefile.h"
#include "engines/gob/video.h" // for SurfacePtr
#include "common/array.h"
#include "engines/gob/video.h" // for SurfacePtr
namespace Gob {
@ -180,6 +182,22 @@ private:
SavePartVars *_notes;
};
/** A handler that behaves like a file but keeps the contents in memory. */
class FakeFileHandler : public SaveHandler {
public:
FakeFileHandler(GobEngine *vm);
~FakeFileHandler();
int32 getSize();
bool load(int16 dataVar, int32 size, int32 offset);
bool save(int16 dataVar, int32 size, int32 offset);
bool deleteFile();
private:
Common::Array<byte> _data;
};
} // End of namespace Gob
#endif // GOB_SAVE_SAVEHANDLER_H