[Scummvm-cvs-logs] CVS: scummvm/common savefile.cpp,1.15,1.16 savefile.h,1.14,1.15
Max Horn
fingolfin at users.sourceforge.net
Sun Apr 10 08:14:59 CEST 2005
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2778/common
Modified Files:
savefile.cpp savefile.h
Log Message:
split SaveFileManager::openSavefile and class SaveFile into two, each, one for loading and one for saving
Index: savefile.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/savefile.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- savefile.cpp 1 Jan 2005 16:08:49 -0000 1.15
+++ savefile.cpp 10 Apr 2005 15:13:36 -0000 1.16
@@ -134,15 +134,16 @@
strncat(buf, filename, bufsize-1);
}
-SaveFile *DefaultSaveFileManager::openSavefile(const char *filename, bool saveOrLoad) {
+OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) {
char buf[256];
join_paths(filename, getSavePath(), buf, sizeof(buf));
- SaveFile *sf = makeSaveFile(buf, saveOrLoad);
- if (!sf->isOpen()) {
- delete sf;
- sf = 0;
- }
- return sf;
+ return makeSaveFile(buf, true);
+}
+
+InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) {
+ char buf[256];
+ join_paths(filename, getSavePath(), buf, sizeof(buf));
+ return makeSaveFile(buf, false);
}
void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) {
@@ -151,8 +152,13 @@
SaveFile *DefaultSaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) {
#ifdef USE_ZLIB
- return new GzipSaveFile(filename, saveOrLoad);
+ GzipSaveFile *sf = new GzipSaveFile(filename, saveOrLoad);
#else
- return new StdioSaveFile(filename, saveOrLoad);
+ StdioSaveFile *sf = new StdioSaveFile(filename, saveOrLoad);
#endif
+ if (!sf->isOpen()) {
+ delete sf;
+ sf = 0;
+ }
+ return sf;
}
Index: savefile.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/savefile.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- savefile.h 9 Jan 2005 16:07:53 -0000 1.14
+++ savefile.h 10 Apr 2005 15:13:37 -0000 1.15
@@ -27,11 +27,38 @@
#include "common/stream.h"
-class SaveFile : public Common::ReadStream, public Common::WriteStream {
+/**
+ * A class which allows game engines to load game state data.
+ * That typically means "save games", but also includes things like the
+ * IQ points in Indy3.
+ *
+ * @todo Add error checking abilities.
+ * @todo Change base class to SeekableReadStream; or alternatively,
+ * add a simple 'skip()' method which would allow skipping
+ * a number of bytes in the savefile.
+ */
+class InSaveFile : public Common::ReadStream {
public:
- virtual ~SaveFile() {}
+ virtual ~InSaveFile() {}
+};
- virtual bool isOpen() const = 0;
+/**
+ * A class which allows game engines to save game state data.
+ * That typically means "save games", but also includes things like the
+ * IQ points in Indy3.
+ *
+ * @todo Add error checking abilities.
+ */
+class OutSaveFile : public Common::WriteStream {
+public:
+ virtual ~OutSaveFile() {}
+};
+
+/**
+ * Convenience intermediate class, to be removed.
+ */
+class SaveFile : public InSaveFile, public OutSaveFile {
+public:
};
class SaveFileManager {
@@ -40,13 +67,19 @@
virtual ~SaveFileManager() {}
/**
- * Open the file with name filename in the given directory for saving or loading.
+ * Open the file with name filename in the given directory for saving.
* @param filename the filename
- * @param directory the directory
- * @param saveOrLoad true for saving, false for loading
- * @return pointer to a SaveFile object
+ * @return pointer to a SaveFile object, or NULL if an error occured.
*/
- virtual SaveFile *openSavefile(const char *filename, bool saveOrLoad) = 0;
+ virtual OutSaveFile *openForSaving(const char *filename) = 0;
+
+ /**
+ * Open the file with name filename in the given directory for loading.
+ * @param filename the filename
+ * @return pointer to a SaveFile object, or NULL if an error occured.
+ */
+ virtual InSaveFile *openForLoading(const char *filename) = 0;
+
virtual void listSavefiles(const char * /* prefix */, bool *marks, int num) = 0;
/** Get the path to the save game directory. */
@@ -55,11 +88,12 @@
class DefaultSaveFileManager : public SaveFileManager {
public:
- virtual SaveFile *openSavefile(const char *filename, bool saveOrLoad);
+ virtual OutSaveFile *openForSaving(const char *filename);
+ virtual InSaveFile *openForLoading(const char *filename);
virtual void listSavefiles(const char * /* prefix */, bool *marks, int num);
protected:
- virtual SaveFile *makeSaveFile(const char *filename, bool saveOrLoad);
+ SaveFile *makeSaveFile(const char *filename, bool saveOrLoad);
};
#endif
More information about the Scummvm-git-logs
mailing list