[Scummvm-cvs-logs] CVS: scummvm/common system.cpp,1.11,1.12 system.h,1.67,1.68 savefile.h,1.10,1.11 savefile.cpp,1.10,1.11

Max Horn fingolfin at users.sourceforge.net
Fri Jun 25 15:12:04 CEST 2004


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8728/common

Modified Files:
	system.cpp system.h savefile.h savefile.cpp 
Log Message:
Cleaned up SaveFileManager stuff a little bit

Index: system.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/system.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- system.cpp	21 May 2004 20:43:07 -0000	1.11
+++ system.cpp	25 Jun 2004 22:11:47 -0000	1.12
@@ -92,6 +92,9 @@
 	dialog.runModal();
 }
 
+SaveFileManager *OSystem::get_savefile_manager() {
+	return new DefaultSaveFileManager();
+}
 
 #pragma mark -
 

Index: system.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/system.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- system.h	5 May 2004 02:32:46 -0000	1.67
+++ system.h	25 Jun 2004 22:11:47 -0000	1.68
@@ -24,10 +24,9 @@
 #define COMMON_SYSTEM_H
 
 #include "common/scummsys.h"
-#include "common/savefile.h"
 #include "common/util.h"
 #include "common/rect.h"
-
+#include "common/savefile.h"
 
 /**
  * Interface for ScummVM backends. If you want to port ScummVM to a system
@@ -623,9 +622,7 @@
 	virtual void displayMessageOnOSD(const char *msg);
 
 	/** Savefile management. */
-	virtual SaveFileManager *get_savefile_manager() {
-		return new SaveFileManager();
-	}
+	virtual SaveFileManager *get_savefile_manager();
 
 	//@}
 };

Index: savefile.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/savefile.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- savefile.h	17 Apr 2004 09:57:15 -0000	1.10
+++ savefile.h	25 Jun 2004 22:11:47 -0000	1.11
@@ -32,30 +32,30 @@
 public:
 	virtual ~SaveFile() {}
 
-	/* Compatible with File API */
-	uint32 read(void *ptr, uint32 size);
-	uint32 write(const void *ptr, uint32 size);
-
 	virtual bool isOpen() const = 0;
-
-protected:
-	/* Only for internal use, use File compatible API above instead */
-	virtual int fread(void *buf, int size, int cnt) = 0;
-	virtual int fwrite(const void *buf, int size, int cnt) = 0;
 };
 
 class SaveFileManager {
-
 public:
 	virtual ~SaveFileManager() {}
 
+	/**
+	 * Open the file with name filename in the given directory for saving or loading.
+	 * @param filename	the filename
+	 * @param directory	the directory
+	 * @param saveOrLoad	true for saving, false for loading
+	 * @return pointer to a SaveFile object
+	 */
+	virtual SaveFile *open_savefile(const char *filename, const char *directory, bool saveOrLoad) = 0;
+	virtual void list_savefiles(const char * /* prefix */,  const char *directory, bool *marks, int num) = 0;
+};
+
+class DefaultSaveFileManager : public SaveFileManager {
+public:
 	virtual SaveFile *open_savefile(const char *filename, const char *directory, bool saveOrLoad);
-	virtual void list_savefiles(const char * /* prefix */,  const char *directory, bool *marks, int num) {
-		memset(marks, true, num * sizeof(bool));
-	}
+	virtual void list_savefiles(const char * /* prefix */,  const char *directory, bool *marks, int num);
 
 protected:
-	void join_paths(const char *filename, const char *directory, char *buf, int bufsize);
 	virtual SaveFile *makeSaveFile(const char *filename, bool saveOrLoad);
 };
 

Index: savefile.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/savefile.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- savefile.cpp	17 Apr 2004 09:57:15 -0000	1.10
+++ savefile.cpp	25 Jun 2004 22:11:47 -0000	1.11
@@ -30,15 +30,6 @@
 #include <zlib.h>
 #endif
 
-uint32 SaveFile::read(void *ptr, uint32 size) {
-	return fread(ptr, 1, size);
-}
-
-uint32 SaveFile::write(const void *ptr, uint32 size) {
-	return fwrite(ptr, 1, size);
-}
-
-
 class StdioSaveFile : public SaveFile {
 private:
 	FILE *fh;
@@ -50,11 +41,10 @@
 
 	bool isOpen() const { return fh != 0; }
 
-protected:
-	int fread(void *buf, int size, int cnt)
-		{ return ::fread(buf, size, cnt, fh); }
-	int fwrite(const void *buf, int size, int cnt)
-		{ return ::fwrite(buf, size, cnt, fh); }
+	uint32 read(void *buf, uint32 cnt)
+		{ return ::fread(buf, 1, cnt, fh); }
+	uint32 write(const void *buf, uint32 cnt)
+		{ return ::fwrite(buf, 1, cnt, fh); }
 };
 
 
@@ -70,11 +60,10 @@
 
 	bool isOpen() const { return fh != 0; }
 
-protected:
-	int fread(void *buf, int size, int cnt) {
-		return ::gzread(fh, buf, size * cnt);
+	uint32 read(void *buf, uint32 cnt) {
+		return ::gzread(fh, buf, cnt);
 	}
-	int fwrite(const void *buf, int size, int cnt) {
+	uint32 write(const void *buf, uint32 cnt) {
 		// Due to a "bug" in the zlib headers (or maybe I should say,
 		// a bug in the C++ spec? Whatever <g>) we have to be a bit
 		// hackish here and remove the const qualifier.
@@ -82,24 +71,13 @@
 		// which you might think is the same as "const void *" but it
 		// is not - rather it is equal to "void const *" which is the 
 		// same as "void *". Hrmpf
-		return ::gzwrite(fh, const_cast<void *>(buf), size * cnt);
+		return ::gzwrite(fh, const_cast<void *>(buf), cnt);
 	}
 };
 #endif
 
 
-SaveFile *SaveFileManager::open_savefile(const char *filename, const char *directory, bool saveOrLoad) {
-	char buf[256];
-	join_paths(filename, directory, buf, sizeof(buf));
-	SaveFile *sf = makeSaveFile(buf, saveOrLoad);
-	if (!sf->isOpen()) {
-		delete sf;
-		sf = 0;
-	}
-	return sf;
-}
-
-void SaveFileManager::join_paths(const char *filename, const char *directory,
+static void join_paths(const char *filename, const char *directory,
 								 char *buf, int bufsize) {
 	buf[bufsize-1] = '\0';
 	strncpy(buf, directory, bufsize-1);
@@ -125,7 +103,22 @@
 	strncat(buf, filename, bufsize-1);
 }
 
-SaveFile *SaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) {
+SaveFile *DefaultSaveFileManager::open_savefile(const char *filename, const char *directory, bool saveOrLoad) {
+	char buf[256];
+	join_paths(filename, directory, buf, sizeof(buf));
+	SaveFile *sf = makeSaveFile(buf, saveOrLoad);
+	if (!sf->isOpen()) {
+		delete sf;
+		sf = 0;
+	}
+	return sf;
+}
+
+void DefaultSaveFileManager::list_savefiles(const char * /* prefix */,  const char *directory, bool *marks, int num) {
+	memset(marks, true, num * sizeof(bool));
+}
+
+SaveFile *DefaultSaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) {
 #ifdef USE_ZLIB
 	return new GzipSaveFile(filename, saveOrLoad);
 #else





More information about the Scummvm-git-logs mailing list