]> git.lyx.org Git - lyx.git/blob - src/support/Path.cpp
cosmetics
[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 // Needed to prevent the definition of the unnamed_Path macro
14 // in the header file.
15
16 #define PATH_C
17
18 #include "support/Path.h"
19 #include "support/lyxlib.h"
20
21
22 namespace lyx {
23 namespace support {
24
25 PathChanger::PathChanger(FileName const & path)
26         : popped_(false)
27 {
28         if (!path.empty()) {
29                 pushedDir_ = getcwd();
30
31                 if (pushedDir_.empty() || chdir(path)) {
32                         /* FIXME: throw */
33                 }
34         } else {
35                 popped_ = true;
36         }
37 }
38
39
40 PathChanger::~PathChanger()
41 {
42         if (!popped_)
43                 pop();
44 }
45
46
47 int PathChanger::pop()
48 {
49         if (popped_) {
50                 // should throw an exception
51                 // throw logical_error();
52                 return 0;
53         }
54
55         if (chdir(pushedDir_)) {
56                 // should throw an exception
57                 // throw DirChangeError();
58         }
59         popped_ = true;
60
61         return 0;
62 }
63
64 } // namespace support
65 } // namespace lyx