diff options
Diffstat (limited to 'src/utils/cpp/tmp_dir.hpp')
-rw-r--r-- | src/utils/cpp/tmp_dir.hpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/utils/cpp/tmp_dir.hpp b/src/utils/cpp/tmp_dir.hpp index 92d24f52..e2e1e7a7 100644 --- a/src/utils/cpp/tmp_dir.hpp +++ b/src/utils/cpp/tmp_dir.hpp @@ -17,38 +17,34 @@ #include <filesystem> #include <memory> -#include <string> +#include <utility> -std::string const kDefaultTemplate{"tmp.XXXXXX"}; - -class TmpDir; -using TmpDirPtr = std::shared_ptr<TmpDir const>; - -class TmpDir { +class TmpDir final { public: - // default ctor; not to be used! - TmpDir() = default; - - /// \brief Destroy the TmpDir object. It tries to remove the tmp folder. - ~TmpDir() noexcept; + using Ptr = std::shared_ptr<TmpDir const>; - // no copies, no moves TmpDir(TmpDir const&) = delete; - TmpDir(TmpDir&& other) noexcept = delete; - auto operator=(TmpDir const&) = delete; - auto operator=(TmpDir&& other) noexcept -> TmpDir& = delete; + auto operator=(TmpDir const&) -> TmpDir& = delete; + TmpDir(TmpDir&& other) = delete; + auto operator=(TmpDir&&) -> TmpDir& = delete; + ~TmpDir() noexcept; [[nodiscard]] auto GetPath() const& noexcept - -> std::filesystem::path const&; - [[nodiscard]] auto GetPath() && = delete; + -> std::filesystem::path const& { + return tmp_dir_; + } /// \brief Creates a completely unique directory in a given prefix path. [[nodiscard]] static auto Create( - std::filesystem::path const& prefix, - std::string const& dir_template = kDefaultTemplate) noexcept - -> TmpDirPtr; + std::filesystem::path const& prefix) noexcept -> Ptr; private: + explicit TmpDir(std::filesystem::path path) noexcept + : tmp_dir_{std::move(path)} {} + + [[nodiscard]] static auto CreateImpl( + std::filesystem::path const& path) noexcept -> Ptr; + std::filesystem::path tmp_dir_; }; |