Added new interface SeekableReadStream
svn-id: r16493
This commit is contained in:
parent
9c7a604c8b
commit
bc44b5ec15
6 changed files with 47 additions and 21 deletions
|
@ -201,7 +201,7 @@ void File::clearIOFailed() {
|
|||
_ioFailed = false;
|
||||
}
|
||||
|
||||
bool File::eof() {
|
||||
bool File::eof() const {
|
||||
if (_handle == NULL) {
|
||||
error("File::eof: File is not open!");
|
||||
return false;
|
||||
|
@ -210,7 +210,7 @@ bool File::eof() {
|
|||
return feof(_handle) != 0;
|
||||
}
|
||||
|
||||
uint32 File::pos() {
|
||||
uint32 File::pos() const {
|
||||
if (_handle == NULL) {
|
||||
error("File::pos: File is not open!");
|
||||
return 0;
|
||||
|
@ -219,7 +219,7 @@ uint32 File::pos() {
|
|||
return ftell(_handle);
|
||||
}
|
||||
|
||||
uint32 File::size() {
|
||||
uint32 File::size() const {
|
||||
if (_handle == NULL) {
|
||||
error("File::size: File is not open!");
|
||||
return 0;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "common/str.h"
|
||||
#include "common/stream.h"
|
||||
|
||||
class File : public Common::ReadStream, public Common::WriteStream {
|
||||
class File : public Common::SeekableReadStream, public Common::WriteStream {
|
||||
protected:
|
||||
/** POSIX file handle to the actual file; 0 if no file is open. */
|
||||
FILE *_handle;
|
||||
|
@ -66,11 +66,11 @@ public:
|
|||
bool isOpen() const;
|
||||
bool ioFailed() const;
|
||||
void clearIOFailed();
|
||||
virtual bool eof();
|
||||
virtual uint32 pos();
|
||||
virtual uint32 size();
|
||||
bool eof() const;
|
||||
uint32 pos() const;
|
||||
uint32 size() const;
|
||||
const char *name() const { return _name.c_str(); }
|
||||
virtual void seek(int32 offs, int whence = SEEK_SET);
|
||||
void seek(int32 offs, int whence = SEEK_SET);
|
||||
uint32 read(void *ptr, uint32 size);
|
||||
uint32 write(const void *ptr, uint32 size);
|
||||
char *gets(void *ptr, uint32 size);
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
namespace Common {
|
||||
|
||||
|
||||
void MemoryReadStream::seek(uint32 offs, int whence) {
|
||||
void MemoryReadStream::seek(int32 offs, int whence) {
|
||||
// Pre-Condition
|
||||
assert(_pos <= _bufSize);
|
||||
assert(0 <= _pos && _pos <= _bufSize);
|
||||
switch (whence) {
|
||||
case SEEK_END:
|
||||
// SEEK_END works just like SEEK_SET, only 'reversed',
|
||||
|
@ -45,7 +45,7 @@ void MemoryReadStream::seek(uint32 offs, int whence) {
|
|||
break;
|
||||
}
|
||||
// Post-Condition
|
||||
assert(_pos <= _bufSize);
|
||||
assert(0 <= _pos && _pos <= _bufSize);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -166,6 +166,24 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Interface for a seekable & readable data stream.
|
||||
*
|
||||
* @todo We really need better error handling here!
|
||||
* Like seek should somehow indicate whether it failed.
|
||||
*/
|
||||
class SeekableReadStream : public ReadStream {
|
||||
public:
|
||||
|
||||
virtual bool eof() const = 0;
|
||||
virtual uint32 pos() const = 0;
|
||||
virtual uint32 size() const = 0;
|
||||
|
||||
virtual void seek(int32 offs, int whence = SEEK_SET) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* XORReadStream is a wrapper around an arbitrary other ReadStream,
|
||||
* which 'decrypts' the data being read by XORing all data bytes with the given
|
||||
|
@ -200,7 +218,7 @@ public:
|
|||
* Simple memory based 'stream', which implements the ReadStream interface for
|
||||
* a plain memory block.
|
||||
*/
|
||||
class MemoryReadStream : public ReadStream {
|
||||
class MemoryReadStream : public SeekableReadStream {
|
||||
private:
|
||||
const byte *_ptr;
|
||||
const byte * const _ptrOrig;
|
||||
|
@ -223,7 +241,7 @@ public:
|
|||
uint32 pos() const { return _pos; }
|
||||
uint32 size() const { return _bufSize; }
|
||||
|
||||
void seek(uint32 offs, int whence = SEEK_SET);
|
||||
void seek(int32 offs, int whence = SEEK_SET);
|
||||
};
|
||||
|
||||
} // End of namespace Common
|
||||
|
|
|
@ -35,6 +35,10 @@ DECLARE_SINGLETON(OSystem);
|
|||
|
||||
template <>
|
||||
OSystem *Common::Singleton<OSystem>::makeInstance() {
|
||||
return OSystem::createSystem();
|
||||
}
|
||||
|
||||
OSystem *OSystem::createSystem() {
|
||||
// Attention: Do not call parseGraphicsMode() here, nor any other function
|
||||
// which needs to access the OSystem instance, else you get stuck in an
|
||||
// endless loop.
|
||||
|
|
|
@ -29,14 +29,6 @@
|
|||
#include "common/savefile.h"
|
||||
#include "common/singleton.h"
|
||||
|
||||
class OSystem;
|
||||
|
||||
/**
|
||||
* Custom object factory for OSystem.
|
||||
*/
|
||||
template <>
|
||||
OSystem *Common::Singleton<OSystem>::makeInstance();
|
||||
|
||||
|
||||
/**
|
||||
* Interface for ScummVM backends. If you want to port ScummVM to a system
|
||||
|
@ -49,6 +41,10 @@ OSystem *Common::Singleton<OSystem>::makeInstance();
|
|||
* control audio CD playback, and sound output.
|
||||
*/
|
||||
class OSystem : public Common::Singleton<OSystem> {
|
||||
protected:
|
||||
static OSystem *createSystem();
|
||||
friend class Common::Singleton<SingletonBaseType>;
|
||||
|
||||
public:
|
||||
|
||||
/** @name Feature flags */
|
||||
|
@ -682,6 +678,14 @@ public:
|
|||
//@}
|
||||
};
|
||||
|
||||
/**
|
||||
* Custom object factory for OSystem.
|
||||
*/
|
||||
template <>
|
||||
OSystem *Common::Singleton<OSystem>::makeInstance();
|
||||
|
||||
|
||||
|
||||
/** The global OSystem instance. Inited in main(). */
|
||||
#define g_system (&OSystem::instance())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue