读写磁盘文件的类 更多...
#include <sttnet.h>
Public 成员函数 | |
| bool | openFile (const std::string &fileName, const bool &create=true, const int &multiple=0, const size_t &size=0, const mode_t &mode=0666) |
| 打开文件 更多... | |
| bool | closeFile (const bool &del=false) |
| 关闭已打开了的文件 更多... | |
| ~File () | |
| 析构函数 更多... | |
| bool | isOpen () |
| 判断对象是否打开了文件 更多... | |
| bool | isBinary () |
| 判断对象是否以二进制模式打开文件 更多... | |
| std::string | getFileName () |
| 获取打开的文件名字 更多... | |
| uint64_t | getFileLine () |
| 获取打开的文件的行数 更多... | |
| size_t | getFileSize () |
| 获取二进制打开的文件的大小 更多... | |
| size_t | getSize1 () |
| 获取二进制打开的文件在内存中的大小 更多... | |
| bool | lockMemory () |
| 把数据从磁盘读入内存 更多... | |
| bool | unlockMemory (const bool &rec=false) |
| 把数据从内存写入磁盘 更多... | |
操作内存中的数据的函数-文本模式 | |
| int | findC (const std::string &targetString, const int linePos=1) |
| 查找行 更多... | |
| bool | appendLineC (const std::string &data, const int &linePos=0) |
| 插入行 更多... | |
| bool | deleteLineC (const int &linePos=0) |
| 删除行 更多... | |
| bool | deleteAllC () |
| 删除全部 更多... | |
| bool | chgLineC (const std::string &data, const int &linePos=0) |
| 修改行 更多... | |
| bool | readLineC (std::string &data, const int linePos) |
| 读取单行 更多... | |
| std::string & | readC (std::string &data, const int &linePos, const int &num) |
| 读取行 更多... | |
| std::string & | readAllC (std::string &data) |
| 读取全部 更多... | |
操作内存中的数据的函数-二进制模式 | |
| bool | readC (char *data, const size_t &pos, const size_t &size) |
| 读取数据块 更多... | |
| bool | writeC (const char *data, const size_t &pos, const size_t &size) |
| 写数据块 更多... | |
| void | formatC () |
| 格式化数据 更多... | |
直接操作磁盘数据的函数-文本模式 | |
| int | find (const std::string &targetString, const int linePos=1) |
| 查找行 更多... | |
| bool | appendLine (const std::string &data, const int &linePos=0) |
| 插入行 更多... | |
| bool | deleteLine (const int &linePos=0) |
| 删除行 更多... | |
| bool | deleteAll () |
| 删除全部 更多... | |
| bool | chgLine (const std::string &data, const int &linePos=0) |
| 修改行 更多... | |
| bool | readLine (std::string &data, const int linePos) |
| 读取单行 更多... | |
| std::string & | read (std::string &data, const int &linePos, const int &num) |
| 读取行 更多... | |
| std::string & | readAll (std::string &data) |
| 读取全部 更多... | |
直接操作磁盘数据的函数-二进制模式 | |
| bool | read (char *data, const size_t &pos, const size_t &size) |
| 读取数据块 更多... | |
| bool | write (const char *data, const size_t &pos, const size_t &size) |
| 写数据块 更多... | |
| void | format () |
| 格式化数据 更多... | |
Protected 属性 | |
| std::mutex | che |
静态 Protected 属性 | |
| static std::mutex | l1 |
| static std::unordered_map < std::string, FileThreadLock > | fl2 |
读写磁盘文件的类
|
inline |
析构函数
| bool stt::file::File::appendLine | ( | const std::string & | data, |
| const int & | linePos = 0 |
||
| ) |
插入行
| data | 需要插入的数据 |
| linePos | 在指定行插入(默认从末尾插入) |
| bool stt::file::File::appendLineC | ( | const std::string & | data, |
| const int & | linePos = 0 |
||
| ) |
插入行
| data | 需要插入的数据 |
| linePos | 在指定行插入(默认从末尾插入) |
| bool stt::file::File::chgLine | ( | const std::string & | data, |
| const int & | linePos = 0 |
||
| ) |
修改行
| data | 覆盖到指定行的数据 |
| linePos | 需要覆盖的行(默认最后一行) |
| bool stt::file::File::chgLineC | ( | const std::string & | data, |
| const int & | linePos = 0 |
||
| ) |
修改行
| data | 覆盖到指定行的数据 |
| linePos | 需要覆盖的行(默认最后一行) |
| bool stt::file::File::closeFile | ( | const bool & | del = false | ) |
关闭已打开了的文件
关闭文件
| del | true:删除文件 false:不删除文件 (默认为false) |
| bool stt::file::File::deleteAll | ( | ) |
删除全部
| bool stt::file::File::deleteAllC | ( | ) |
删除全部
| bool stt::file::File::deleteLine | ( | const int & | linePos = 0 | ) |
删除行
| linePos | 需要删除的行 |
| bool stt::file::File::deleteLineC | ( | const int & | linePos = 0 | ) |
删除行
| linePos | 需要删除的行 |
| int stt::file::File::find | ( | const std::string & | targetString, |
| const int | linePos = 1 |
||
| ) |
查找行
| targetString | 需要查找的字符串 |
| linePos | 从指定行开始寻找(默认从第一行开始) |
| int stt::file::File::findC | ( | const std::string & | targetString, |
| const int | linePos = 1 |
||
| ) |
查找行
| targetString | 需要查找的字符串 |
| linePos | 从指定行开始寻找(默认从第一行开始) |
| void stt::file::File::format | ( | ) |
格式化数据
| void stt::file::File::formatC | ( | ) |
格式化数据
|
inline |
获取打开的文件的行数
|
inline |
获取打开的文件名字
|
inline |
获取二进制打开的文件的大小
|
inline |
获取二进制打开的文件在内存中的大小
|
inline |
判断对象是否以二进制模式打开文件
|
inline |
判断对象是否打开了文件
| bool stt::file::File::lockMemory | ( | ) |
把数据从磁盘读入内存
| bool stt::file::File::openFile | ( | const std::string & | fileName, |
| const bool & | create = true, |
||
| const int & | multiple = 0, |
||
| const size_t & | size = 0, |
||
| const mode_t & | mode = 0666 |
||
| ) |
打开文件
| fileName | 打开文件的名字(可以用绝对路径或者相对路径) |
| create | true:当文件不存在的时候创建文件(以及目录) false:当文件不存在的时候不创建文件 (默认为true) |
| multiple | 当>=1的时候启用二进制打开文件,这个值为需要操作文件所需的预定的文件空间大小和原文件大小的比值 当<1的时候采用文本模式打开文件 (默认为0 文本模式打开) |
| size | 当文件大小为0且参数multiple启用了二进制打开时,因为0和任何倍数都等于0,所以参数multiple会失效。这时候需要手动填入所需的预定文件空间的大小 (单位字节)(默认为0) |
| mode | 如果create为true,且文件不存在,用位掩码表示新建文件的权限(默认为0666 rw- rw- rw-) |
示例代码 1: 文本模式打开和程序同一路径下名为"test"的文件
示例代码 2: 二进制模式下打开和程序同一路径下名为"test"的文件,计划只读
示例代码 3: 二进制模式下打开和程序同一路径下名为"test"的文件,预计会写入数据,写入后大小不大于原来文件大小的两倍
示例代码 4: 二进制模式下打开和程序同一路径下名为"test"的文件,预计会写入数据,写入大小不大于1024字节,原文件大小为0
| std::string& stt::file::File::read | ( | std::string & | data, |
| const int & | linePos, | ||
| const int & | num | ||
| ) |
读取行
| data | 接收数据的字符串容器 |
| linePos | 读取的起始位置 |
| num | 读取的行的数量 |
| bool stt::file::File::read | ( | char * | data, |
| const size_t & | pos, | ||
| const size_t & | size | ||
| ) |
读取数据块
| data | 接收数据的容器 |
| pos | 数据起始位置 |
| size | 数据块大小 |
| std::string& stt::file::File::readAll | ( | std::string & | data | ) |
读取全部
| data | 接收数据的字符串容器 |
| std::string& stt::file::File::readAllC | ( | std::string & | data | ) |
读取全部
| data | 接收数据的字符串容器 |
| std::string& stt::file::File::readC | ( | std::string & | data, |
| const int & | linePos, | ||
| const int & | num | ||
| ) |
读取行
| data | 接收数据的字符串容器 |
| linePos | 读取的起始位置 |
| num | 读取的行的数量 |
| bool stt::file::File::readC | ( | char * | data, |
| const size_t & | pos, | ||
| const size_t & | size | ||
| ) |
读取数据块
| data | 接收数据的容器 |
| pos | 数据起始位置 |
| size | 数据块大小 |
| bool stt::file::File::readLine | ( | std::string & | data, |
| const int | linePos | ||
| ) |
读取单行
| data | 接收数据的字符串容器 |
| linePos | 读取的行 |
| bool stt::file::File::readLineC | ( | std::string & | data, |
| const int | linePos | ||
| ) |
读取单行
| data | 接收数据的字符串容器 |
| linePos | 读取的行 |
| bool stt::file::File::unlockMemory | ( | const bool & | rec = false | ) |
把数据从内存写入磁盘
| rec | false 不回退操作,把操作结果保存入磁盘; true 回退操作,不保存。(默认为false 不需要回退)。 |
| bool stt::file::File::write | ( | const char * | data, |
| const size_t & | pos, | ||
| const size_t & | size | ||
| ) |
写数据块
| data | 装着写入数据的容器 |
| pos | 写入位置 |
| size | 写入数据块大小 |
| bool stt::file::File::writeC | ( | const char * | data, |
| const size_t & | pos, | ||
| const size_t & | size | ||
| ) |
写数据块
| data | 装着写入数据的容器 |
| pos | 写入位置 |
| size | 写入数据块大小 |
|
protected |
|
staticprotected |
|
staticprotected |
1.8.5