SNAP Library 2.1, Developer Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TFIn Class Reference

#include <fl.h>

Inheritance diagram for TFIn:
Collaboration diagram for TFIn:

List of all members.

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)

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

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.

                         :
  TSBase(FNm.CStr()), TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
  EAssertR(!FNm.Empty(), "Empty file-name.");
  FileId=fopen(FNm.CStr(), "rb");
  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
  Bf=new char[MxBfL]; BfC=BfL=-1; FillBf();
}

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.

                                        :
  TSBase(FNm.CStr()), TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
  EAssertR(!FNm.Empty(), "Empty file-name.");
  FileId=fopen(FNm.CStr(), "rb");
  OpenedP=(FileId!=NULL);
  if (OpenedP){
    Bf=new char[MxBfL]; BfC=BfL=-1; FillBf();}
}

Here is the call graph for this function:

Definition at line 298 of file fl.cpp.

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

           {
  if (FileId!=NULL){
    EAssertR(fclose(FileId)==0, "Can not close file '"+GetSNm()+"'.");}
  if (Bf!=NULL){delete[] Bf;}
}

Here is the call graph for this function:


Member Function Documentation

bool TFIn::Eof ( ) [inline, virtual]

Implements TSIn.

Definition at line 298 of file fl.h.

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

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

            {
    if ((BfC==BfL)&&(BfL==MxBfL)){FillBf();}
    return (BfC==BfL)&&(BfL<MxBfL);}

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().

                 {
  EAssertR(
   (BfC==BfL)&&((BfL==-1)||(BfL==MxBfL)),
   "Error reading file '"+GetSNm()+"'.");
  BfL=int(fread(Bf, 1, MxBfL, FileId));
  EAssertR((BfC!=0)||(BfL!=0), "Error reading file '"+GetSNm()+"'.");
  BfC=0;
}

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 360 of file fl.cpp.

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

Referenced by GetNextLnBf().

                                       {
  char Ch;

  if (BfC >= BfL) {
    // read more data, check for eof
    if (Eof()) {
      return -1;
    }
    if (CrEnd && Bf[BfC]=='\n') {
      BfC++;
      BfN = BfC-1;
      return 1;
    }
  }

  CrEnd = false;
  while (BfC < BfL) {
    Ch = Bf[BfC++];
    if (Ch=='\n') {
      BfN = BfC-1;
      return 1;
    }
    if (Ch=='\r') {
      if (BfC == BfL) {
        CrEnd = true;
        BfN = BfC-1;
        return 0;
      } else if (Bf[BfC]=='\n') {
        BfC++;
        BfN = BfC-2;
        return 1;
      }
    }
  }
  BfN = BfC;

  return 0;
}

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 304 of file fl.cpp.

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

                                                 {
  int LBfS=0;
  if (TSize(BfC+LBfL)>TSize(BfL)){
    for (TSize LBfC=0; LBfC<LBfL; LBfC++){
      if (BfC==BfL){FillBf();}
      LBfS+=((char*)LBf)[LBfC]=Bf[BfC++];}
  } else {
    for (TSize LBfC=0; LBfC<LBfL; LBfC++){
      LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
  }
  return LBfS;
}

Here is the call graph for this function:

char TFIn::GetCh ( ) [inline, virtual]

Implements TSIn.

Definition at line 302 of file fl.h.

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

Referenced by TILx::GetLnV().

              {
    if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC++];}
    else {return Bf[BfC++];}}

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().

                        {
  const int FPos=GetFPos();
  EAssertR(
   fseek(FileId, 0, SEEK_END)==0,
   "Error seeking into file '"+GetSNm()+"'.");
  const int FLen=GetFPos(); SetFPos(FPos);
  return FLen;
}

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().

                        {
  const int FPos=(int)ftell(FileId);
  EAssertR(FPos!=-1, "Error seeking into file '"+GetSNm()+"'.");
  return FPos;
}

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 321 of file fl.cpp.

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

                                  {
  int Status;
  int BfN;        // new pointer to the end of line
  int BfP;        // previous pointer to the line start
  bool CrEnd;     // last character in previous buffer was CR

  LnChA.Clr();

  CrEnd = false;
  do {
    if (BfC >= BfL) {
      // reset the current pointer, FindEol() will read a new buffer
      BfP = 0;
    } else {
      BfP = BfC;
    }
    Status = FindEol(BfN,CrEnd);
    if (Status >= 0) {
      if (BfN-BfP > 0) {
        LnChA.AddBf(&Bf[BfP],BfN-BfP);
      }
      if (Status == 1) {
        // got a complete line
        return true;
      }
    }
    // get more data, if the line is incomplete
  } while (Status == 0);

  // eof or the last line has no newline
  return !LnChA.Empty();
}

Here is the call graph for this function:

int TFIn::Len ( ) const [inline, virtual]

Implements TSIn.

Definition at line 301 of file fl.h.

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

{return GetFLen()-(GetFPos()-BfL+BfC);}

Here is the call graph for this function:

PSIn TFIn::New ( const TStr FNm) [static]

Definition at line 290 of file fl.cpp.

References TFIn().

Referenced by TUniChDb::LoadBin(), TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), TLAMisc::LoadMatlabTFltVV(), THtmlDoc::LoadTxt(), TStr::LoadTxt(), TExpHelp::LoadXml(), TBigStrPool::New(), TStrPool::New(), TUniChDb::Test(), and TPreproc::TPreproc().

                             {
  return PSIn(new TFIn(FNm));
}

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 294 of file fl.cpp.

References TFIn().

                                            {
  return PSIn(new TFIn(FNm, OpenedP));
}

Here is the call graph for this function:

TFIn& TFIn::operator= ( const TFIn ) [private]
char TFIn::PeekCh ( ) [inline, virtual]

Implements TSIn.

Definition at line 305 of file fl.h.

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

               {
    if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC];}
    else {return Bf[BfC];}}

Here is the call graph for this function:

void TFIn::Reset ( ) [inline, virtual]

Reimplemented from TSIn.

Definition at line 309 of file fl.h.

References BfC, BfL, TSBase::Cs, FileId, and FillBf().

{rewind(FileId); Cs=TCs(); BfC=BfL=-1; FillBf();}

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().

                                        {
  EAssertR(
   fseek(FileId, FPos, SEEK_SET)==0,
   "Error seeking into file '"+GetSNm()+"'.");
}

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(), GetCh(), GetNextLnBf(), PeekCh(), TFIn(), and ~TFIn().

int TFIn::BfC [private]

Definition at line 280 of file fl.h.

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

int TFIn::BfL [private]

Definition at line 280 of file fl.h.

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

TFileId TFIn::FileId [private]

Definition at line 278 of file fl.h.

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

const int TFIn::MxBfL = 16*1024 [static, private]

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: