| 1 |
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ |
| 2 |
|
| 3 |
#ifndef MPT_IO_FILE_UNIQUE_UNIQUE_TEMPFILENAME_HPP |
| 4 |
#define MPT_IO_FILE_UNIQUE_UNIQUE_TEMPFILENAME_HPP |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "mpt/base/detect.hpp" |
| 9 |
#include "mpt/base/namespace.hpp" |
| 10 |
#include "mpt/io_file_unique/unique_basename.hpp" |
| 11 |
#include "mpt/fs/common_directories.hpp" |
| 12 |
#include "mpt/fs/fs.hpp" |
| 13 |
#include "mpt/path/native_path.hpp" |
| 14 |
#include "mpt/path/os_path.hpp" |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
namespace mpt { |
| 19 |
inline namespace MPT_INLINE_NS { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace IO { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class unique_tempfilename { |
| 28 |
|
| 29 |
private: |
| 30 |
mpt::os_path m_Filename; |
| 31 |
|
| 32 |
public: |
| 33 |
unique_tempfilename(const unique_basename & basename, const mpt::os_path & extension = MPT_OS_PATH("tmp")) |
| 34 |
: m_Filename(mpt::common_directories::get_temp_directory().WithTrailingSlash() + static_cast<mpt::os_path>(basename) + (extension.empty() ? extension : MPT_OS_PATH(".") + extension)) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
public: |
| 39 |
operator mpt::os_path() const { |
| 40 |
return m_Filename; |
| 41 |
} |
| 42 |
|
| 43 |
}; // class unique_tempfilename |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
} // namespace IO |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
} // namespace MPT_INLINE_NS |
| 52 |
} // namespace mpt |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#endif // MPT_IO_FILE_UNIQUE_UNIQUE_TEMPFILENAME_HPP |