tweak transport bar spacing
[ardour.git] / libs / pbd / pbd / filesystem.h
index a5b0ed5b28afcbff8c4bf746b73a8e06f5c01612..a20efaf61320606df66fceb39c16b2c78c381b88 100644 (file)
@@ -66,25 +66,29 @@ namespace PBD {
 
 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.
+        */
+       std::string leaf () const; 
 
        /**
         * @returns the directory component of a path without any trailing
@@ -95,7 +99,7 @@ public:
 
 private:
 
-       string m_path;
+       std::string m_path;
 };
 
 class filesystem_error : public std::runtime_error
@@ -109,9 +113,16 @@ public:
        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);
 
+
+/// @return true if path at p exists and is writable, false otherwise
+bool exists_and_writable(const path & p);
+
 /// @return true if path at p is a directory.
 bool is_directory(const path & p);
 
@@ -153,6 +164,11 @@ bool create_directories(const path & p);
  */
 bool remove(const path & p);
 
+/**
+ * Renames from_path to to_path as if by the glib function g_rename.
+ */
+void rename (const path& from_path, const path& to_path);
+
 /**
  * Attempt to copy the contents of the file from_path to a new file 
  * at path to_path.
@@ -162,8 +178,26 @@ bool remove(const path & p);
  */
 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.
+ */ 
+std::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.
+ */
+std::string extension (const path& p);
 
-string basename (const path& p);
+path get_absolute_path (const path &);
 
 } // namespace sys