]> git.lyx.org Git - lyx.git/blob - src/support/Path.h
more latin1..utf8 schanges. all of src/* should be utf8 now
[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
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 PathChanger {
35 public:
36         /// change to the given directory
37         explicit PathChanger(FileName const & path);
38
39         /// set cwd to the previous value if needed
40         ~PathChanger();
41
42         /// set cwd to the previous value if needed
43         int pop();
44 private:
45         /// noncopyable
46         PathChanger(PathChanger const &);
47         void operator=(PathChanger const &);
48
49         /// whether we are in the new cwd or not
50         bool popped_;
51         /// the previous cwd
52         FileName pushedDir_;
53 };
54
55 // To avoid the wrong usage:
56 // PathChanger("/tmp");   // wrong
57 // PathChanger p("/tmp");  // right
58 // we add this macro:
59 #define PathChanger(x) unnamed_PathChanger;
60 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
61
62 } // namespace support
63 } // namespace lyx
64
65 #endif // PATH_H