MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
temp_file.hpp
1#ifndef MSTL_CORE_FILE_TEMP_FILE_HPP__
2#define MSTL_CORE_FILE_TEMP_FILE_HPP__
3#include "file.hpp"
5
6class MSTL_API temp_file {
7public:
8 enum class DELETE_POLICY {
9 AUTO_DELETE,
10 MANUAL_DELETE,
11 KEEP_ON_EXIT
12 };
13
14 explicit temp_file(
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
18 );
19
20 explicit temp_file(
21 const path& existing_path,
22 DELETE_POLICY policy = DELETE_POLICY::AUTO_DELETE
23 );
24
25 ~temp_file();
26
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;
31
32 _MSTL file& file() noexcept { return file_; }
33 const _MSTL file& file() const noexcept { return file_; }
34
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_; }
38
39 void cleanup();
40 void release();
41
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
46 );
47
48 static void cleanup_all_temp_files();
49 static void register_for_cleanup(const path& temp_path);
50
51private:
52 _MSTL file file_;
53 DELETE_POLICY delete_policy_ = DELETE_POLICY::AUTO_DELETE;
54
55 static vector<path>& get_temp_registry();
56 static mutex& get_registry_mutex();
57
58 static path generate_unique_path(const string& prefix, const string& suffix);
59};
60
62#endif // MSTL_CORE_FILE_TEMP_FILE_HPP__
@ release
释放操作,确保前面的读写不会被重排到后面
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL