/src/CMake/Source/cmWorkingDirectory.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <string> |
8 | | |
9 | | /** \class cmWorkingDirectory |
10 | | * \brief An RAII class to manipulate the working directory. |
11 | | * |
12 | | * The current working directory is set to the location given to the |
13 | | * constructor. The working directory can be changed again as needed |
14 | | * by calling SetDirectory(). When the object is destroyed, the destructor |
15 | | * will restore the working directory to what it was when the object was |
16 | | * created, regardless of any calls to SetDirectory() in the meantime. |
17 | | */ |
18 | | class cmWorkingDirectory |
19 | | { |
20 | | public: |
21 | | cmWorkingDirectory(std::string const& newdir); |
22 | | ~cmWorkingDirectory(); |
23 | | |
24 | | cmWorkingDirectory(cmWorkingDirectory const&) = delete; |
25 | | cmWorkingDirectory& operator=(cmWorkingDirectory const&) = delete; |
26 | | |
27 | | bool SetDirectory(std::string const& newdir); |
28 | | void Pop(); |
29 | 0 | bool Failed() const { return !this->Error.empty(); } |
30 | 0 | std::string const& GetError() const { return this->Error; } |
31 | 0 | std::string const& GetOldDirectory() const { return this->OldDir; } |
32 | | |
33 | | private: |
34 | | std::string OldDir; |
35 | | std::string Error; |
36 | | }; |