]> git.lyx.org Git - lyx.git/blob - src/support/path.h
fix typo that put too many include paths for most people
[lyx.git] / src / support / path.h
1 // -*- C++ -*-
2 #ifndef PATH_H
3 #define PATH_H
4
5 #include "LString.h"
6 //#include "filetools.h"
7 #include "lyxlib.h"
8 #include <boost/utility.hpp>
9
10 #ifdef __GNUG__
11 #pragma interface
12 #endif
13
14 ///
15 class Path : boost::noncopyable {
16 public:
17         ///
18         explicit
19         Path(string const & path)
20                 : popped_(false)
21         {
22                 if (!path.empty()) {
23                         pushedDir_ = lyx::getcwd(); // GetCWD();
24                         if (pushedDir_.empty() || lyx::chdir(path)) {
25                                 // should throw an exception
26                                 // throw DirChangeError();
27                                 // The use of Alert::err_alert makes this
28                                 // impossible to inline.
29                                 //Alert::err_alert(_("Error: Could not change to directory: "),
30                                 //           path);
31                         }
32                 } else {
33                         popped_ = true;
34                 }
35         }
36         ///
37         ~Path()
38         {
39                 if (!popped_) pop();
40         }
41         ///
42         int pop();
43 private:
44         ///
45         bool popped_;
46         ///
47         string pushedDir_;
48 };
49
50 // To avoid the wrong usage:
51 // Path("/tmp");   // wrong
52 // Path p("/tmp");  // right
53 // we add this macro:
54 ///
55 #define Path(x) unnamed_Path;
56 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
57
58 #endif