NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
temp_file.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_FILE_TEMP_FILE_HPP__
2#define NEFORCE_CORE_FILE_TEMP_FILE_HPP__
3
11
13NEFORCE_BEGIN_NAMESPACE__
14
20
28class NEFORCE_API temp_file {
29public:
34 enum class delete_policy {
35 AUTO_DELETE,
36 MANUAL_DELETE,
37 KEEP_ON_EXIT
38 };
39
40private:
41 _NEFORCE file file_;
42 delete_policy delete_policy_ = delete_policy::AUTO_DELETE;
43
44public:
56 explicit temp_file(const string& prefix = "tmp", const string& suffix = ".tmp",
59
69
78
79 temp_file(const temp_file&) = delete;
80 temp_file& operator=(const temp_file&) = delete;
81
88 temp_file(temp_file&& other) noexcept;
89
97 temp_file& operator=(temp_file&& other) noexcept;
98
103 NEFORCE_NODISCARD _NEFORCE file& file() noexcept { return file_; }
104
109 NEFORCE_NODISCARD const _NEFORCE file& file() const noexcept { return file_; }
110
116 void keep() noexcept { delete_policy_ = delete_policy::KEEP_ON_EXIT; }
117
122 void set_delete_policy(const delete_policy policy) noexcept { delete_policy_ = policy; }
123
128 NEFORCE_NODISCARD delete_policy policy() const noexcept { return delete_policy_; }
129
138 void cleanup() noexcept;
139
146 void release();
147
157 NEFORCE_NODISCARD static temp_file create_temp_file(const string& prefix = "tmp", const string& suffix = ".tmp",
159
167
175 static void register_for_cleanup(const path& temp_path);
176};
177 // File
179
180NEFORCE_END_NAMESPACE__
181#endif // NEFORCE_CORE_FILE_TEMP_FILE_HPP__
文件操作类
文件路径类
NEFORCE_NODISCARD const _NEFORCE file & file() const noexcept
获取内部常量文件对象
void set_delete_policy(const delete_policy policy) noexcept
设置删除策略
static void register_for_cleanup(const path &temp_path)
注册一个路径以供程序退出时清理
~temp_file()
析构函数
void release()
释放临时文件的所有权
NEFORCE_NODISCARD _NEFORCE file & file() noexcept
获取内部文件对象
void keep() noexcept
设置删除策略为 KEEP_ON_EXIT
static void cleanup_all_temp_files()
清理所有已注册的临时文件
void cleanup() noexcept
手动清理临时文件
static NEFORCE_NODISCARD temp_file create_temp_file(const string &prefix="tmp", const string &suffix=".tmp", file_creation mode=file_creation::CREATE_FORCE)
创建临时文件(工厂函数)
temp_file(temp_file &&other) noexcept
移动构造函数
temp_file(const path &existing_path, delete_policy policy=delete_policy::AUTO_DELETE)
构造函数:接管已有的文件作为临时文件
delete_policy
临时文件删除策略
@ AUTO_DELETE
析构自动删除
@ KEEP_ON_EXIT
程序退出时保留
temp_file(const string &prefix="tmp", const string &suffix=".tmp", file_creation mode=file_creation::CREATE_FORCE, delete_policy policy=delete_policy::AUTO_DELETE)
构造函数:创建新的临时文件
temp_file & operator=(temp_file &&other) noexcept
移动赋值运算符
NEFORCE_NODISCARD delete_policy policy() const noexcept
获取当前删除策略
文件操作类
file_creation
文件创建方式枚举
@ CREATE_FORCE
强制创建新文件(覆盖已存在)