aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/file.cpp6
-rw-r--r--common/file.h10
-rw-r--r--common/stream.cpp6
-rw-r--r--common/stream.h22
-rw-r--r--common/system.cpp4
-rw-r--r--common/system.h20
6 files changed, 47 insertions, 21 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 61485d30ca..f3241cdf6e 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -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;
diff --git a/common/file.h b/common/file.h
index 09928f132a..803d0d5905 100644
--- a/common/file.h
+++ b/common/file.h
@@ -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);
diff --git a/common/stream.cpp b/common/stream.cpp
index 7b5e1378fd..4f065d5d5d 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -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);
}
diff --git a/common/stream.h b/common/stream.h
index a1c634b8dc..b77adccbba 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -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
diff --git a/common/system.cpp b/common/system.cpp
index 9487052de1..4c25d132ec 100644
--- a/common/system.cpp
+++ b/common/system.cpp
@@ -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.
diff --git a/common/system.h b/common/system.h
index 8c672e18c9..39ff9b3d0d 100644
--- a/common/system.h
+++ b/common/system.h
@@ -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())