Moved the OutSaveFile::finalize method to WriteStream; implemented DumpFile::flush()

svn-id: r33604
This commit is contained in:
Max Horn 2008-08-04 11:30:47 +00:00
parent 3f180a4c3f
commit 99f546caad
4 changed files with 29 additions and 15 deletions

View File

@ -553,5 +553,12 @@ uint32 DumpFile::write(const void *ptr, uint32 len) {
return (uint32)fwrite(ptr, 1, len, (FILE *)_handle);
}
void DumpFile::flush() {
assert(_handle);
// TODO: Should check the return value of fflush, and if it is non-zero,
// check errno and set an error flag.
fflush((FILE *)_handle);
}
} // End of namespace Common

View File

@ -148,7 +148,9 @@ public:
*/
virtual bool eof() const;
uint32 write(const void *dataPtr, uint32 dataSize);
virtual uint32 write(const void *dataPtr, uint32 dataSize);
virtual void flush();
};

View File

@ -39,6 +39,7 @@ namespace Common {
* That typically means "save games", but also includes things like the
* IQ points in Indy3.
*/
//typedef SeekableReadStream InSaveFile;
class InSaveFile : public SeekableReadStream {};
/**
@ -46,20 +47,8 @@ class InSaveFile : public SeekableReadStream {};
* That typically means "save games", but also includes things like the
* IQ points in Indy3.
*/
class OutSaveFile : public WriteStream {
public:
/**
* Close this savefile, to be called right before destruction of this
* savefile. The idea is that this ways, I/O errors that occur
* during closing/flushing of the file can still be handled by the
* game engine.
*
* By default, this just flushes the stream.
*/
virtual void finalize() {
flush();
}
};
//typedef WriteStream OutSaveFile;
class OutSaveFile : public WriteStream {};
/**

View File

@ -78,6 +78,22 @@ public:
*/
virtual void flush() {}
/**
* Finalize and close this stream. To be called right before this
* stream instance is deleted. The goal here is to enable calling
* code to detect and handle I/O errors which might occur when
* closing (and this flushing, if buffered) the stream.
*
* After this method has been called, no further writes may be
* peformed on the stream. Calling ioFailed() is allowed.
*
* By default, this just flushes the stream.
*/
virtual void finalize() {
flush();
}
// The remaining methods all have default implementations; subclasses
// need not (and should not) overload them.