[Scummvm-cvs-logs] SF.net SVN: scummvm:[46408] tools/branches/gsoc2009-gui
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Thu Dec 17 22:39:53 CET 2009
Revision: 46408
http://scummvm.svn.sourceforge.net/scummvm/?rev=46408&view=rev
Author: fingolfin
Date: 2009-12-17 21:39:52 +0000 (Thu, 17 Dec 2009)
Log Message:
-----------
TOOLS: Removed 'FileMode' variants of File constructor & open() method; fix 'r+' file mode; added File::clearErr() method
Modified Paths:
--------------
tools/branches/gsoc2009-gui/common/file.cpp
tools/branches/gsoc2009-gui/common/file.h
tools/branches/gsoc2009-gui/extract_agos.cpp
Modified: tools/branches/gsoc2009-gui/common/file.cpp
===================================================================
--- tools/branches/gsoc2009-gui/common/file.cpp 2009-12-17 21:12:20 UTC (rev 46407)
+++ tools/branches/gsoc2009-gui/common/file.cpp 2009-12-17 21:39:52 UTC (rev 46408)
@@ -26,15 +26,14 @@
#include <assert.h>
// Filenname implementation
-Filename::Filename(const char *path) {
- _path = path;
+Filename::Filename() {
}
-Filename::Filename(std::string path) {
- _path = path;
+Filename::Filename(const char *path) : _path(path) {
}
+Filename::Filename(std::string path) : _path(path) {
+}
-Filename::Filename(const Filename& filename) {
- _path = filename._path;
+Filename::Filename(const Filename& filename) : _path(filename._path) {
}
Filename& Filename::operator=(const Filename& filename) {
@@ -189,14 +188,6 @@
_xormode = 0;
}
-File::File(const Filename &filepath, FileMode mode) {
- _file = NULL;
- _mode = FILEMODE_READ;
- _xormode = 0;
-
- open(filepath, mode);
-}
-
File::File(const Filename &filepath, const char *mode) {
_file = NULL;
_mode = FILEMODE_READ;
@@ -210,36 +201,24 @@
}
void File::open(const Filename &filepath, const char *mode) {
- FileMode m = FILEMODE_WRITE;
+
+ // Clean up previously opened file
+ close();
+
+ _file = fopen(filepath.getFullPath().c_str(), mode);
+
+ FileMode m = FILEMODE_READ;
do {
switch(*mode) {
case 'w': m = FILEMODE_WRITE; break;
case 'r': m = FILEMODE_READ; break;
case 'b': m = FileMode(m | FILEMODE_BINARY); break;
- case '+': m = FileMode(m | FILEMODE_APPEND); break;
+ case '+': m = FileMode(m | FILEMODE_READ | FILEMODE_WRITE); break;
default: throw FileException(std::string("Unsupported FileMode ") + mode);
}
} while (*++mode);
-
- open(filepath, m);
-}
+ _mode = m;
-void File::open(const Filename &filepath, FileMode mode) {
- // Clean up previously opened file
- close();
-
- std::string strmode;
- if (mode & FILEMODE_READ)
- strmode += 'r';
- if (mode & FILEMODE_WRITE)
- strmode += 'w';
- if (mode & FILEMODE_BINARY)
- strmode += 'b';
- if (mode & FILEMODE_APPEND)
- strmode += '+';
-
- _file = fopen(filepath.getFullPath().c_str(), strmode.c_str());
- _mode = mode;
_name = filepath;
_xormode = 0;
@@ -488,6 +467,10 @@
return ferror(_file);
}
+void File::clearErr() {
+ clearerr(_file);
+}
+
bool File::eos() const {
return feof(_file) != 0;
}
Modified: tools/branches/gsoc2009-gui/common/file.h
===================================================================
--- tools/branches/gsoc2009-gui/common/file.h 2009-12-17 21:12:20 UTC (rev 46407)
+++ tools/branches/gsoc2009-gui/common/file.h 2009-12-17 21:39:52 UTC (rev 46408)
@@ -44,7 +44,8 @@
public:
std::string _path;
- Filename(std::string path = "");
+ Filename();
+ Filename(std::string path);
Filename(const char *path);
Filename(const Filename &path);
Filename& operator=(const Filename &fn);
@@ -148,8 +149,7 @@
enum FileMode {
FILEMODE_READ = 1,
FILEMODE_WRITE = 2,
- FILEMODE_BINARY = 4,
- FILEMODE_APPEND = 8,
+ FILEMODE_BINARY = 4
};
/**
@@ -162,12 +162,10 @@
/**
* Opens the given file path as an in/out stream, depending on the
* second argument.
- * File is always opened in binary mode.
*
- * @param filename The file to open
- * @param mode The mode to open the file in, can be either OR mask or in text
+ * @param filename file to open
+ * @param mode mode to open the file in
*/
- File(const Filename &filename, FileMode mode);
File(const Filename &filename, const char *mode);
/**
@@ -180,11 +178,10 @@
* Opens the given file path as an in/out stream, depending on the
* second argument.
*
- * @param filename The file to open
- * @param mode The mode to open the file in
+ * @param filename file to open
+ * @param mode mode to open the file in
*/
void open(const Filename &filename, const char *mode);
- void open(const Filename &filename, FileMode mode);
/**
* Closes the file, if it's open.
@@ -365,6 +362,8 @@
*/
int err() const;
+ void clearErr();
+
/**
* True if there is nothing more to read from this file.
*/
Modified: tools/branches/gsoc2009-gui/extract_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_agos.cpp 2009-12-17 21:12:20 UTC (rev 46407)
+++ tools/branches/gsoc2009-gui/extract_agos.cpp 2009-12-17 21:39:52 UTC (rev 46408)
@@ -203,7 +203,7 @@
* @param length How many bytes to write
*/
void ExtractAgos::savefile(const Filename &name, void *mem, size_t length) {
- File file(name, FILEMODE_WRITE);
+ File file(name, "wb");
file.write(mem, length);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list