|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
文件操作类 更多...
#include <file.hpp>
类 | |
| class | line_iterator |
| 行迭代器 更多... | |
| struct | chunk_info |
| 文件块信息 更多... | |
Public 类型 | |
| using | size_type = size_t |
| 大小类型 | |
| using | difference_type = ::off_t |
| 偏移量类型 | |
| using | native_handle_type = int |
| 原生文件句柄类型 | |
Public 成员函数 | |
| file () | |
| 默认构造函数 | |
| file (path pth, bool append=false, file_access access=file_access::READ_WRITE, file_shared share_mode=file_shared::SHARE_READ, file_creation creation=file_creation::OPEN_EXIST, file_attri attributes=file_attri::NORMAL) | |
| 构造函数(打开文件) | |
| file (file &&other) noexcept | |
| 移动构造函数 | |
| file & | operator= (file &&other) noexcept |
| 移动赋值运算符 | |
| ~file () | |
| 析构函数 | |
| bool | open (path pth, bool append=false, file_access access=file_access::READ_WRITE, file_shared share_mode=file_shared::SHARE_READ_WRITE, file_creation creation=file_creation::OPEN_EXIST, file_attri attributes=file_attri::NORMAL) |
| 打开文件 | |
| bool | open (bool append=false, file_access access=file_access::READ_WRITE, file_shared share_mode=file_shared::SHARE_READ_WRITE, file_creation creation=file_creation::OPEN_EXIST, file_attri attributes=file_attri::NORMAL) |
| 重新打开文件(使用原有路径) | |
| void | close () noexcept |
| 关闭文件 | |
| bool | flush () noexcept |
| 刷新缓冲区 | |
| size_type | write (const string &data, size_type size) |
| 写入数据 | |
| size_type | write (const string &data) |
| 写入字符串 | |
| size_type | write (const void *data, size_type size) |
| 写入二进制数据 | |
| size_type | read (void *buffer, size_type size) const |
| 读取数据到缓冲区 | |
| size_type | read (string &out, size_type size) const |
| 读取数据到字符串 | |
| size_type | read (string &out) const |
| 读取数据到字符串(自动调整大小) | |
| NEFORCE_NODISCARD string | read () const |
| 读取整个文件 | |
| size_type | read_binary (void *out, size_type size) const |
| 读取二进制数据到缓冲区 | |
| size_type | read_binary (string &out, size_type size) const |
| 读取二进制数据到字符串 | |
| size_type | read_binary (string &out) const |
| 读取二进制数据到字符串(自动调整大小) | |
| NEFORCE_NODISCARD string | read_binary () const |
| 读取整个文件(二进制模式) | |
| bool | read_line (string &line) const |
| 读取一行 | |
| NEFORCE_NODISCARD string | read_line () const |
| 读取一行 | |
| NEFORCE_NODISCARD vector< string > | read_lines () const |
| 读取所有行 | |
| vector< string > | read_chunks (size_type chunk_size=buffer_size *16) const |
| 读取文件块 | |
| bool | write_chunks (const vector< string > &chunks) |
| 写入文件块 | |
| NEFORCE_NODISCARD vector< chunk_info > | chunks_info (size_type chunk_size) const |
| 获取块信息 | |
| bool | seek (difference_type distance, file_pointer method=file_pointer::END) const |
| 移动文件指针 | |
| difference_type | tell () const |
| 获取当前文件指针位置 | |
| difference_type | system_tell () const |
| 获取系统文件指针位置 | |
| bool | prefetch (size_type hint_size=0) const |
| 预取数据到缓存 | |
| bool | truncate (difference_type size) const |
| 截断文件 | |
| NEFORCE_NODISCARD size_type | size () const |
| 获取文件大小 | |
| bool | size (size_type &out_size) const |
| 获取文件大小 | |
| NEFORCE_NODISCARD uint64_t | size64 () const |
| 获取文件大小 | |
| NEFORCE_NODISCARD native_handle_type | native_handle () const noexcept |
| 获取原生文件句柄 | |
| NEFORCE_NODISCARD const path & | file_path () const noexcept |
| 获取文件路径 | |
| NEFORCE_NODISCARD bool | is_opened () const noexcept |
| 检查文件是否已打开 | |
| NEFORCE_NODISCARD bool | is_append () const noexcept |
| 检查是否为追加模式 | |
| NEFORCE_NODISCARD const error_code & | last_error_code () const noexcept |
| 获取最后错误码 | |
| void | clear_error () noexcept |
| 清除错误状态 | |
| NEFORCE_NODISCARD line_iterator | begin_lines () const |
| 获取行迭代器起始 | |
| NEFORCE_NODISCARD line_iterator | end_lines () const |
| 获取行迭代器结束 | |
| NEFORCE_NODISCARD file_mapper & | mapper () noexcept |
| 获取内存映射对象 | |
| NEFORCE_NODISCARD file_locker & | locker () noexcept |
| 获取文件锁对象 | |
| NEFORCE_NODISCARD file_info & | info () noexcept |
| 获取文件信息对象 | |
| NEFORCE_NODISCARD file_async & | async () noexcept |
| 获取异步I/O对象 | |
静态 Public 属性 | |
| static constexpr size_t | buffer_size = 8192 |
| 文件操作缓冲区大小 | |
文件操作类
支持移动语义,不支持拷贝,线程安全
主要特性:
线程安全,支持移动语义,不支持拷贝。
| file::file | ( | ) |
默认构造函数
创建未打开的文件对象。
引用了 file().
被这些函数引用 file(), file(), file(), file::line_iterator::line_iterator(), operator=() , 以及 ~file().
|
explicit |
构造函数(打开文件)
| pth | 文件路径 |
| append | 是否为追加模式,默认为false |
| access | 访问模式,默认为读写 |
| share_mode | 共享模式,默认为只读共享 |
| creation | 创建方式,默认为打开已存在文件 |
| attributes | 文件属性,默认为普通 |
创建并打开文件。
引用了 file().
| file::~file | ( | ) |
|
inlinenoexcept |
|
inline |
| NEFORCE_NODISCARD vector< chunk_info > file::chunks_info | ( | size_type | chunk_size | ) | const |
|
inline |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
| bool file::open | ( | bool | append = false, |
| file_access | access = file_access::READ_WRITE, | ||
| file_shared | share_mode = file_shared::SHARE_READ_WRITE, | ||
| file_creation | creation = file_creation::OPEN_EXIST, | ||
| file_attri | attributes = file_attri::NORMAL ) |
重新打开文件(使用原有路径)
| append | 是否为追加模式 |
| access | 访问模式 |
| share_mode | 共享模式 |
| creation | 创建方式 |
| attributes | 文件属性 |
引用了 open().
| bool file::open | ( | path | pth, |
| bool | append = false, | ||
| file_access | access = file_access::READ_WRITE, | ||
| file_shared | share_mode = file_shared::SHARE_READ_WRITE, | ||
| file_creation | creation = file_creation::OPEN_EXIST, | ||
| file_attri | attributes = file_attri::NORMAL ) |
| bool file::prefetch | ( | size_type | hint_size = 0 | ) | const |
预取数据到缓存
| hint_size | 提示预取大小(字节) |
建议操作系统将后续数据预加载到内存,提高顺序访问性能。
引用了 prefetch().
被这些函数引用 prefetch().
| NEFORCE_NODISCARD string file::read_binary | ( | ) | const |
读取二进制数据到缓冲区
| out | 缓冲区指针 |
| size | 要读取的大小 |
引用了 read_binary() , 以及 size().
被这些函数引用 read_binary(), read_binary(), read_binary() , 以及 read_binary().
| vector< string > file::read_chunks | ( | size_type | chunk_size = buffer_size *16 | ) | const |
读取文件块
| chunk_size | 块大小(字节) |
将文件按固定大小分块,适用于流式处理大文件。
引用了 buffer_size , 以及 read_chunks().
被这些函数引用 read_chunks().
| NEFORCE_NODISCARD string file::read_line | ( | ) | const |
| bool file::read_line | ( | string & | line | ) | const |
| bool file::seek | ( | difference_type | distance, |
| file_pointer | method = file_pointer::END ) const |
移动文件指针
| distance | 移动距离(字节) |
| method | 移动方式 |
追加模式下只能seek到文件末尾。
引用了 distance() , 以及 seek().
被这些函数引用 seek().
| NEFORCE_NODISCARD size_type file::size | ( | ) | const |
获取文件大小
引用了 size().
被这些函数引用 read(), read(), read_binary(), read_binary(), size(), size(), truncate(), write() , 以及 write().
| NEFORCE_NODISCARD uint64_t file::size64 | ( | ) | const |
| difference_type file::system_tell | ( | ) | const |
| difference_type file::tell | ( | ) | const |
| bool file::truncate | ( | difference_type | size | ) | const |
截断文件
| size | 新文件大小(字节) |
将文件截断到指定大小,多余数据丢失。 如果新大小大于原文件,文件会扩展(内容未定义)。
引用了 size() , 以及 truncate().
被这些函数引用 truncate().
|
staticconstexpr |