]> git.lyx.org Git - lyx.git/blob - src/support/path.C
* lyxfunctional.h: delete compare_memfun and helper classes
[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
20 using std::string;
21
22
23 namespace lyx {
24 namespace support {
25
26 Path::Path(string const & path)
27         : popped_(false)
28 {
29         if (!path.empty()) {
30                 pushedDir_ = getcwd();
31                 if (pushedDir_.empty() || chdir(path))
32                         /* FIXME: throw */;
33         } else {
34                 popped_ = true;
35         }
36 }
37
38
39 Path::~Path()
40 {
41         if (!popped_) pop();
42 }
43
44
45 int Path::pop()
46 {
47         if (popped_) {
48                 // should throw an exception
49                 // throw logical_error();
50                 return 0;
51         }
52
53         if (chdir(pushedDir_)) {
54                 // should throw an exception
55                 // throw DirChangeError();
56         }
57         popped_ = true;
58
59         return 0;
60 }
61
62 } // namespace support
63 } // namespace lyx