[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.74,1.75 file.h,1.29,1.30

Max Horn fingolfin at users.sourceforge.net
Sat Nov 27 09:14:52 CET 2004


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

Modified Files:
	file.cpp file.h 
Log Message:
Make use of our String class instead of juggling with char pointers; added File::exists method

Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- file.cpp	14 Nov 2004 21:10:50 -0000	1.74
+++ file.cpp	27 Nov 2004 15:09:52 -0000	1.75
@@ -26,7 +26,7 @@
 Common::StringList File::_defaultDirectories;
 
 
-FILE *File::fopenNoCase(const char *filename, const char *directory, const char *mode) {
+static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode) {
 	FILE *file;
 	char buf[512];
 	char *ptr;
@@ -104,28 +104,27 @@
 }
 
 File::File()
- : _handle(0), _ioFailed(false), _refcount(1), _name(0) {
+ : _handle(0), _ioFailed(false), _refcount(1) {
 }
 
 //#define DEBUG_FILE_REFCOUNT
 
 File::~File() {
 #ifdef DEBUG_FILE_REFCOUNT
-	warning("File::~File on file '%s'", _name);
+	warning("File::~File on file '%s'", _name.c_str());
 #endif
 	close();
-	delete [] _name;
 }
 void File::incRef() {
 #ifdef DEBUG_FILE_REFCOUNT
-	warning("File::incRef on file '%s'", _name);
+	warning("File::incRef on file '%s'", _name.c_str());
 #endif
 	_refcount++;
 }
 
 void File::decRef() {
 #ifdef DEBUG_FILE_REFCOUNT
-	warning("File::decRef on file '%s'", _name);
+	warning("File::decRef on file '%s'", _name.c_str());
 #endif
 	if (--_refcount == 0) {
 		delete this;
@@ -137,7 +136,7 @@
 	assert(mode == kFileReadMode || mode == kFileWriteMode);
 
 	if (_handle) {
-		error("File::open: This file object already is opened (%s), won't open '%s'", _name, filename);
+		error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename);
 	}
 
 	if (filename == NULL || *filename == 0) {
@@ -168,19 +167,22 @@
 		return false;
 	}
 
-	int len = strlen(filename);
-	if (_name != 0)
-		delete [] _name;
-	_name = new char[len+1];
-	memcpy(_name, filename, len+1);
+
+	_name = filename;
 
 #ifdef DEBUG_FILE_REFCOUNT
-	warning("File::open on file '%s'", _name);
+	warning("File::open on file '%s'", _name.c_str());
 #endif
 
 	return true;
 }
 
+bool File::exists(const char *filename, const char *directory) {
+	// FIXME: Ugly ugly hack!
+	File tmp;
+	return tmp.open(filename, kFileReadMode, directory);
+}
+
 void File::close() {
 	if (_handle)
 		fclose(_handle);

Index: file.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- file.h	16 Oct 2004 13:09:52 -0000	1.29
+++ file.h	27 Nov 2004 15:09:52 -0000	1.30
@@ -39,11 +39,9 @@
 	int32 _refcount;
 
 	/** The name of this file, for debugging. */
-	char *_name;
+	Common::String _name;
 
 
-	static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
-	
 	static Common::StringList _defaultDirectories;
 
 public:
@@ -62,6 +60,8 @@
 	void decRef();
 
 	virtual bool open(const char *filename, AccessMode mode = kFileReadMode, const char *directory = NULL);
+	virtual bool exists(const char *filename, const char *directory = NULL);
+
 	virtual void close();
 	bool isOpen() const;
 	bool ioFailed() const;
@@ -69,7 +69,7 @@
 	virtual bool eof();
 	virtual uint32 pos();
 	virtual uint32 size();
-	const char *name() const { return _name; }
+	const char *name() const { return _name.c_str(); }
 	virtual void seek(int32 offs, int whence = SEEK_SET);
 	uint32 read(void *ptr, uint32 size);
 	uint32 write(const void *ptr, uint32 size);





More information about the Scummvm-git-logs mailing list