]> git.lyx.org Git - lyx.git/blobdiff - src/support/path.h
Create a grfx::Loader class and so move large chunks of code out of
[lyx.git] / src / support / path.h
index 7059b1a285d325c9def93a6388612889e6dd3582..4b802cc14c947463bdd79536d5d38e5271d2dc32 100644 (file)
@@ -1,4 +1,12 @@
 // -*- C++ -*-
+/**
+ * \file path.h
+ * Copyright 1995-2002 the LyX Team
+ * Read the file COPYING
+ *
+ * \author unknown
+ */
+
 #ifndef PATH_H
 #define PATH_H
 
 #pragma interface
 #endif
 
-///
+
+/**
+ * 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_ = lyx::getcwd(); // GetCWD();
-                       if (pushedDir_.empty() || lyx::chdir(path)) {
-                               // should throw an exception
-                               // throw DirChangeError();
-                               // The use of Alert::err_alert makes this
-                               // impossible to inline.
-                               //Alert::err_alert(_("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 +72,4 @@ private:
 #define Path(x) unnamed_Path;
 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
 
-#endif
+#endif // PATH_H