[Scummvm-cvs-logs] CVS: scummvm/common file.cpp,1.61,1.62 file.h,1.25,1.26
Max Horn
fingolfin at users.sourceforge.net
Mon Jun 28 15:35:02 CEST 2004
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25360/common
Modified Files:
file.cpp file.h
Log Message:
Added simple ref-counting to the File class
Index: file.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.cpp,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- file.cpp 28 Jun 2004 00:06:15 -0000 1.61
+++ file.cpp 28 Jun 2004 22:34:22 -0000 1.62
@@ -104,16 +104,35 @@
_defaultDirectories.clear();
}
-File::File() {
- _handle = NULL;
- _ioFailed = false;
- _name = 0;
+File::File()
+ : _handle(0), _ioFailed(false), _refcount(1), _name(0) {
}
+//#define DEBUG_FILE_REFCOUNT
+
File::~File() {
+#ifdef DEBUG_FILE_REFCOUNT
+ warning("File::~File on file '%s'", _name);
+#endif
close();
delete [] _name;
}
+void File::incRef() {
+#ifdef DEBUG_FILE_REFCOUNT
+ warning("File::incRef on file '%s'", _name);
+#endif
+ _refcount++;
+}
+
+void File::decRef() {
+#ifdef DEBUG_FILE_REFCOUNT
+ warning("File::decRef on file '%s'", _name);
+#endif
+ if (--_refcount == 0) {
+ delete this;
+ }
+}
+
bool File::open(const char *filename, AccessMode mode, const char *directory) {
if (_handle) {
@@ -156,6 +175,10 @@
_name = new char[len+1];
memcpy(_name, filename, len+1);
+#ifdef DEBUG_FILE_REFCOUNT
+ warning("File::open on file '%s'", _name);
+#endif
+
return true;
}
Index: file.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/file.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- file.h 28 Jun 2004 00:06:15 -0000 1.25
+++ file.h 28 Jun 2004 22:34:22 -0000 1.26
@@ -29,10 +29,18 @@
class File : public Common::ReadStream, public Common::WriteStream {
private:
-
- FILE * _handle;
+ /** POSIX file handle to the actual file; 0 if no file is open. */
+ FILE *_handle;
+
+ /** Status flag which tells about recent I/O failures. */
bool _ioFailed;
- char *_name; // For debugging
+
+ /** Simple ref-counter for File objects. */
+ int32 _refcount;
+
+ /** The name of this file, for debugging. */
+ char *_name;
+
static FILE *fopenNoCase(const char *filename, const char *directory, const char *mode);
@@ -49,6 +57,10 @@
File();
virtual ~File();
+
+ void incRef();
+ void decRef();
+
bool open(const char *filename, AccessMode mode = kFileReadMode, const char *directory = NULL);
void close();
bool isOpen() const;
More information about the Scummvm-git-logs
mailing list