namespace sys {
-using std::string;
-
class path
{
public:
path() : m_path("") { }
path(const path & p) : m_path(p.m_path) { }
- path(const string & s) : m_path(s) { }
+ path(const std::string & s) : m_path(s) { }
path(const char* s) : m_path(s) { }
path& operator=(const path& p) { m_path = p.m_path; return *this;}
- path& operator=(const string& s) { m_path = s; return *this; }
+ path& operator=(const std::string& s) { m_path = s; return *this; }
path& operator=(const char* s) { m_path = s; return *this; }
path& operator/=(const path& rhs);
- path& operator/=(const string& s);
+ path& operator/=(const std::string& s);
path& operator/=(const char* s);
- const string to_string() const { return m_path; }
+ const std::string to_string() const { return m_path; }
/**
* @return the last component of the path, if the path refers to
* a file then it will be the entire filename including any extension.
*/
- string leaf() const;
-
- /**
- * @returns the directory component of a path without any trailing
- * path separator or an empty string if the path has no directory
- * component(branch path).
- */
- path branch_path () const;
+ std::string leaf () const;
private:
- string m_path;
+ std::string m_path;
};
class filesystem_error : public std::runtime_error
int system_error() const { return m_error_code; }
};
+inline path operator/ (const path& lhs, const path& rhs)
+{ return path(lhs) /= rhs; }
+
/// @return true if path at p exists
bool exists(const path & p);
*/
bool create_directories(const path & p);
-/**
- * Attempt to delete the file at path p as if by the glib function
- * g_unlink.
- *
- * @return true if file existed prior to removing it, false if file
- * at p did not exist.
- *
- * @throw filesystem_error if removing the file failed for any other
- * reason other than the file did not exist.
- */
-bool remove(const path & p);
-
-/**
- * Attempt to copy the contents of the file from_path to a new file
- * at path to_path.
- *
- * @throw filesystem_error if from_path.empty() || to_path.empty() ||
- * !exists(from_path) || !is_regular(from_path) || exists(to_path)
- */
-void copy_file(const path & from_path, const path & to_path);
-
-/**
- * @return The substring of the filename component of the path, starting
- * at the beginning of the filename up to but not including the last dot.
- *
- * boost::filesystem::path::basename differs from g_path_get_basename and
- * ::basename and most other forms of basename in that it removes the
- * extension from the filename if the filename has one.
- */
-string basename (const path& p);
-
-/**
- * @return If the filename contains a dot, return a substring of the
- * filename starting the rightmost dot to the end of the string, otherwise
- * an empty string.
- *
- * @param p a file path.
- */
-string extension (const path& p);
-
} // namespace sys
} // namespace PBD