]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sg_dir.hxx
Make tsync part of libSimGearCore when building shared libraries
[simgear.git] / simgear / misc / sg_dir.hxx
index 5ff51c9cb85fdd6272938412da95b8b4d689d2d1..109a0d4b0d846b1a51732683d2aec1f6882cfbf5 100644 (file)
 #include <simgear/math/sg_types.hxx>
 #include <simgear/misc/sg_path.hxx>
 
+#ifdef _MSC_VER
+  typedef int mode_t;
+#endif
+
 namespace simgear
 {
   typedef std::vector<SGPath> PathList;
@@ -38,6 +42,23 @@ namespace simgear
   class Dir
   {
   public:
+    Dir();
+    ~Dir();
+    
+    /**
+     * when this directory object is destroyed, remove the corresponding
+     * diretory (and its contents) from the disk. Often used with temporary
+     * directories to ensure they are cleaned up.
+     */
+    void setRemoveOnDestroy();
+    
+    static Dir current();
+    
+    /**
+     * create a temporary directory, using the supplied name
+     */
+    static Dir tempDir(const std::string& templ);
+      
     Dir(const SGPath& path);
     Dir(const Dir& rel, const SGPath& relPath);
     
@@ -52,8 +73,35 @@ namespace simgear
     PathList children(int types = 0, const std::string& nameGlob = "") const;
     
     SGPath file(const std::string& name) const;
+    
+    SGPath path() const
+        { return _path; }
+    
+    /**
+     * create the directory (and any parents as required) with the
+     * request mode, or return failure
+     */
+    bool create(mode_t mode);
+    
+    /**
+     * remove the directory. 
+     * If recursive is true, contained files and directories are
+     * recursively removed
+     */
+    bool remove(bool recursive = false);
+    
+    /**
+     * Check that the directory at the path exists (and is a directory!)
+     */
+    bool exists() const;
+    
+    /**
+     * parent directory, if one exists
+     */
+    Dir parent() const;
   private:
     mutable SGPath _path;
+    bool _removeOnDestroy;
   };
 } // of namespace simgear