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