|
Console Library 8.0.0
A header-only library that makes C++ simple
|
文件路径封装类,提供便捷的文件读写和路径操作。 More...
#include <file.h>
Public Types | |
| using | Bytes = std::vector<unsigned char> |
| 字节向量类型 | |
Public Member Functions | |
| BasicPath (const CharT *str) | |
| 构造函数,接受一个字符指针作为路径字符串。 | |
| BasicPath (const string_type &str) | |
| 构造函数,接受一个字符串作为路径字符串。 | |
| BasicPath & | operator/= (const BasicPath &p) |
| 重载运算符,用于路径拼接。 | |
| string_type | read_text () const |
| 读取文本文件内容。 | |
| Bytes | read_binary () const |
| 读取二进制文件内容。 | |
| std::vector< string_type > | read_lines () const |
| 读取文本文件的行内容。 | |
| template<class T> | |
| T | read_POD () const |
| 读取 POD 类型数据。 | |
| template<class T> | |
| T | unsafe_read_POD () const |
| 读取 POD 类型数据(不安全)。 | |
| void | write_text (const string_type &text) const |
| 写入文本内容。 | |
| void | write_binary (const Bytes &bts) const |
| 写入二进制内容。 | |
| void | write_lines (const std::vector< string_type > &lines) const |
| 写入行内容。 | |
| template<class T> | |
| void | write_POD (const T &data) const |
| 写入 POD 类型数据。 | |
| template<class T> | |
| void | unsafe_write_POD (const T &data) const |
| 写入 POD 类型数据(不安全)。 | |
| bool | exists () const |
| 判断文件是否存在。 | |
| void | touch () const |
| 创建文件(若不存在)。 | |
| void | ensure () const |
| 确保文件存在(若不存在则创建)。 | |
| void | remove () const |
| 删除文件(若存在)。 | |
| const string_type & | str () const |
| 获取文件路径字符串。 | |
| std::fstream | stream (std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) const |
| 以指定模式打开文件流。 | |
Private Types | |
| using | string_type = std::basic_string<CharT> |
| 字符串类型 | |
Private Member Functions | |
| std::string | narrow () const |
| 将宽字符路径转换为窄字符路径。 | |
Static Private Member Functions | |
| template<class T = CharT> | |
| static std::enable_if< std::is_same< T, char >::value, string_type >::type | widen_or_pass (const std::string &s) |
| 根据字符类型选择宽字符或窄字符转换函数。 | |
| template<class T = CharT> | |
| static std::enable_if< std::is_same< T, wchar_t >::value, string_type >::type | widen_or_pass (const std::string &s) |
| 根据字符类型选择宽字符或窄字符转换函数。 | |
| template<class T = CharT> | |
| static std::enable_if< std::is_same< T, char >::value, void >::type | write_to_stream (std::ofstream &fout, const string_type &text) |
| 根据字符类型选择宽字符或窄字符转换函数。 | |
| template<class T = CharT> | |
| static std::enable_if< std::is_same< T, wchar_t >::value, void >::type | write_to_stream (std::ofstream &fout, const string_type &text) |
| 根据字符类型选择宽字符或窄字符转换函数。 | |
Private Attributes | |
| string_type | path |
| 路径字符串 | |
Friends | |
| BasicPath | operator/ (const BasicPath &p1, const BasicPath &p2) |
| 重载运算符,用于路径拼接。 | |
文件路径封装类,提供便捷的文件读写和路径操作。
| CharT | 字符类型(char 或 wchar_t)。 |
| using console::BasicPath< CharT >::Bytes = std::vector<unsigned char> |
字节向量类型
|
private |
字符串类型
|
inline |
构造函数,接受一个字符指针作为路径字符串。
| str | 路径字符串。 |
|
inline |
构造函数,接受一个字符串作为路径字符串。
| str | 路径字符串。 |
|
inline |
确保文件存在(若不存在则创建)。
|
inline |
判断文件是否存在。
|
inlineprivate |
将宽字符路径转换为窄字符路径。
|
inline |
重载运算符,用于路径拼接。
| p | 路径字符串。 |
|
inline |
读取二进制文件内容。
|
inline |
读取文本文件的行内容。
|
inline |
读取 POD 类型数据。
|
inline |
读取文本文件内容。
|
inline |
删除文件(若存在)。
|
inline |
获取文件路径字符串。
|
inline |
以指定模式打开文件流。
| mode | 打开模式,默认为 std::ios_base::in | std::ios_base::out。 |
|
inline |
创建文件(若不存在)。
|
inline |
读取 POD 类型数据(不安全)。
|
inline |
写入 POD 类型数据(不安全)。
| data | 数据。 |
|
inlinestaticprivate |
根据字符类型选择宽字符或窄字符转换函数。
| s | 字符串。 |
|
inlinestaticprivate |
根据字符类型选择宽字符或窄字符转换函数。
| s | 字符串。 |
|
inline |
写入二进制内容。
| bts | 二进制内容。 |
|
inline |
写入行内容。
| lines | 行内容列表。 |
|
inline |
写入 POD 类型数据。
| data | 数据。 |
|
inline |
写入文本内容。
| text | 文本内容。 |
|
inlinestaticprivate |
根据字符类型选择宽字符或窄字符转换函数。
| fout | 输出流。 |
| text | 字符串。 |
|
inlinestaticprivate |
根据字符类型选择宽字符或窄字符转换函数。
| fout | 输出流。 |
| text | 字符串。 |
|
friend |
重载运算符,用于路径拼接。
| p1 | 路径字符串。 |
| p2 | 路径字符串。 |
|
private |
路径字符串