]> git.lyx.org Git - lyx.git/blob - src/support/path.h
d1c4dfe18fac0ad6b68ce9078cb7a48bd6b0be76
[lyx.git] / src / support / path.h
1 // -*- C++ -*-
2 /**
3  * \file path.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef PATH_H
13 #define PATH_H
14
15 #include <boost/utility.hpp>
16
17 #include <string>
18
19 namespace lyx {
20 namespace support {
21
22 /**
23  * Path - utility closs for stackable working directories
24  *
25  * You can use a local variable of this type to temporarily
26  * change to a directory as the cwd, for example :
27  *
28  * if (blah) {
29  *      Path p("/tmp/blah");
30  *      ...
31  * }
32  *
33  * At the end of p's scope the cwd is reset to its previous value.
34  */
35 class Path : boost::noncopyable {
36 public:
37         /// change to the given directory
38         explicit Path(std::string const & path);
39
40         /// set cwd to the previous value if needed
41         ~Path();
42
43         /// set cwd to the previous value if needed
44         int pop();
45 private:
46         /// whether we are in the new cwd or not
47         bool popped_;
48         /// the previous cwd
49         std::string pushedDir_;
50 };
51
52 // To avoid the wrong usage:
53 // Path("/tmp");   // wrong
54 // Path p("/tmp");  // right
55 // we add this macro:
56 ///
57 // With boost 1.34 this is not usable anymore
58 //#ifndef PATH_C
59 //#define Path(x) unnamed_Path;
60 //#endif
61 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
62
63 } // namespace support
64 } // namespace lyx
65
66 #endif // PATH_H