123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #ifndef FILENAME_H
- #define FILENAME_H
- #include <string>
- namespace NICE {
-
- /**
- * Represents a file name.
- * Supports special string and file operations.
- *
- * @author Ferid Bajramovic (ferid [dot] bajramovic [at] informatik [dot] uni-jena [dot] de)
- */
- class FileName {
- public:
- /**
- * Constructor: empty filename.
- */
- FileName();
- /**
- * Constructor.
- * @param _fileName initial file name
- */
- FileName(const std::string& _fileName);
- /**
- * Constructor.
- * @param _fileName initial file name
- */
- FileName(const char* _fileName);
-
- /**
- * Copy-Constructor.
- */
- FileName(const FileName& _fileName);
-
- /**
- * Assignment.
- */
- FileName& operator=(const FileName& _fileName);
- /**
- * Assignment.
- */
- FileName& operator=(const std::string& _fileName);
- /**
- * Assignment.
- */
- FileName& operator=(const char* _fileName);
-
- virtual ~FileName();
-
- /**
- * Convert to \c string.
- * @return the file name (as \c string)
- */
- const std::string& str() const;
- /**
- * Convert (cast) to <tt>char *</tt>.
- * @return the file name (as <tt>char *</tt>)
- */
- operator const char*() const;
- /**
- * Convert (cast) to \c string.
- * @return the file name (as \c string)
- */
- operator const std::string&() const;
-
- /**
- * Set the FileName to \c s.
- * @param s new filename
- */
- inline void set(const std::string& s) { fileName = s; }
- /**
- * Extract the path (including the last slash '/').
- * Example: <tt> FileName("/a/b/c/file.txt").extractPath()</tt>
- * returns "/a/b/c/"
- * @return the path
- */
- FileName extractPath() const;
- /**
- * Extract the file name (name and extension, no path)
- * Example: <tt>FileName("/a/b/c/file.txt").extractFileName()</tt>
- * returns "file.txt"
- * @return file name without path
- */
- FileName extractFileName() const;
- /**
- * Extract the extension (everything from the last dot '.', inclusive)
- * Example: <tt>FileName("/a/b/c/file.txt").extractExtension()</tt>
- * returns ".txt"
- * @return the file extension
- */
- FileName extractExtension() const;
-
- /**
- * Remove the extension if one exists (everything from the last dot '.', inclusive)
- */
- void removeExtension();
-
- /**
- * Add a slash '/' at the end if there is non
- * (except when the FileName is empty "")
- */
- void addSlash();
- /**
- * Remove a slash '/' at the end if there is one
- */
- void removeSlash();
-
- /**
- * Add \c extension as file name extension,
- * except if the file name extension is already \c extension.
- * @param extension The new file name extension
- * (should contain a leading dot ".")
- */
- void setExtension(const std::string& extension);
-
- /**
- * Create a directory named as this FileName.
- */
- void createDirectory() const;
-
- /**
- * Does this filename exist (i.e. a file with this name)?
- * @return true if the file exists
- */
- bool fileExists() const;
- /**
- * Is this filename a directory?
- * @return true if it's directory
- */
- bool isDirectory() const;
-
- /**
- * Delete the file (does not work on directories).
- */
- void deleteFile() const;
-
- private:
- //! stores the file name
- std::string fileName;
- };
- } // namespace
- #endif // FILENAME_H
|