1#ifndef MSTL_CORE_FILE_TEMP_FILE_HPP__
2#define MSTL_CORE_FILE_TEMP_FILE_HPP__
6class MSTL_API temp_file {
8 enum class DELETE_POLICY {
15 const string& prefix =
"tmp",
const string& suffix =
".tmp",
16 FILE_CREATION mode = FILE_CREATION::CREATE_FORCE,
17 DELETE_POLICY policy = DELETE_POLICY::AUTO_DELETE
21 const path& existing_path,
22 DELETE_POLICY policy = DELETE_POLICY::AUTO_DELETE
27 temp_file(
const temp_file&) =
delete;
28 temp_file& operator =(
const temp_file&) =
delete;
29 temp_file(temp_file&& other)
noexcept;
30 temp_file& operator =(temp_file&& other)
noexcept;
32 _MSTL file& file() noexcept {
return file_; }
33 const _MSTL file& file() const noexcept {
return file_; }
35 void keep() noexcept { delete_policy_ = DELETE_POLICY::KEEP_ON_EXIT; }
36 void set_delete_policy(
const DELETE_POLICY policy)
noexcept { delete_policy_ = policy; }
37 DELETE_POLICY delete_policy() const noexcept {
return delete_policy_; }
42 static temp_file create_temp_file(
43 const string& prefix =
"tmp",
44 const string& suffix =
".tmp",
45 FILE_CREATION mode = FILE_CREATION::CREATE_FORCE
48 static void cleanup_all_temp_files();
49 static void register_for_cleanup(
const path& temp_path);
53 DELETE_POLICY delete_policy_ = DELETE_POLICY::AUTO_DELETE;
55 static vector<path>& get_temp_registry();
56 static mutex& get_registry_mutex();
58 static path generate_unique_path(
const string& prefix,
const string& suffix);
@ release
释放操作,确保前面的读写不会被重排到后面
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL