]> git.lyx.org Git - features.git/blob - src/support/path.h
Replace LString.h with support/std_string.h,
[features.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 "support/std_string.h"
16 #include <boost/utility.hpp>
17
18 namespace lyx {
19 namespace support {
20
21 /**
22  * Path - utility closs for stackable working directories
23  *
24  * You can use a local variable of this type to temporarily
25  * change to a directory as the cwd, for example :
26  *
27  * if (blah) {
28  *      Path p("/tmp/blah");
29  *      ...
30  * }
31  *
32  * At the end of p's scope the cwd is reset to its previous value.
33  */
34 class Path : boost::noncopyable {
35 public:
36         /// change to the given directory
37         explicit Path(string const & path);
38
39         /// set cwd to the previous value if needed
40         ~Path();
41
42         /// set cwd to the previous value if needed
43         int pop();
44 private:
45         /// whether we are in the new cwd or not
46         bool popped_;
47         /// the previous cwd
48         string pushedDir_;
49 };
50
51 // To avoid the wrong usage:
52 // Path("/tmp");   // wrong
53 // Path p("/tmp");  // right
54 // we add this macro:
55 ///
56 #ifndef PATH_C
57 #define Path(x) unnamed_Path;
58 #endif
59 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
60
61 } // namespace support
62 } // namespace lyx
63
64 #endif // PATH_H