]> git.lyx.org Git - lyx.git/blob - src/support/Path.cpp
Transfer tempName() implementation to FileName.
[lyx.git] / src / support / Path.cpp
1 /**
2  * \file Path.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/Path.h"
14 #include "support/lyxlib.h"
15
16 // undef PathChanger macro when building PathChanger
17 #undef PathChanger
18
19
20 namespace lyx {
21 namespace support {
22
23 PathChanger::PathChanger(FileName const & path)
24         : popped_(false)
25 {
26         if (!path.empty()) {
27                 pushedDir_ = getcwd();
28
29                 if (pushedDir_.empty() || !path.chdir()) {
30                         /* FIXME: throw */
31                 }
32         } else {
33                 popped_ = true;
34         }
35 }
36
37
38 PathChanger::~PathChanger()
39 {
40         if (!popped_)
41                 pop();
42 }
43
44
45 int PathChanger::pop()
46 {
47         if (popped_) {
48                 // should throw an exception
49                 // throw logical_error();
50                 return 0;
51         }
52
53         if (!pushedDir_.chdir()) {
54                 // should throw an exception
55                 // throw DirChangeError();
56         }
57         popped_ = true;
58
59         return 0;
60 }
61
62 } // namespace support
63 } // namespace lyx
64
65
66 #define PathChanger(x) unnamed_PathChanger;
67 // in merged builds this is not the last line.