layout codes.

This commit is contained in:
2020-09-03 15:39:00 +08:00
parent b37c9439e3
commit 51f22f0ed3
17 changed files with 176 additions and 92 deletions

View File

@@ -8,19 +8,19 @@ namespace hgl
{
namespace io
{
enum FileOpenMode ///文件访问模式枚举
enum class FileOpenMode ///文件访问模式枚举
{
fomNone=0,
None=0,
fomCreate, ///<创建文件,如存在则失败
fomCreateTrunc, ///<强制创建,如存在则抹掉
fomCreateTemp,
fomOnlyRead, ///<只读方式
fomOnlyWrite, ///<只写方式
fomReadWrite, ///<可读可写
fomAppend, ///<追加模式
Create, ///<创建文件,如存在则失败
CreateTrunc, ///<强制创建,如存在则抹掉
CreateTemp,
OnlyRead, ///<只读方式
OnlyWrite, ///<只写方式
ReadWrite, ///<可读可写
Append, ///<追加模式
fomEnd
End
};//enum FileOpenMode
/**
@@ -43,13 +43,13 @@ namespace hgl
FileAccess();
virtual ~FileAccess();
virtual bool Open(const OSString &,FileOpenMode fom); ///<以指定模式打开一个文件
virtual bool Create(const OSString &fn){return Open(fn,fomCreate);} ///<创建一个新文件,如文件已存在则创建失败
virtual bool CreateTrunc(const OSString &fn){return Open(fn,fomCreateTrunc);} ///<创建一个新文件,如文件已存在则抹消它
virtual bool OpenRead(const OSString &fn){return Open(fn,fomOnlyRead);} ///<以只读模式打开一个文件
virtual bool OpenWrite(const OSString &fn){return Open(fn,fomOnlyWrite);} ///<以只写模式打开一个文件
virtual bool OpenReadWrite(const OSString &fn){return Open(fn,fomReadWrite);} ///<以读写模式打开一个文件
virtual bool CreateTemp();
virtual bool Open (const OSString &,FileOpenMode fom); ///<以指定模式打开一个文件
virtual bool Create (const OSString &fn){return Open(fn,FileOpenMode::Create);} ///<创建一个新文件,如文件已存在则创建失败
virtual bool CreateTrunc (const OSString &fn){return Open(fn,FileOpenMode::CreateTrunc);} ///<创建一个新文件,如文件已存在则抹消它
virtual bool OpenRead (const OSString &fn){return Open(fn,FileOpenMode::OnlyRead);} ///<以只读模式打开一个文件
virtual bool OpenWrite (const OSString &fn){return Open(fn,FileOpenMode::OnlyWrite);} ///<以只写模式打开一个文件
virtual bool OpenReadWrite (const OSString &fn){return Open(fn,FileOpenMode::ReadWrite);} ///<以读写模式打开一个文件
virtual bool CreateTemp (); ///<创建一个临时文件
virtual void Close(); ///<关闭文件
virtual void CloseRead(); ///<仅关闭读取
@@ -64,7 +64,7 @@ namespace hgl
virtual bool CanRestart()const{return CanSeek();} ///<文件是否可复位访问
virtual bool CanSize()const{return(true);} ///<文件是否可取得长度
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<定位访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<定位访问指针
virtual int64 Tell()const; ///<取得访问指针位置
virtual int64 GetSize(); ///<取得文件长度
virtual bool Restart(); ///<复位访问指针

View File

@@ -24,11 +24,11 @@ namespace hgl
FileOutputStream(SharedPtr<FileAccess> &);
virtual ~FileOutputStream();
virtual bool Open(const OSString &fn,FileOpenMode mode){return OpenFile(fn,mode);} ///<打开文件,指定一个模式
virtual bool Open(const OSString &fn){return OpenFile(fn,fomOnlyWrite);} ///<打开文件
virtual bool Create(const OSString &fn){return OpenFile(fn,fomCreate);} ///<创建文件,如存在创建失败
virtual bool CreateTrunc(const OSString &fn){return OpenFile(fn,fomCreateTrunc);} ///<创建文件,如存在则抹去
virtual bool OpenAppend(const OSString &fn){return OpenFile(fn,fomAppend);} ///<打开文件,追加模式
virtual bool Open (const OSString &fn,FileOpenMode mode){return OpenFile(fn,mode);} ///<打开文件,指定一个模式
virtual bool Open (const OSString &fn){return OpenFile(fn,FileOpenMode::OnlyWrite);} ///<打开文件
virtual bool Create (const OSString &fn){return OpenFile(fn,FileOpenMode::Create);} ///<创建文件,如存在创建失败
virtual bool CreateTrunc (const OSString &fn){return OpenFile(fn,FileOpenMode::CreateTrunc);} ///<创建文件,如存在则抹去
virtual bool OpenAppend (const OSString &fn){return OpenFile(fn,FileOpenMode::Append);} ///<打开文件,追加模式
virtual void Close(); ///<关闭文件
@@ -67,7 +67,7 @@ namespace hgl
* @param mode 打开模式,默认只写(必然可读)
* @see FileOpenMode
*/
OpenFileOutputStream(const OSString &filename,FileOpenMode mode=fomOnlyWrite)
OpenFileOutputStream(const OSString &filename,FileOpenMode mode=FileOpenMode::OnlyWrite)
{
fos=new FileOutputStream();

View File

@@ -29,7 +29,7 @@ namespace hgl
}
int64 read (void *ptr,int size){return in?in->ReadFully(ptr,size):-1;}
int skipBytes (int size) {return in?in->Seek(size,soCurrent):-1;}
int skipBytes (int size) {return in?in->Seek(size,SeekOrigin::Current):-1;}
bool readBoolean (bool &b) {return in?in->ReadBool (b):false;}
bool readByte (int8 &i) {return in?in->ReadInt8 (i):false;}