]> git.lyx.org Git - lyx.git/blobdiff - src/support/path.h
another safety belt
[lyx.git] / src / support / path.h
index ced3358c240c8c37a30606b858a3d2fbec733ef4..bbc567ca2e60ca8508497cc74a60da1bfd6fc304 100644 (file)
@@ -1,9 +1,19 @@
 // -*- C++ -*-
+/**
+ * \file path.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
 #ifndef PATH_H
 #define PATH_H
 
 #include "LString.h"
-#include "filetools.h"
+//#include "filetools.h"
 #include "lyxlib.h"
 #include <boost/utility.hpp>
 
 #pragma interface
 #endif
 
-///
-class Path : public noncopyable {
+
+/**
+ * Path - utility closs for stackable working directories
+ *
+ * You can use a local variable of this type to temporarily
+ * change to a directory as the cwd, for example :
+ *
+ * if (blah) {
+ *     Path p("/tmp/blah");
+ *     ...
+ * }
+ *
+ * At the end of p's scope the cwd is reset to its previous value.
+ */
+class Path : boost::noncopyable {
 public:
-       ///
+       /// change to the given directory
        explicit
        Path(string const & path)
                : popped_(false)
        {
-               if (!path.empty()) { 
-                       pushedDir_ = GetCWD();
-                       if (pushedDir_.empty() || lyx::chdir(path)) {
-                               // should throw an exception
-                               // throw DirChangeError();
-                               // The use of WriteFSAlert makes this
-                               // impossible to inline.
-                               //WriteFSAlert(_("Error: Could not change to directory: "), 
-                               //           path);
-                       }
+               if (!path.empty()) {
+                       pushedDir_ = lyx::getcwd();
+                       if (pushedDir_.empty() || lyx::chdir(path))
+                               /* FIXME: throw */;
                } else {
                        popped_ = true;
                }
        }
-       ///
+
+       /// set cwd to the previous value if needed
        ~Path()
        {
                if (!popped_) pop();
        }
-       ///
+
+       /// set cwd to the previous value if needed
        int pop();
 private:
-       ///
+       /// whether we are in the new cwd or not
        bool popped_;
-       ///
+       /// the previous cwd
        string pushedDir_;
 };
 
@@ -55,4 +74,4 @@ private:
 #define Path(x) unnamed_Path;
 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
 
-#endif
+#endif // PATH_H