]> git.lyx.org Git - lyx.git/blob - src/support/PathChanger.h
Update shortcuts in fr.po
[lyx.git] / src / support / PathChanger.h
1 // -*- C++ -*-
2 /**
3  * \file PathChanger.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 PATHCHANGER_H
13 #define PATHCHANGER_H
14
15 #include "support/FileName.h"
16
17
18 namespace lyx {
19 namespace support {
20
21 /**
22  * Path - utility class 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  *      FileName pp("/tmp/blah");
29  *      PathChanger p(pp);
30  *      ...
31  * }
32  *
33  * At the end of p's scope the cwd is reset to its previous value.
34  */
35 class PathChanger {
36 public:
37         /// change to the given directory
38         explicit PathChanger(FileName const & path);
39
40         /// set cwd to the previous value if needed
41         ~PathChanger();
42
43         /// set cwd to the previous value if needed
44         int pop();
45 private:
46         /// noncopyable
47         PathChanger(PathChanger const &);
48         void operator=(PathChanger const &);
49
50         /// whether we are in the new cwd or not
51         bool popped_;
52         /// the previous cwd
53         FileName pushedDir_;
54 };
55
56 // To avoid the wrong usage:
57 // PathChanger("/tmp");   // wrong
58 // PathChanger p("/tmp");  // right
59 // we add this macro:
60 #define PathChanger(x) unnamed_PathChanger;
61 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
62
63 } // namespace support
64 } // namespace lyx
65
66
67 #endif // PATHCHANGER_H