YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
YSLib::File类 参考

文件基类。 更多...

#include <yfile.h>

类 YSLib::File 继承关系图:
YSLib::File 的协作图:

Public 成员函数

 File ()
 构造。
 
 File (const_path_t, const char *="rb")
 构造:使用指定文件路径初始化对象。
 
 File (const_path_t, std::ios_base::openmode)
 
 File (const String &, const ucs2_t *=u"rb")
 
 File (const String &, std::ios_base::openmode)
 
virtual ~File ()
 析构。
 
bool operator! () const ynothrow
 判断无效性。
 
 operator bool () const ynothrow
 判断有效性。
 
FILE * GetPtr () const ynothrow
 取文件指针。
 
size_t GetSize () const ynothrow
 取文件大小。
 
ptrdiff_t GetPosition () const ynothrow
 取文件指针的位置,返回值语义同 std::ftell 。
 
int Seek (ptrdiff_t offset, int whence) const
 设置文件指针位置。
 
int CheckEOF () const
 检测文件结束符。
 
void Close ()
 关闭文件。
 
int Flush () const
 刷新流。
 
size_t Read (void *ptr, size_t size=1U, size_t nmemb=1U) const
 连续读 nmemb 个大小为 size 文件块到 ptr 中。
 
void Rewind () const
 文件指针返回到文件头,语义同 std::rewind 。
 
virtual bool Truncate (size_t) const
 截断文件。
 
size_t Write (void *ptr, size_t size=1U, size_t nmemb=1U) const
 连续写 nmemb 个大小为 size 文件块到 ptr 中。
 
bool Open (const_path_t, const char *="rb")
 以指定方式打开指定路径的文件。
 
bool Open (const_path_t, std::ios_base::openmode)
 
bool Open (const String &, const ucs2_t *=u"rb")
 
bool Open (const String &, std::ios_base::openmode)
 

Private 成员函数

void CheckSize ()
 检查文件有效长度后读位置返回文件起始。
 
- Private 成员函数 继承自 ystdex::noncopyable
 noncopyable (const noncopyable &)=delete
 禁止复制构造。
 
noncopyableoperator= (const noncopyable &)=delete
 禁止赋值复制。
 
 noncopyable ()=default
 protected 构造:默认实现。
 
 ~noncopyable ()=default
 protected 析构:默认实现。
 

Private 属性

std::FILE * fp
 
size_t fsize
 文件大小。
 

详细描述

文件基类。

自从
build 206

在文件 yfile.h41 行定义.

构造及析构函数说明

YSL_BEGIN File::File ( )

构造。

注解
得到空对象。

在文件 yfile.cpp33 行定义.

YSLib::File::File ( const_path_t  ,
const char *  = "rb" 
)
explicit

构造:使用指定文件路径初始化对象。

注解
自动打开文件。
自从
build 326
YSLib::File::File ( const_path_t  ,
std::ios_base::openmode   
)
YSLib::File::File ( const String &  ,
const ucs2_t *  = u"rb" 
)
explicit
YSLib::File::File ( const String &  ,
std::ios_base::openmode   
)
File::~File ( )
virtual

析构。

注解
自动关闭文件。

在文件 yfile.cpp63 行定义.

参考 Close().

函数调用图:

成员函数说明

int YSLib::File::CheckEOF ( ) const
inline

检测文件结束符。

注解
参数和返回值语义同 std::feof()

在文件 yfile.h107 行定义.

参考自 Session::Session().

这是这个函数的调用关系图:

void File::CheckSize ( )
private

检查文件有效长度后读位置返回文件起始。

自从
build 305

在文件 yfile.cpp69 行定义.

参考 fsize,GetPosition(),Rewind() , 以及 Seek().

函数调用图:

void File::Close ( )

关闭文件。

注解
语义同 std::fclose
清除文件指针。

在文件 yfile.cpp77 行定义.

参考 fp.

参考自 ~File().

这是这个函数的调用关系图:

int YSLib::File::Flush ( ) const
inline

刷新流。

返回
若成功则为 0 ,否则为 EOF
注解
语义同 std::fflush
警告
刷新输入流或最近操作为输入的流导致未定义行为。
参见
ISO C11 7.21.5.2 。
自从
build 329

在文件 yfile.h135 行定义.

ptrdiff_t YSLib::File::GetPosition ( ) const
inline

取文件指针的位置,返回值语义同 std::ftell 。

在文件 yfile.h93 行定义.

参考自 CheckSize().

这是这个函数的调用关系图:

size_t YSLib::File::GetSize ( ) const
inline

取文件大小。

在文件 yfile.h89 行定义.

参考自 YSLib::TextFile::CheckBOM().

这是这个函数的调用关系图:

bool YSLib::File::Open ( const_path_t  ,
const char *  = "rb" 
)

以指定方式打开指定路径的文件。

注解
语义同 std::fopen
对于输入 openmode ,使用 ystdex::openmode_conv 转换。
参见
ISO C11 7.21.5.3 。
自从
build 326
bool YSLib::File::Open ( const_path_t  ,
std::ios_base::openmode   
)
bool YSLib::File::Open ( const String &  ,
const ucs2_t *  = u"rb" 
)
bool YSLib::File::Open ( const String &  ,
std::ios_base::openmode   
)
YSLib::File::operator bool ( ) const
inlineexplicit

判断有效性。

自从
build 319

在文件 yfile.h86 行定义.

bool YSLib::File::operator! ( ) const
inline

判断无效性。

自从
build 319

在文件 yfile.h79 行定义.

size_t YSLib::File::Read ( void *  ptr,
size_t  size = 1U,
size_t  nmemb = 1U 
) const
inline

连续读 nmemb 个大小为 size 文件块到 ptr 中。

返回
返回成功读取的文件块数。
注解
语义同 std::fread
参见
ISO C11 7.21.8.1 。
自从
build 290

在文件 yfile.h163 行定义.

参考自 YSLib::TextFile::CheckBOM().

这是这个函数的调用关系图:

void YSLib::File::Rewind ( ) const
inline

文件指针返回到文件头,语义同 std::rewind 。

在文件 yfile.h169 行定义.

参考自 CheckSize() , 以及 YSLib::TextFile::GetBOM().

这是这个函数的调用关系图:

int YSLib::File::Seek ( ptrdiff_t  offset,
int  whence 
) const
inline

设置文件指针位置。

注解
参数和返回值语义同 std::fseek
自从
build 273

在文件 yfile.h100 行定义.

参考自 CheckSize(),YSLib::TextFile::Locate() , 以及 YSLib::TextFile::Rewind().

这是这个函数的调用关系图:

bool File::Truncate ( size_t  size) const
virtual

截断文件。

参见
platform::truncate
注解
派生类可能覆盖默认行为。
自从
build 341

YSLib::TextFile 重载.

在文件 yfile.cpp111 行定义.

参考 GetPtr() , 以及 platform::truncate().

参考自 YSLib::TextFile::Truncate().

函数调用图:

这是这个函数的调用关系图:

size_t YSLib::File::Write ( void *  ptr,
size_t  size = 1U,
size_t  nmemb = 1U 
) const
inline

连续写 nmemb 个大小为 size 文件块到 ptr 中。

返回
返回成功写入的文件块数。
注解
语义同 std::fwrite
参见
ISO C11 7.21.8.2 。
自从
build 329

在文件 yfile.h188 行定义.

类成员变量说明

std::FILE* YSLib::File::fp
private
自从
build 341 默认文件指针。

在文件 yfile.h45 行定义.

参考自 Close().

size_t YSLib::File::fsize
private

文件大小。

自从
build 341

在文件 yfile.h47 行定义.

参考自 CheckSize().


该类的文档由以下文件生成: