====== IOFile ====== **//Inherited from//** NULL **//Inherited by//** NULL **//Friend class//** NULL **//Description//** IOFile封装了文件IO的操作,支持大于2GB的大文件的读入写出,IOFile支持二进制和文本格式的读入写出,对于文本格式,IOFile还提供了缓存模式,可以大幅提高文件IO的性能。除此之外,针对XT系统的应用,IOFile还提供了二进制数据块的校验功能(startBlock、endBlock、readBlockHeader和assertBlock),根据XT系统的文本文件格式,提供了方便的读入写出函数。 **//Members//** * Path [[iofile#m_strpath|m_strPath]] * void* [[iofile#m_pfp|m_pFp]] * int64 [[iofile#m_lisize|m_liSize]] * char * [[iofile#m_pbuf|m_pBuf]] * int [[iofile#m_ibufsize|m_iBufSize]] **//Public interface//** * [[iofile#iofile1|IOFile]](const char * path = 0) * bool [[iofile#open|open]](IOFlag f) * bool [[iofile#isend|isEnd]]() * void [[iofile#close|close]]() * int64 [[iofile#size|size]]() * void [[iofile#writebinary|writeBinary]](void * data,int size) * void [[iofile#readbinary|readBinary]](void * data,int size) * void [[iofile#writechar|writeChar]](char c) * char [[iofile#readchar|readChar]]() * void [[iofile#writetext|writeText]](const char * data) * void [[iofile#readtext|readText]](const char * data) * void [[iofile#setpath|setPath]](const char * path) * int64 [[iofile#getcurpos|getCurPos]]() * void [[iofile#setpos|setPos]](int64 pos) * const char * [[iofile#getpath|getPath]]() * BlockHeader * [[iofile#getheader|getHeader]](bool bKeepPos = true) * DBVersion * [[iofile#getversion|getVersion]](bool bKeepPos = true) * void [[iofile#startblock|startBlock]](BlockHeader & header,bool bAuto = true) * void [[iofile#endblock|endBlock]](BlockHeader & header,bool bAuto = true) * ErrorCode [[iofile#readblockheader|readBlockHeader]](BlockHeader & header) * void [[iofile#assertblock|assertBlock]](BlockHeader & header) * void [[iofile#skipblock|skipBlock]]() * int [[iofile#readint|readInt]]() * double [[iofile#readdouble|readDouble]]() * char * [[iofile#readname|readName]](char * str = 0) * void [[iofile#writeint|writeInt]](int v) * void [[iofile#writedouble|writeDouble]](double v) * void [[iofile#writename|writeName]](char * str) * char * [[iofile#readkeyword|readKeyword]]() * bool [[iofile#isnextkeyword|isNextKeyword]](const char * key = 0) * int [[iofile#readtextint|readTextInt]]() * double [[iofile#readtextdouble|readTextDouble]]() * bool [[iofile#readtextbool|readTextBool]]() * void [[iofile#writetextint|writeTextInt]](int v) * void [[iofile#writetextdouble|writeTextDouble]](double v) * void [[iofile#writetextbool|writeTextBool]](bool v) * void [[iofile#writekeyword|writeKeyword]](char * v) * void [[iofile#nextline|nextLine]]() * void [[iofile#skipline|skipLine]]() * void [[iofile#readpath|readPath]](char * path) * void [[iofile#skipwhite|skipWhite]]() * void [[iofile#skipcomment|skipComment]]() * void [[iofile#showprogress|showProgress]]() * void [[iofile#enablebuffer|enableBuffer]](int size) * void [[iofile#disablebuffer|disableBuffer]]() * void [[iofile#resetbuffer|resetBuffer]]() * void [[iofile#flushbuffer|flushBuffer]]() * IOFile & operator [[iofile#<<|<<]] (double v) * IOFile & operator [[iofile#<<|<<]] (int v) * IOFile & operator [[iofile#<<|<<]] (ulong v) * IOFile & operator [[iofile#<<|<<]] (bool v) * IOFile & operator [[iofile#<<|<<]] (char * keyword) * IOFile & operator [[iofile#<<|<<]] (IOCharacter c) * IOFile & operator [[iofile#>>|>>]] (double& v) * IOFile & operator [[iofile#>>|>>]] (int& v) * IOFile & operator [[iofile#>>|>>]] (ulong& v) * IOFile & operator [[iofile#>>|>>]] (bool& v) * IOFile & operator [[iofile#>>|>>]] (char * keyword) * IOFile & operator [[iofile#>>|>>]] (IOCharacter c) * void [[iofile#pumpbuffer|pumpBuffer]]() ---- {{anchor:m_strpath}} **Path m_strPath** IOFile读入或者写出的文件路径 {{anchor:m_pfp}} **void* m_pFp** IOFile操作的目标文件指针 {{anchor:m_lisize}} **int64 m_liSize** 文件大小,一般用于显示文件读入或者写出进度 {{anchor:m_pbuf}} **char * m_pBuf** 缓存模式时,缓存空间的地址 {{anchor:m_ibufsize}} **int m_iBufSize** 缓存模式时缓存空间的大小 ---- {{anchor:iofile1}} **IOFile(const char * path = 0)** *function: 构造IOFile *parameters: - [i]const char * path = 0: 文件路径 *return value: 无 {{anchor:open}} **bool open(IOFlag f)** *function: 设置文件读写模式并打开文件,此时m_pFp将被赋予一个有效文件指针 *parameters: - [i]IOFlag f: 文件模式,支持四种:二进制读入、二进制写出、文本读入、文本写出 *return value: 打开文件成功则返回true,否则返回false {{anchor:isend}} **bool isEnd()** *function: 当读入文件时,判断是否到文件结束位置 *parameters: NULL *return value: 到达文件结束位置返回true,否则返回false {{anchor:close}} **void close()** *function: 关闭文件,重置文件指针m_pFp *parameters: NULL *return value: 无 {{anchor:size}} **int64 size()** *function: 当读入文件时,获取文件大小 *parameters: NULL *return value: 文件大小 {{anchor:writebinary}} **void writeBinary(void * data,int size)** *function: 二进制写出时,将大小为size的数据块data写出 *parameters: - [i]void * data: 数据块地址 - [i]int size: 数据块大小 *return value: 无 {{anchor:readbinary}} **void readBinary(void * data,int size)** *function: 二进制读入时,读入大小为size的数据块到内存data中 *parameters: - [i]void * data: 有效内存空间 - [i]int size: 读入的数据块大小 *return value: 无 {{anchor:writechar}} **void writeChar(char c)** *function: 二进制写出时,写出一个字节 *parameters: - [i]char c: 待写出的字节 *return value: 无 {{anchor:readchar}} **char readChar()** *function: 二进制读入时,读入一个字节 *parameters: NULL *return value: 读入的字节 {{anchor:writetext}} **void writeText(const char * data)** *function: 文本格式输出时,输出字符串 *parameters: - [i]const char * data: 输出的字符串 *return value: 无 {{anchor:readtext}} **void readText(const char * data)** *function: 文本格式读入时,读入字符串到内存空间data中 *parameters: - [i]const char * data: 放置字符串的内存空间 *return value: 无 {{anchor:setpath}} **void setPath(const char * path)** *function: 重新设置文件路径 *parameters: - [i]const char * path: 文件路径字符串 *return value: 无 {{anchor:getcurpos}} **int64 getCurPos()** *function: 获取文件当前的位置 *parameters: NULL *return value: 文件当前的位置 {{anchor:setpos}} **void setPos(int64 pos)** *function: 设置文件当前位置到pos *parameters: - [i]int64 pos: 文件的目标位置 *return value: 无 {{anchor:getpath}} **const char * getPath()** *function: 获取文件路径 *parameters: NULL *return value: 文件路径 {{anchor:getheader}} **BlockHeader * getHeader(bool bKeepPos = true)** *function: 获取二进制数据块的块头结构 *parameters: - [i]bool bKeepPos = true: 若保持位置,则读出一个块头结构之后将文件当前位置回位到读出之前的位置,否则将在读出之后的位置 *return value: 读出的块头结构指针 {{anchor:getversion}} **DBVersion * getVersion(bool bKeepPos = true)** *function: 获取二进制数据的块头结构的版本信息 *parameters: - [i]bool bKeepPos = true: 若保持位置,则读出一个版本信息之后将文件当前位置回位到读出之前的位置,否则将在读出之后的位置 *return value: 读出的版本信息结构体指针 {{anchor:startblock}} **void startBlock(BlockHeader & header,bool bAuto = true)** *function: 二进制写出模式时,开始一个数据块的输出 *parameters: - [i]BlockHeader & header: 数据块的块头结构 - [i]bool bAuto = true: 若为true,则在结束数据块输出时(endblock)自动计算该数据块的大小;否则由调用者自己计算大小 *return value: 无 {{anchor:endblock}} **void endBlock(BlockHeader & header,bool bAuto = true)** *function: 二进制文件写出时,结束一个数据块的输出 *parameters: - [i]BlockHeader & header: 数据块的块头结构 - [i]bool bAuto = true: 若为真,则自动计算数据块的大小; *return value: 无 {{anchor:readblockheader}} **ErrorCode readBlockHeader(BlockHeader & header)** *function: 二进制文件读入时,开始读入数据块的块头结构。注意,该函数一般与assertBlock配套使用 *parameters: - [i]BlockHeader & header: 块头结构 *return value: 根据实际情况返回错误编码,若没有错误返回Error_None {{anchor:assertblock}} **void assertBlock(BlockHeader & header)** *function: 二进制文件读入时,结束读入数据块,并对数据块大小进行校验 *parameters: - [i]BlockHeader & header: 数据块的块头信息 *return value: 无 {{anchor:skipblock}} **void skipBlock()** *function: 二进制文件读入时,根据数据块的大小信息略过该数据块 *parameters: NULL *return value:无 {{anchor:readint}} **int readInt()** *function: 二进制文件读入时,读入一个整型数 *parameters: NULL *return value: 读入的整型值 {{anchor:readdouble}} **double readDouble()** *function: 二进制文件读入时,读入一个浮点数 *parameters: NULL *return value: 读入的浮点数值 {{anchor:readname}} **char * readName(char * str = 0)** *function: 二进制文件读入时,读入一个名字(为MAX_NAME_LENGTH大小) *parameters: - [i]char * str = 0: 存放名字的内存空间,可为空 *return value: 若存放名字的内存空间为空,则返回读入的名字地址 {{anchor:writeint}} **void writeInt(int v)** *function: 二进制文件写出时,写出一个整型数 *parameters: - [i]int v: 写出的整型数 *return value: 无 {{anchor:writedouble}} **void writeDouble(double v)** *function: 二进制文件写出时,写出一个浮点数 *parameters: - [i]double v: 写出的浮点数 *return value: 无 {{anchor:writename}} **void writeName(char * str)** *function: 二进制文件写出时,写出一个名字 *parameters: - [i]char * str: 写出的名字 *return value: 无 {{anchor:readkeyword}} **char * readKeyword()** *function: 文本格式读入时,读入一个关键字(大小为32个字节) *parameters: NULL *return value: 关键字字符串 {{anchor:isnextkeyword}} **bool isNextKeyword(const char * key = 0)** *function: 文本格式读入时,判断下面是否为指定的关键字 *parameters: - [i]const char * key = 0: 待匹配的关键字,若为0,则匹配任意关键字 *return value: 若匹配成功,则返回true,否则返回false; {{anchor:readtextint}} **int readTextInt()** *function: 文本格式读入时,读入一个整型数(12个字节大小) *parameters: NULL *return value: 读入的整型数值 {{anchor:readtextdouble}} **double readTextDouble()** *function: 文本格式读入时,读入一个浮点数(18个字节大小) *parameters: NULL *return value: 读入的浮点数值 {{anchor:readtextbool}} **bool readTextBool()** *function: 文本格式读入时,读入一个bool变量(%-8s) *parameters: NULL *return value: 若为“true”则返回true,否则返回false {{anchor:writetextint}} **void writeTextInt(int v)** *function: 文本格式写出时,写出一个整型数(%12d) *parameters: - [i]int v: 整型数 *return value:无 {{anchor:writetextdouble}} **void writeTextDouble(double v)** *function: 文本格式写出时,写出一个浮点数(%18.9e) *parameters: - [i]double v: 浮点数 *return value: 无 {{anchor:writetextbool}} **void writeTextBool(bool v)** *function: 文本格式写出时,写出一个bool值(%-8s) *parameters: - [i]bool v: 若v为true,写出“true”,否则写出“false” *return value: 无 {{anchor:writekeyword}} **void writeKeyword(char * v)** *function: 文本格式写出时写出一个关键字(@%31s) *parameters: - [i]char * v: 关键字字符串 *return value: 无 {{anchor:nextline}} **void nextLine()** *function: 文本格式写出时,开始新的一行 *parameters: NULL *return value: 无 {{anchor:skipline}} **void skipLine()** *function: 文本格式读入时,略过一行 *parameters: NULL *return value: 无 {{anchor:readpath}} **void readPath(char * path)** *function: 文本格式读入时,读入文本路径,最大为MAX_PATH_LENGTH. *parameters: - [i]char * path: 放置文本路径的内存地址 *return value: 无 {{anchor:skipwhite}} **void skipWhite()** *function: 略过空白字符(回车符、制表符和空格) *parameters: NULL *return value: 无 {{anchor:skipcomment}} **void skipComment()** *function: 文本格式读入时,略过注释 *parameters: NULL *return value: 无 {{anchor:showprogress}} **void showProgress()** *function: 向主框架通知当前的读入/写出进度信息,当写出时,需预先计算写出的文件大小 *parameters: NULL *return value: 无 {{anchor:enablebuffer}} **void enableBuffer(int size)** *function: 开启缓存模式并分配缓存空间,仅在文本格式时有效 *parameters: - [i]int size: 缓存空间大小 *return value: 无 {{anchor:disablebuffer}} **void disableBuffer()** *function: 关闭缓存模式 *parameters: NULL *return value: 无 {{anchor:resetbuffer}} **void resetBuffer()** *function: 读入数据内容到缓存空间中 *parameters: NULL *return value: 无 {{anchor:flushbuffer}} **void flushBuffer()** *function: 将缓存空间内容一次性写出到文件中 *parameters: NULL *return value: 无 {{anchor:<<}} **IOFile & operator << (double v)** *function: 读入文本浮点数的简化函数,同[[iofile#writetextdouble|writeTextDouble]] *parameters: - [i]double v: 浮点数 *return value: 当前IOFile的引用 {{anchor:<<}} **IOFile & operator << (int v)** *function: 同[[iofile#writetextint|writeTextInt]] *parameters: - [i]int v: 整数 *return value: 当前IOFile的引用 {{anchor:<<}} **IOFile & operator << (ulong v)** *function: 同[[iofile#writetextint|writeTextInt]] *parameters: - [i]ulong v: 无符号整数值 *return value: 当前IOFile的引用 {{anchor:<<}} **IOFile & operator << (bool v)** *function: 同[[iofile#writetextbool|writeTextBool]] *parameters: - [i]bool v: bool值 *return value: 当前IOFile的引用 {{anchor:<<}} **IOFile & operator << (char * keyword)** *function: 同[[iofile#writekeyword|writeKeyword]] *parameters: - [i]char * keyword: 关键字字符串,最长31个字符 *return value: 当前IOFile的引用 {{anchor:<<}} **IOFile & operator << (IOCharacter c)** *function: 文本输出模式时,输出特殊字符。目前只支持NewLine,等同于[[iofile#nextline|nextLine]] *parameters: - [i]IOCharacter c: 特殊字符,目前只支持NewLine *return value: 当前IOFile的引用 {{anchor:>>}} **IOFile & operator >> (double& v)** *function: 文本读入模式时,读入浮点数,同[[iofile#readtextdouble|readTextDouble]] *parameters: - [i]double& v: 读入的浮点数将赋值到v上 *return value: 当前IOFile的引用 {{anchor:>>}} **IOFile & operator >> (int& v)** *function: 文本读入模式时,读入整数,同[[iofile#readtextint|readTextInt]] *parameters: - [i]int& v: 读入的整型数将赋值到v上 *return value: 当前IOFile的引用 {{anchor:>>}} **IOFile & operator >> (ulong& v)** *function: 文本读入模式时,读入无符号整数 *parameters: - [i]ulong& v: 读入的无符号整数将赋值到v上 *return value: 当前IOFile的引用 {{anchor:>>}} **IOFile & operator >> (bool& v)** *function: 文本读入模式时,读入bool值,同[[iofile#readtextdouble|readTextDouble]] *parameters: - [i]bool& v: 读入的bool值将赋值到v上 *return value: 当前IOFile的引用 {{anchor:>>}} **IOFile & operator >> (char * keyword)** *function: 文本读入模式时,读入关键字,同[[iofile#readtextdouble|readTextDouble]] *parameters: - [i]char * keyword: 读入的关键字将放到keyword中,最长31个有效字符 *return value: 当前IOFile的引用 {{anchor:>>}} **IOFile & operator >> (IOCharacter c)** *function: 文本读入模式时,读入特殊字符。目前只支持NewLine,等同于[[iofile#skipline|skipLine]] *parameters: - [i]IOCharacter c: 特殊字符 *return value: 当前IOFile的引用 {{anchor:pumpbuffer}} **void pumpBuffer()** *function: 从文件中读入新的内容到缓存空间中 *parameters: NULL *return value: 无