CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmWorkingDirectory.h
blobe593621471a6224f3a7ea5ea5887a49f916a6326
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <string>
9 /** \class cmWorkingDirectory
10 * \brief An RAII class to manipulate the working directory.
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.
18 class cmWorkingDirectory
20 public:
21 cmWorkingDirectory(std::string const& newdir);
22 ~cmWorkingDirectory();
24 cmWorkingDirectory(const cmWorkingDirectory&) = delete;
25 cmWorkingDirectory& operator=(const cmWorkingDirectory&) = delete;
27 bool SetDirectory(std::string const& newdir);
28 void Pop();
29 bool Failed() const { return this->ResultCode != 0; }
31 /** \return 0 if the last attempt to set the working directory was
32 * successful. If it failed, the value returned will be the
33 * \c errno value associated with the failure. A description
34 * of the error code can be obtained by passing the result
35 * to \c std::strerror().
37 int GetLastResult() const { return this->ResultCode; }
39 std::string const& GetOldDirectory() const { return this->OldDir; }
41 private:
42 std::string OldDir;
43 int ResultCode;