[Scummvm-cvs-logs] SF.net SVN: scummvm:[43060] tools/branches/gsoc2009-gui

Remere at users.sourceforge.net Remere at users.sourceforge.net
Wed Aug 5 02:32:26 CEST 2009


Revision: 43060
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43060&view=rev
Author:   Remere
Date:     2009-08-05 00:32:23 +0000 (Wed, 05 Aug 2009)

Log Message:
-----------
*Added exists() method to the Filename class.
*Added doxygen documentation to the Filename class.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/util.cpp
    tools/branches/gsoc2009-gui/util.h

Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp	2009-08-05 00:11:09 UTC (rev 43059)
+++ tools/branches/gsoc2009-gui/util.cpp	2009-08-05 00:32:23 UTC (rev 43060)
@@ -163,7 +163,22 @@
 	return _path.empty();
 }
 
-bool Filename::hasExtension(std::string suffix) const {
+bool Filename::directory() const {
+	return getFullName().size() == 0;
+}
+
+bool Filename::exists() const { 
+	// This fails if we don't have permission to read the file
+	// but in most cases, that's the same thing for us.
+	FILE *f = fopen(_path.c_str(), "r");
+	if (f) {
+		fclose(f);
+		return true;
+	}
+	return false;
+}
+
+bool Filename::hasExtension(std::string ext) const {
 	size_t dot = _path.rfind('.');
 	if (dot == std::string::npos)
 		return false;
@@ -183,19 +198,19 @@
 	// We compare extensions, skip any dots
 	if (_path[dot] == '.')
 		dot++;
-	if (suffix[0] == '.')
-		suffix = suffix.substr(1);
+	if (ext[0] == '.')
+		ext = ext.substr(1);
 
 	std::string tmp = _path.substr(dot);
 #ifdef _WIN32
 	// On Windows paths are case-insensitive
-	return scumm_stricmp(tmp.c_str(), suffix.c_str()) == 0;
+	return scumm_stricmp(tmp.c_str(), ext.c_str()) == 0;
 #else
-	return tmp == suffix;
+	return tmp == ext;
 #endif
 }
 
-const std::string &Filename::getFullPath() const {
+std::string Filename::getFullPath() const {
 	return _path;
 }
 

Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h	2009-08-05 00:11:09 UTC (rev 43059)
+++ tools/branches/gsoc2009-gui/util.h	2009-08-05 00:32:23 UTC (rev 43060)
@@ -289,23 +289,92 @@
 		return equals(fn);
 	}
 	
+	/**
+	 * Change the entire path including directory, volume and actual filname.
+	 *
+	 * @param path The new path.
+	 */
 	void setFullPath(const std::string &path);
+
+	/**
+	 * Sets the name of the file referred to, does not change the directory referred to.
+	 *
+	 * @param name New filename.
+	 */
 	void setFullName(const std::string &name);
+
+	/**
+	 * Adds an extension to the filename (does not replace any current extension).
+	 *
+	 * @param ext Extension to add.
+	 */
 	void addExtension(const std::string &ext);
+
+	/**
+	 * Sets the extension of the filename, replacing any current one, or adding one if there isn't any.
+	 *
+	 * @param ext The new extension of the filename.
+	 */
 	void setExtension(const std::string &ext);
 
-	bool hasExtension(std::string suffix) const;
+	/**
+	 * Returns true if the file has that extension.
+	 *
+	 * @param ext Extension to check for, only last extension is checked.
+	 * @return True if the filename has that extension.
+	 */
+	bool hasExtension(std::string ext) const;
+
+	/**
+	 * Has the filename been set to anything.
+	 */
 	bool empty() const;
-	bool directory() const {return getFullName().size() == 0;}
+
+	/**
+	 * Returns true if the file exists, does NOT work for directories
+	 */
+	bool exists() const;
+
+	/**
+	 * Returns true if the file is a directory, which is if the path ends with '/'.
+	 *
+	 * @return true if the path looks like a directory.
+	 */
+	bool directory() const;
+
+	/**
+	 * True if the filenames are different (relative and absolute paths will NOT compare equally).
+	 *
+	 * @param other The filename to compare to.
+	 * @return True if they are equal.
+	 */
 	bool equals(const Filename &other) const;
 	
-	// Doesn't work
-	bool mkdir(int permission = 077);
 
-	const std::string &getFullPath() const;
+	/**
+	 * Returns the entire path.
+	 */
+	std::string getFullPath() const;
+
+	/**
+	 * Returns the filename (ie. strips all directories from the path)
+	 */
 	std::string getFullName() const;
+
+	/**
+	 * Returns the name of the file, excluding extension and directories.
+	 * Note that in the case of multiple extensions, only the last extension is stripped.
+	 */
 	std::string getName() const;
+
+	/**
+	 * Get the extension of the filename, only the last extension in case of many.
+	 */
 	std::string getExtension() const;
+
+	/**
+	 * Returns the path of the filename, the name and extension of the file is stripped.
+	 */
 	std::string getPath() const;
 };
 


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