]> git.lyx.org Git - lyx.git/blobdiff - src/support/path.h
fix compiler warnings about unused parameter
[lyx.git] / src / support / path.h
index 88dba32bfaa050dae2fb1cc3888569ff87f9a991..13296353aa6a87ce6b919773e6c2804915cb1663 100644 (file)
@@ -1,50 +1,54 @@
 // -*- 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 "lyxlib.h"
+#include "support/filename.h"
+
 #include <boost/utility.hpp>
 
-#ifdef __GNUG__
-#pragma interface
-#endif
+#include <string>
 
-///
+namespace lyx {
+namespace support {
+
+/**
+ * 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:
-       ///
-       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);
-                       }
-               } else {
-                       popped_ = true;
-               }
-       }
-       ///
-       ~Path()
-       {
-               if (!popped_) pop();
-       }
-       ///
+       /// change to the given directory
+       explicit Path(std::string const & path);
+
+       /// set cwd to the previous value if needed
+       ~Path();
+
+       /// set cwd to the previous value if needed
        int pop();
 private:
-       ///
+       /// whether we are in the new cwd or not
        bool popped_;
-       ///
-       string pushedDir_;
+       /// the previous cwd
+       FileName pushedDir_;
 };
 
 // To avoid the wrong usage:
@@ -52,7 +56,13 @@ private:
 // Path p("/tmp");  // right
 // we add this macro:
 ///
-#define Path(x) unnamed_Path;
+// With boost 1.34 this is not usable anymore
+//#ifndef PATH_C
+//#define Path(x) unnamed_Path;
+//#endif
 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
 
-#endif
+} // namespace support
+} // namespace lyx
+
+#endif // PATH_H