diff options
author | Max Horn | 2008-09-13 16:51:46 +0000 |
---|---|---|
committer | Max Horn | 2008-09-13 16:51:46 +0000 |
commit | 655ce26b3f09628d9408a4d82efe3a26116999fe (patch) | |
tree | 779a25dbe25c8f916fb385b3dd2d48e0e379d9ec /common | |
parent | b86a047164b54c20366fcbe21b55bf63f2ced5f4 (diff) | |
download | scummvm-rg350-655ce26b3f09628d9408a4d82efe3a26116999fe.tar.gz scummvm-rg350-655ce26b3f09628d9408a4d82efe3a26116999fe.tar.bz2 scummvm-rg350-655ce26b3f09628d9408a4d82efe3a26116999fe.zip |
Big patch changing the signature of various Stream methods (some ports may need to be slightly tweaked to fix overloading errors/warnings)
svn-id: r34514
Diffstat (limited to 'common')
-rw-r--r-- | common/file.cpp | 28 | ||||
-rw-r--r-- | common/file.h | 8 | ||||
-rw-r--r-- | common/stream.cpp | 12 | ||||
-rw-r--r-- | common/stream.h | 66 | ||||
-rw-r--r-- | common/unarj.cpp | 8 | ||||
-rw-r--r-- | common/unarj.h | 6 |
6 files changed, 75 insertions, 53 deletions
diff --git a/common/file.cpp b/common/file.cpp index ba94cb285a..1297775f15 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -113,13 +113,7 @@ bool File::open(const FilesystemNode &node) { } else if (node.isDirectory()) { warning("File::open: Trying to open a FilesystemNode which is a directory"); return false; - } /*else if (!node.isReadable() && mode == kFileReadMode) { - warning("File::open: Trying to open an unreadable FilesystemNode object for reading"); - return false; - } else if (!node.isWritable() && mode == kFileWriteMode) { - warning("File::open: Trying to open an unwritable FilesystemNode object for writing"); - return false; - }*/ + } String filename(node.getName()); @@ -181,19 +175,19 @@ bool File::eos() const { return _handle->eos(); } -uint32 File::pos() const { +int32 File::pos() const { assert(_handle); return _handle->pos(); } -uint32 File::size() const { +int32 File::size() const { assert(_handle); return _handle->size(); } -void File::seek(int32 offs, int whence) { +bool File::seek(int32 offs, int whence) { assert(_handle); - _handle->seek(offs, whence); + return _handle->seek(offs, whence); } uint32 File::read(void *ptr, uint32 len) { @@ -223,13 +217,7 @@ bool DumpFile::open(const FilesystemNode &node) { if (node.isDirectory()) { warning("File::open: Trying to open a FilesystemNode which is a directory"); return false; - } /*else if (!node.isReadable() && mode == kFileReadMode) { - warning("File::open: Trying to open an unreadable FilesystemNode object for reading"); - return false; - } else if (!node.isWritable() && mode == kFileWriteMode) { - warning("File::open: Trying to open an unwritable FilesystemNode object for writing"); - return false; - }*/ + } _handle = node.openForWriting(); @@ -263,9 +251,9 @@ uint32 DumpFile::write(const void *ptr, uint32 len) { return _handle->write(ptr, len); } -void DumpFile::flush() { +bool DumpFile::flush() { assert(_handle); - _handle->flush(); + return _handle->flush(); } } // End of namespace Common diff --git a/common/file.h b/common/file.h index 4b7674584d..b4cadd7256 100644 --- a/common/file.h +++ b/common/file.h @@ -92,9 +92,9 @@ public: void clearIOFailed(); bool eos() const; - virtual uint32 pos() const; - virtual uint32 size() const; - void seek(int32 offs, int whence = SEEK_SET); + virtual int32 pos() const; + virtual int32 size() const; + bool seek(int32 offs, int whence = SEEK_SET); uint32 read(void *dataPtr, uint32 dataSize); }; @@ -132,7 +132,7 @@ public: virtual uint32 write(const void *dataPtr, uint32 dataSize); - virtual void flush(); + virtual bool flush(); }; } // End of namespace Common diff --git a/common/stream.cpp b/common/stream.cpp index d866fe0b5a..1ddaa17575 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -60,7 +60,7 @@ uint32 MemoryReadStream::read(void *dataPtr, uint32 dataSize) { return dataSize; } -void MemoryReadStream::seek(int32 offs, int whence) { +bool MemoryReadStream::seek(int32 offs, int whence) { // Pre-Condition assert(_pos <= _size); switch (whence) { @@ -81,6 +81,8 @@ void MemoryReadStream::seek(int32 offs, int whence) { } // Post-Condition assert(_pos <= _size); + + return true; // FIXME: STREAM REWRITE } #define LF 0x0A @@ -241,7 +243,7 @@ SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, u _parentStream->seek(_pos); } -void SeekableSubReadStream::seek(int32 offset, int whence) { +bool SeekableSubReadStream::seek(int32 offset, int whence) { assert(_pos >= _begin); assert(_pos <= _end); @@ -259,7 +261,7 @@ void SeekableSubReadStream::seek(int32 offset, int whence) { assert(_pos >= _begin); assert(_pos <= _end); - _parentStream->seek(_pos); + return _parentStream->seek(_pos); } BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, bool disposeParentStream) @@ -324,7 +326,7 @@ BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *paren _parentStream(parentStream) { } -void BufferedSeekableReadStream::seek(int32 offset, int whence) { +bool BufferedSeekableReadStream::seek(int32 offset, int whence) { // If it is a "local" seek, we may get away with "seeking" around // in the buffer only. // Note: We could try to handle SEEK_END and SEEK_SET, too, but @@ -339,6 +341,8 @@ void BufferedSeekableReadStream::seek(int32 offset, int whence) { _pos = _bufSize; _parentStream->seek(offset, whence); } + + return true; // FIXME: STREAM REWRITE } } // End of namespace Common diff --git a/common/stream.h b/common/stream.h index babb00e706..de7f1fedf6 100644 --- a/common/stream.h +++ b/common/stream.h @@ -75,8 +75,10 @@ public: * Commit any buffered data to the underlying channel or * storage medium; unbuffered streams can use the default * implementation. + * + * @return true on success, false in case of a failure */ - virtual void flush() {} + virtual bool flush() { return true; } /** * Finalize and close this stream. To be called right before this @@ -85,7 +87,7 @@ public: * 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. + * performed on the stream. Calling ioFailed() is allowed. * * By default, this just flushes the stream. */ @@ -303,18 +305,46 @@ public: /** * Interface for a seekable & readable data stream. * - * @todo We really need better error handling here! - * Like seek should somehow indicate whether it failed. + * @todo Get rid of SEEK_SET, SEEK_CUR, or SEEK_END, use our own constants */ class SeekableReadStream : virtual public ReadStream { public: - virtual uint32 pos() const = 0; - virtual uint32 size() const = 0; + /** + * Obtains the current value of the stream position indicator of the + * stream. + * + * @return the current position indicator, or -1 if an error occurred. + */ + virtual int32 pos() const = 0; - virtual void seek(int32 offset, int whence = SEEK_SET) = 0; + /** + * Obtains the total size of the stream, measured in bytes. + * If this value is unknown or can not be computed, -1 is returned. + * + * @return the size of the stream, or -1 if an error occurred + */ + virtual int32 size() const = 0; - void skip(uint32 offset) { seek(offset, SEEK_CUR); } + /** + * Sets the stream position indicator for the stream. The new position, + * measured in bytes, is obtained by adding offset bytes to the position + * specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or + * SEEK_END, the offset is relative to the start of the file, the current + * position indicator, or end-of-file, respectively. A successful call + * to the seek() method clears the end-of-file indicator for the stream. + * + * @param offset the relative offset in bytes + * @param whence the seek reference: SEEK_SET, SEEK_CUR, or SEEK_END + * @return true on success, false in case of a failure + */ + virtual bool seek(int32 offset, int whence = SEEK_SET) = 0; + + /** + * TODO: Get rid of this??? Or keep it and document it + * @return true on success, false in case of a failure + */ + virtual bool skip(uint32 offset) { return seek(offset, SEEK_CUR); } /** * DEPRECATED: Do not use this method! Instead use readLine_NEW() or readline(). @@ -401,10 +431,10 @@ protected: public: SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream = false); - virtual uint32 pos() const { return _pos - _begin; } - virtual uint32 size() const { return _end - _begin; } + virtual int32 pos() const { return _pos - _begin; } + virtual int32 size() const { return _end - _begin; } - virtual void seek(int32 offset, int whence = SEEK_SET); + virtual bool seek(int32 offset, int whence = SEEK_SET); }; /** @@ -471,10 +501,10 @@ protected: public: BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, bool disposeParentStream = false); - virtual uint32 pos() const { return _parentStream->pos() - (_bufSize - _pos); } - virtual uint32 size() const { return _parentStream->size(); } + virtual int32 pos() const { return _parentStream->pos() - (_bufSize - _pos); } + virtual int32 size() const { return _parentStream->size(); } - virtual void seek(int32 offset, int whence = SEEK_SET); + virtual bool seek(int32 offset, int whence = SEEK_SET); }; @@ -516,11 +546,11 @@ public: uint32 read(void *dataPtr, uint32 dataSize); - bool eos() const { return _pos == _size; } - uint32 pos() const { return _pos; } - uint32 size() const { return _size; } + bool eos() const { return _pos == _size; } // FIXME: Wrong + int32 pos() const { return _pos; } + int32 size() const { return _size; } - void seek(int32 offs, int whence = SEEK_SET); + bool seek(int32 offs, int whence = SEEK_SET); }; diff --git a/common/unarj.cpp b/common/unarj.cpp index 9a7766a41f..13ff0fd673 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -320,16 +320,16 @@ bool ArjFile::eos() { return _uncompressed->eos(); } -uint32 ArjFile::pos() { +int32 ArjFile::pos() { return _uncompressed->pos(); } -uint32 ArjFile::size() { +int32 ArjFile::size() { return _uncompressed->size(); } -void ArjFile::seek(int32 offset, int whence) { - _uncompressed->seek(offset, whence); +bool ArjFile::seek(int32 offset, int whence) { + return _uncompressed->seek(offset, whence); } void ArjFile::init_getbits() { diff --git a/common/unarj.h b/common/unarj.h index c8965968f6..bc9575fdc2 100644 --- a/common/unarj.h +++ b/common/unarj.h @@ -115,9 +115,9 @@ public: uint32 read(void *dataPtr, uint32 dataSize); bool eos(); - uint32 pos(); - uint32 size(); - void seek(int32 offset, int whence = SEEK_SET); + int32 pos(); + int32 size(); + bool seek(int32 offset, int whence = SEEK_SET); bool isOpen() { return _isOpen; } private: |