SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TFIn Class Reference

#include <fl.h>

Inheritance diagram for TFIn:
Collaboration diagram for TFIn:

Public Member Functions

 TFIn (const TStr &FNm)
 
 TFIn (const TStr &FNm, bool &OpenedP)
 
 ~TFIn ()
 
bool Eof ()
 
int Len () const
 
char GetCh ()
 
char PeekCh ()
 
int GetBf (const void *LBf, const TSize &LBfL)
 
void Reset ()
 
bool GetNextLnBf (TChA &LnChA)
 
- Public Member Functions inherited from TSIn
 TSIn ()
 
 TSIn (const TStr &Str)
 
virtual ~TSIn ()
 
bool IsFastMode () const
 
void SetFastMode (const bool &_FastMode)
 
virtual void LoadCs ()
 
void LoadBf (const void *Bf, const TSize &BfL)
 
void * LoadNewBf (const int &BfL)
 
void Load (bool &Bool)
 
void Load (uchar &UCh)
 
void Load (char &Ch)
 
void Load (short &Short)
 
void Load (ushort &UShort)
 
void Load (int &Int)
 
void Load (uint &UInt)
 
void Load (int64 &Int)
 
void Load (uint64 &UInt)
 
void Load (double &Flt)
 
void Load (sdouble &SFlt)
 
void Load (ldouble &LFlt)
 
void Load (char *&CStr, const int &MxCStrLen, const int &CStrLen)
 
void Load (char *&CStr)
 
TSInoperator>> (bool &Bool)
 
TSInoperator>> (uchar &UCh)
 
TSInoperator>> (char &Ch)
 
TSInoperator>> (short &Sh)
 
TSInoperator>> (ushort &USh)
 
TSInoperator>> (int &Int)
 
TSInoperator>> (uint &UInt)
 
TSInoperator>> (int64 &Int)
 
TSInoperator>> (uint64 &UInt)
 
TSInoperator>> (float &Flt)
 
TSInoperator>> (double &Double)
 
TSInoperator>> (long double &LDouble)
 
bool GetNextLn (TStr &LnStr)
 
bool GetNextLn (TChA &LnChA)
 
- Public Member Functions inherited from TSBase
 TSBase (const TSStr &Nm)
 
virtual ~TSBase ()
 
virtual TStr GetSNm () const
 

Static Public Member Functions

static PSIn New (const TStr &FNm)
 
static PSIn New (const TStr &FNm, bool &OpenedP)
 

Private Member Functions

void SetFPos (const int &FPos) const
 
int GetFPos () const
 
int GetFLen () const
 
void FillBf ()
 
int FindEol (int &BfN, bool &CrEnd)
 
 TFIn ()
 
 TFIn (const TFIn &)
 
TFInoperator= (const TFIn &)
 

Private Attributes

TFileId FileId
 
char * Bf
 
int BfC
 
int BfL
 

Static Private Attributes

static const int MxBfL =16*1024
 

Additional Inherited Members

- Static Public Attributes inherited from TSIn
static const TPt< TSInStdIn =PSIn(new TStdIn())
 
- Protected Attributes inherited from TSBase
TCRef CRef
 
TSStr SNm
 
TCs Cs
 

Detailed Description

Definition at line 275 of file fl.h.

Constructor & Destructor Documentation

TFIn::TFIn ( )
private

Referenced by New().

Here is the caller graph for this function:

TFIn::TFIn ( const TFIn )
private
TFIn::TFIn ( const TStr FNm)

Definition at line 273 of file fl.cpp.

References Bf, BfC, BfL, TStr::CStr(), EAssertR, TStr::Empty(), FileId, FillBf(), and MxBfL.

273  :
274  TSBase(FNm.CStr()), TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
275  EAssertR(!FNm.Empty(), "Empty file-name.");
276  FileId=fopen(FNm.CStr(), "rb");
277  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
278  Bf=new char[MxBfL]; BfC=BfL=-1; FillBf();
279 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
int BfL
Definition: fl.h:280
void FillBf()
Definition: fl.cpp:264
TFileId FileId
Definition: fl.h:278
char * Bf
Definition: fl.h:279
int BfC
Definition: fl.h:280
TSIn()
Definition: fl.h:65
bool Empty() const
Definition: dt.h:491
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
static const int MxBfL
Definition: fl.h:277
char * CStr()
Definition: dt.h:479

Here is the call graph for this function:

TFIn::TFIn ( const TStr FNm,
bool &  OpenedP 
)

Definition at line 281 of file fl.cpp.

References Bf, BfC, BfL, TStr::CStr(), EAssertR, TStr::Empty(), FileId, FillBf(), and MxBfL.

281  :
282  TSBase(FNm.CStr()), TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
283  EAssertR(!FNm.Empty(), "Empty file-name.");
284  FileId=fopen(FNm.CStr(), "rb");
285  OpenedP=(FileId!=NULL);
286  if (OpenedP){
287  Bf=new char[MxBfL]; BfC=BfL=-1; FillBf();}
288 }
TSBase(const TSStr &Nm)
Definition: fl.h:50
int BfL
Definition: fl.h:280
void FillBf()
Definition: fl.cpp:264
TFileId FileId
Definition: fl.h:278
char * Bf
Definition: fl.h:279
int BfC
Definition: fl.h:280
TSIn()
Definition: fl.h:65
bool Empty() const
Definition: dt.h:491
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
static const int MxBfL
Definition: fl.h:277
char * CStr()
Definition: dt.h:479

Here is the call graph for this function:

TFIn::~TFIn ( )

Definition at line 305 of file fl.cpp.

References Bf, EAssertR, FileId, and TSBase::GetSNm().

305  {
306  if (FileId!=NULL){
307  EAssertR(fclose(FileId)==0, "Can not close file '"+GetSNm()+"'.");}
308  if (Bf!=NULL){delete[] Bf;}
309 }
TFileId FileId
Definition: fl.h:278
char * Bf
Definition: fl.h:279
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
virtual TStr GetSNm() const
Definition: fl.cpp:20

Here is the call graph for this function:

Member Function Documentation

bool TFIn::Eof ( )
inlinevirtual

Implements TSIn.

Definition at line 298 of file fl.h.

References FillBf(), and MxBfL.

Referenced by FindEol(), GetCh(), TILx::GetLnV(), TKeyDatFl< TKey, TDat, THashFunc >::Next(), and PeekCh().

298  {
299  if ((BfC==BfL)&&(BfL==MxBfL)){FillBf();}
300  return (BfC==BfL)&&(BfL<MxBfL);}
int BfL
Definition: fl.h:280
void FillBf()
Definition: fl.cpp:264
int BfC
Definition: fl.h:280
static const int MxBfL
Definition: fl.h:277

Here is the call graph for this function:

Here is the caller graph for this function:

void TFIn::FillBf ( )
private

Definition at line 264 of file fl.cpp.

References Bf, BfC, BfL, EAssertR, FileId, TSBase::GetSNm(), and MxBfL.

Referenced by Eof(), GetBf(), Reset(), and TFIn().

264  {
265  EAssertR(
266  (BfC==BfL)&&((BfL==-1)||(BfL==MxBfL)),
267  "Error reading file '"+GetSNm()+"'.");
268  BfL=int(fread(Bf, 1, MxBfL, FileId));
269  EAssertR((BfC!=0)||(BfL!=0), "Error reading file '"+GetSNm()+"'.");
270  BfC=0;
271 }
int BfL
Definition: fl.h:280
TFileId FileId
Definition: fl.h:278
char * Bf
Definition: fl.h:279
int BfC
Definition: fl.h:280
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
virtual TStr GetSNm() const
Definition: fl.cpp:20
static const int MxBfL
Definition: fl.h:277

Here is the call graph for this function:

Here is the caller graph for this function:

int TFIn::FindEol ( int &  BfN,
bool &  CrEnd 
)
private

Definition at line 367 of file fl.cpp.

References Bf, BfC, BfL, and Eof().

Referenced by GetNextLnBf().

367  {
368  char Ch;
369 
370  if (BfC >= BfL) {
371  // read more data, check for eof
372  if (Eof()) {
373  return -1;
374  }
375  if (CrEnd && Bf[BfC]=='\n') {
376  BfC++;
377  BfN = BfC-1;
378  return 1;
379  }
380  }
381 
382  CrEnd = false;
383  while (BfC < BfL) {
384  Ch = Bf[BfC++];
385  if (Ch=='\n') {
386  BfN = BfC-1;
387  return 1;
388  }
389  if (Ch=='\r') {
390  if (BfC == BfL) {
391  CrEnd = true;
392  BfN = BfC-1;
393  return 0;
394  } else if (Bf[BfC]=='\n') {
395  BfC++;
396  BfN = BfC-2;
397  return 1;
398  }
399  }
400  }
401  BfN = BfC;
402 
403  return 0;
404 }
int BfL
Definition: fl.h:280
char * Bf
Definition: fl.h:279
bool Eof()
Definition: fl.h:298
int BfC
Definition: fl.h:280

Here is the call graph for this function:

Here is the caller graph for this function:

int TFIn::GetBf ( const void *  LBf,
const TSize LBfL 
)
virtual

Implements TSIn.

Definition at line 311 of file fl.cpp.

References Bf, BfC, BfL, and FillBf().

311  {
312  int LBfS=0;
313  if (TSize(BfC+LBfL)>TSize(BfL)){
314  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
315  if (BfC==BfL){FillBf();}
316  LBfS+=((char*)LBf)[LBfC]=Bf[BfC++];}
317  } else {
318  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
319  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
320  }
321  return LBfS;
322 }
int BfL
Definition: fl.h:280
void FillBf()
Definition: fl.cpp:264
size_t TSize
Definition: bd.h:58
char * Bf
Definition: fl.h:279
int BfC
Definition: fl.h:280

Here is the call graph for this function:

char TFIn::GetCh ( )
inlinevirtual

Implements TSIn.

Definition at line 302 of file fl.h.

References Eof().

Referenced by TILx::GetLnV().

302  {
303  if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC++];}
304  else {return Bf[BfC++];}}
int BfL
Definition: fl.h:280
char * Bf
Definition: fl.h:279
bool Eof()
Definition: fl.h:298
int BfC
Definition: fl.h:280

Here is the call graph for this function:

Here is the caller graph for this function:

int TFIn::GetFLen ( ) const
private

Definition at line 255 of file fl.cpp.

References EAssertR, FileId, GetFPos(), TSBase::GetSNm(), SEEK_END, and SetFPos().

Referenced by Len().

255  {
256  const int FPos=GetFPos();
257  EAssertR(
258  fseek(FileId, 0, SEEK_END)==0,
259  "Error seeking into file '"+GetSNm()+"'.");
260  const int FLen=GetFPos(); SetFPos(FPos);
261  return FLen;
262 }
#define SEEK_END
Definition: fl.cpp:969
TFileId FileId
Definition: fl.h:278
int GetFPos() const
Definition: fl.cpp:249
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
virtual TStr GetSNm() const
Definition: fl.cpp:20
void SetFPos(const int &FPos) const
Definition: fl.cpp:243

Here is the call graph for this function:

Here is the caller graph for this function:

int TFIn::GetFPos ( ) const
private

Definition at line 249 of file fl.cpp.

References EAssertR, FileId, and TSBase::GetSNm().

Referenced by GetFLen(), and Len().

249  {
250  const int FPos=(int)ftell(FileId);
251  EAssertR(FPos!=-1, "Error seeking into file '"+GetSNm()+"'.");
252  return FPos;
253 }
TFileId FileId
Definition: fl.h:278
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
virtual TStr GetSNm() const
Definition: fl.cpp:20

Here is the call graph for this function:

Here is the caller graph for this function:

bool TFIn::GetNextLnBf ( TChA LnChA)
virtual

Implements TSIn.

Definition at line 328 of file fl.cpp.

References TChA::AddBf(), Bf, BfC, BfL, TChA::Clr(), TChA::Empty(), and FindEol().

328  {
329  int Status;
330  int BfN; // new pointer to the end of line
331  int BfP; // previous pointer to the line start
332  bool CrEnd; // last character in previous buffer was CR
333 
334  LnChA.Clr();
335 
336  CrEnd = false;
337  do {
338  if (BfC >= BfL) {
339  // reset the current pointer, FindEol() will read a new buffer
340  BfP = 0;
341  } else {
342  BfP = BfC;
343  }
344  Status = FindEol(BfN,CrEnd);
345  if (Status >= 0) {
346  if (BfN-BfP > 0) {
347  LnChA.AddBf(&Bf[BfP],BfN-BfP);
348  }
349  if (Status == 1) {
350  // got a complete line
351  return true;
352  }
353  }
354  // get more data, if the line is incomplete
355  } while (Status == 0);
356 
357  // eof or the last line has no newline
358  return !LnChA.Empty();
359 }
int BfL
Definition: fl.h:280
bool Empty() const
Definition: dt.h:260
int FindEol(int &BfN, bool &CrEnd)
Definition: fl.cpp:367
void Clr()
Definition: dt.h:258
char * Bf
Definition: fl.h:279
int BfC
Definition: fl.h:280
void AddBf(char *NewBf, const int &BfS)
Definition: dt.h:275

Here is the call graph for this function:

int TFIn::Len ( ) const
inlinevirtual

Implements TSIn.

Definition at line 301 of file fl.h.

References BfC, GetFLen(), and GetFPos().

301 {return GetFLen()-(GetFPos()-BfL+BfC);}
int BfL
Definition: fl.h:280
int GetFPos() const
Definition: fl.cpp:249
int BfC
Definition: fl.h:280
int GetFLen() const
Definition: fl.cpp:255

Here is the call graph for this function:

PSIn TFIn::New ( const TStr FNm)
static

Definition at line 290 of file fl.cpp.

References EFailR, and TFIn().

Referenced by TUniChDb::LoadBin(), TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), TMBlobBs::LoadMain(), TLAMisc::LoadMatlabTFltVV(), TSs::LoadTxt(), THtmlDoc::LoadTxt(), TXmlDoc::LoadTxt(), TStr::LoadTxt(), TBigStrPool::New(), TStrPool::New(), TZipIn::NewIfZip(), TUniChDb::Test(), TPreproc::TPreproc(), and TSsParser::TSsParser().

290  {
291  try {
292  return PSIn(new TFIn(FNm));
293  } catch (PExcept& Except) {
294  printf("*** Exception: %s\n", Except->GetMsgStr().CStr());
295  EFailR(Except->GetMsgStr());
296  }
297 
298  return PSIn(new TFIn(FNm));
299 }
#define EFailR(Reason)
Definition: bd.h:246
Definition: bd.h:196
TPt< TSIn > PSIn
Definition: fl.h:119

Here is the call graph for this function:

Here is the caller graph for this function:

PSIn TFIn::New ( const TStr FNm,
bool &  OpenedP 
)
static

Definition at line 301 of file fl.cpp.

References TFIn().

301  {
302  return PSIn(new TFIn(FNm, OpenedP));
303 }
TPt< TSIn > PSIn
Definition: fl.h:119

Here is the call graph for this function:

TFIn& TFIn::operator= ( const TFIn )
private
char TFIn::PeekCh ( )
inlinevirtual

Implements TSIn.

Definition at line 305 of file fl.h.

References BfC, and Eof().

305  {
306  if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC];}
307  else {return Bf[BfC];}}
int BfL
Definition: fl.h:280
char * Bf
Definition: fl.h:279
bool Eof()
Definition: fl.h:298
int BfC
Definition: fl.h:280

Here is the call graph for this function:

void TFIn::Reset ( )
inlinevirtual

Reimplemented from TSIn.

Definition at line 309 of file fl.h.

References TSBase::Cs, and FillBf().

309 {rewind(FileId); Cs=TCs(); BfC=BfL=-1; FillBf();}
int BfL
Definition: fl.h:280
void FillBf()
Definition: fl.cpp:264
TFileId FileId
Definition: fl.h:278
int BfC
Definition: fl.h:280
Definition: fl.h:11
TCs Cs
Definition: fl.h:44

Here is the call graph for this function:

void TFIn::SetFPos ( const int &  FPos) const
private

Definition at line 243 of file fl.cpp.

References EAssertR, FileId, TSBase::GetSNm(), and SEEK_SET.

Referenced by GetFLen().

243  {
244  EAssertR(
245  fseek(FileId, FPos, SEEK_SET)==0,
246  "Error seeking into file '"+GetSNm()+"'.");
247 }
TFileId FileId
Definition: fl.h:278
#define SEEK_SET
Definition: fl.cpp:970
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
virtual TStr GetSNm() const
Definition: fl.cpp:20

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

char* TFIn::Bf
private

Definition at line 279 of file fl.h.

Referenced by FillBf(), FindEol(), GetBf(), GetNextLnBf(), TFIn(), and ~TFIn().

int TFIn::BfC
private

Definition at line 280 of file fl.h.

Referenced by FillBf(), FindEol(), GetBf(), GetNextLnBf(), Len(), PeekCh(), and TFIn().

int TFIn::BfL
private

Definition at line 280 of file fl.h.

Referenced by FillBf(), FindEol(), GetBf(), GetNextLnBf(), and TFIn().

TFileId TFIn::FileId
private

Definition at line 278 of file fl.h.

Referenced by FillBf(), GetFLen(), GetFPos(), SetFPos(), TFIn(), and ~TFIn().

const int TFIn::MxBfL =16*1024
staticprivate

Definition at line 277 of file fl.h.

Referenced by Eof(), FillBf(), and TFIn().


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