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