TRF Language Model
wb::File Class Reference

file class. More...

#include <wb-file.h>

Inheritance diagram for wb::File:
wb::ObjFile

Public Member Functions

 File ()
 constructor More...
 
 File (const char *path, const char *mode, bool bHardOpen=true)
 constructor More...
 
 ~File ()
 destructor More...
 
virtual bool Open (const char *path, const char *mode, bool bHardOpen=true)
 Open file. More...
 
virtual bool Reopen (const char *model)
 re-open the file More...
 
virtual void Close ()
 close the file More...
 
 operator FILE * ()
 transform the class to FILE pointer More...
 
virtual char * GetLine (bool bPrecent=false)
 Read a line into the buffer. More...
 
virtual bool GetLine (char *str, int maxLen=MAX_SENTENCE_LEN)
 read a line into buffer str. More...
 
virtual void Print (const char *p_pMessage,...)
 print More...
 
virtual int Scanf (const char *p_pMessage,...)
 scanf More...
 
void Flush ()
 clean buffer More...
 
void Reset ()
 reset position More...
 
bool Good () const
 return if the file is accessible. More...
 
template<typename TYPE >
void PrintArray (const char *pformat, TYPE *pbuf, int num)
 print a array into file More...
 

Public Attributes

FILE * fp
 file pointer More...
 
int nLine
 the number of reading from file More...
 
char * pStrLine
 store the string get from file More...
 
string strFileName
 stroe the file name More...
 
bool bOver
 record the if the buffer is overflow More...
 
short nBuf
 record the buffer is nBuf times of GS_SENTENCE_LEN More...
 

Detailed Description

file class.

Author
WangBin
Date
2016-05-05

There are several convenient functions in this class:

  • function GetLine. It can read a line in a text file. For example:
    char *pline = NULL;
    while (pline = file.GetLine()) {
    ... process the line ...
    }
  • function PrintArray. It can print a array to into a line of a text file. For example:
    float a[10] = {1,2,3};
    file.PrintArray("%f", a, 10);

Definition at line 94 of file wb-file.h.

Constructor & Destructor Documentation

§ File() [1/2]

wb::File::File ( )
inline

constructor

Definition at line 108 of file wb-file.h.

§ File() [2/2]

wb::File::File ( const char *  path,
const char *  mode,
bool  bHardOpen = true 
)
inline

constructor

Definition at line 110 of file wb-file.h.

§ ~File()

wb::File::~File ( )
inline

destructor

Definition at line 112 of file wb-file.h.

Member Function Documentation

§ Close()

virtual void wb::File::Close ( )
inlinevirtual

close the file

Definition at line 124 of file wb-file.h.

§ Flush()

void wb::File::Flush ( )
inline

clean buffer

Definition at line 140 of file wb-file.h.

§ GetLine() [1/2]

char * wb::File::GetLine ( bool  bPrecent = false)
virtual

Read a line into the buffer.

Parameters
[in]bPrecentif true, then print the precent in the tille
Returns
return the string, which can be accepted by char* variables.

Definition at line 47 of file wb-file.cpp.

§ GetLine() [2/2]

bool wb::File::GetLine ( char *  str,
int  maxLen = MAX_SENTENCE_LEN 
)
virtual

read a line into buffer str.

Definition at line 88 of file wb-file.cpp.

§ Good()

bool wb::File::Good ( ) const
inline

return if the file is accessible.

Definition at line 145 of file wb-file.h.

§ Open()

bool wb::File::Open ( const char *  path,
const char *  mode,
bool  bHardOpen = true 
)
virtual

Open file.

Parameters
[in]paththe file path
[in]modeopen mode {'w', 'r', 't', 'b', 'a'}
[in]bHardOpenif ture, report error if opening the file fails.
Returns
if open the file successfully.

Definition at line 23 of file wb-file.cpp.

§ operator FILE *()

wb::File::operator FILE * ( )
inline

transform the class to FILE pointer

Definition at line 126 of file wb-file.h.

§ Print()

void wb::File::Print ( const char *  p_pMessage,
  ... 
)
virtual

print

Definition at line 115 of file wb-file.cpp.

§ PrintArray()

template<typename TYPE >
void wb::File::PrintArray ( const char *  pformat,
TYPE *  pbuf,
int  num 
)
inline

print a array into file

Definition at line 148 of file wb-file.h.

§ Reopen()

bool wb::File::Reopen ( const char *  model)
virtual

re-open the file

Definition at line 42 of file wb-file.cpp.

§ Reset()

void wb::File::Reset ( )
inline

reset position

using _fseeki64 to reset position

Definition at line 143 of file wb-file.h.

§ Scanf()

int wb::File::Scanf ( const char *  p_pMessage,
  ... 
)
virtual

scanf

Definition at line 132 of file wb-file.cpp.

Member Data Documentation

§ bOver

bool wb::File::bOver

record the if the buffer is overflow

Definition at line 103 of file wb-file.h.

§ fp

FILE* wb::File::fp

file pointer

Definition at line 97 of file wb-file.h.

§ nBuf

short wb::File::nBuf

record the buffer is nBuf times of GS_SENTENCE_LEN

Definition at line 104 of file wb-file.h.

§ nLine

int wb::File::nLine

the number of reading from file

Definition at line 98 of file wb-file.h.

§ pStrLine

char* wb::File::pStrLine

store the string get from file

Definition at line 100 of file wb-file.h.

§ strFileName

string wb::File::strFileName

stroe the file name

Definition at line 101 of file wb-file.h.


The documentation for this class was generated from the following files: