23 bool File::Open(
const char *path,
const char *mode,
bool bHardOpen)
26 if (path == NULL || mode == NULL)
33 fp = fopen(path, mode);
50 lout_error(
"file open failed, can't GetLine!!");
53 if (bPrecent &&
nLine == 0)
91 char *p = fgets(str, maxLen,
fp);
102 if (str[l - 1] ==
'\n')
108 if (str[l-2] ==
'\r')
122 va_start(vaParams, p_pMessage);
124 vfprintf(
fp, p_pMessage, vaParams);
139 va_start(vaParams, p_pMessage);
140 int retval = vfscanf(
fp, p_pMessage, vaParams);
150 Print(
"nTotalNum = %d\n\n", m_nTotalNum);
156 fscanf(
File::fp,
"nTotalNum = %d\n\n", &m_nTotalNum);
163 Print(
"nObj: %d\n", m_nCurNum);
164 m_pObj->WriteT(*
this);
173 if (m_nCurNum >= m_nTotalNum)
176 fscanf(
File::fp,
"nObj: %d\n", &m_nCurNum);
178 m_pObj->ReadT(*
this);
186 fwrite(&m_nTotalNum,
sizeof(m_nTotalNum), 1,
fp);
192 fread(&m_nTotalNum,
sizeof(m_nTotalNum), 1,
fp);
198 fwrite(&m_nCurNum,
sizeof(m_nCurNum), 1,
fp);
199 m_pObj->WriteB(*
this);
207 if (m_nCurNum >= m_nTotalNum)
210 fread(&m_nCurNum,
sizeof(m_nCurNum), 1,
fp);
211 m_pObj->ReadB(*
this);
void ReadHeadT()
��txt��read the head
short nBuf
record the buffer is nBuf times of GS_SENTENCE_LEN
void WriteHeadT()
��txt��write the head
bool ReadObjT()
��txt��read the object
void ReadHeadB()
��bin��read the head
virtual int Scanf(const char *p_pMessage,...)
scanf
virtual void Close()
close the file
#define SAFE_FOPEN(pfile, path, mode)
file open
virtual void Print(const char *p_pMessage,...)
print
virtual bool Open(const char *path, const char *mode, bool bHardOpen=true)
Open file.
void WriteHeadB()
��bin��write the head
virtual bool Reopen(const char *model)
re-open the file
virtual char * GetLine(bool bPrecent=false)
Read a line into the buffer.
void Progress(long long n=-1, bool bInit=false, long long total=100, const char *head="")
progress bar
string strFileName
stroe the file name
bool ReadObjB()
��bin��read the object
bool bOver
record the if the buffer is overflow
char * pStrLine
store the string get from file
Log lout
the defination is in wb-log.cpp
bool Good() const
return if the file is accessible.
int nLine
the number of reading from file
#define MAX_SENTENCE_LEN
the maximum length of string read from file once
void WriteObjB()
��bin��write the object
void WriteObjT()
��txt��write the object
define all the code written by Bin Wang.