SNAP Library, User Reference  2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TFIn Class Reference

#include <fl.h>

Inherits TSIn.

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

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 ()
 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 271 of file fl.h.


Constructor & Destructor Documentation

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

Definition at line 267 of file fl.cpp.

                         :
  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();
}
TFIn::TFIn ( const TStr FNm,
bool &  OpenedP 
)

Definition at line 275 of file fl.cpp.

                                        :
  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();}
}

Definition at line 292 of file fl.cpp.

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

Member Function Documentation

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

Implements TSIn.

Definition at line 293 of file fl.h.

            {
    if ((BfC==BfL)&&(BfL==MxBfL)){FillBf();}
    return (BfC==BfL)&&(BfL<MxBfL);}
void TFIn::FillBf ( ) [private]

Definition at line 258 of file fl.cpp.

                 {
  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;
}
int TFIn::GetBf ( const void *  LBf,
const TSize LBfL 
) [virtual]

Implements TSIn.

Definition at line 298 of file fl.cpp.

                                                 {
  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;
}
char TFIn::GetCh ( ) [inline, virtual]

Implements TSIn.

Definition at line 297 of file fl.h.

              {
    if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC++];}
    else {return Bf[BfC++];}}
int TFIn::GetFLen ( ) const [private]

Definition at line 249 of file fl.cpp.

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

Definition at line 243 of file fl.cpp.

                        {
  const int FPos=(int)ftell(FileId);
  EAssertR(FPos!=-1, "Error seeking into file '"+GetSNm()+"'.");
  return FPos;
}
int TFIn::Len ( ) const [inline, virtual]

Implements TSIn.

Definition at line 296 of file fl.h.

{return GetFLen()-(GetFPos()-BfL+BfC);}
PSIn TFIn::New ( const TStr FNm) [static]

Definition at line 284 of file fl.cpp.

                             {
  return PSIn(new TFIn(FNm));
}
PSIn TFIn::New ( const TStr FNm,
bool &  OpenedP 
) [static]

Definition at line 288 of file fl.cpp.

                                            {
  return PSIn(new TFIn(FNm, OpenedP));
}
TFIn& TFIn::operator= ( const TFIn ) [private]
char TFIn::PeekCh ( ) [inline, virtual]

Implements TSIn.

Definition at line 300 of file fl.h.

               {
    if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC];}
    else {return Bf[BfC];}}
void TFIn::Reset ( ) [inline, virtual]

Reimplemented from TSIn.

Definition at line 304 of file fl.h.

{rewind(FileId); Cs=TCs(); BfC=BfL=-1; FillBf();}
void TFIn::SetFPos ( const int &  FPos) const [private]

Definition at line 237 of file fl.cpp.

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

Member Data Documentation

char* TFIn::Bf [private]

Definition at line 275 of file fl.h.

int TFIn::BfC [private]

Definition at line 276 of file fl.h.

int TFIn::BfL [private]

Definition at line 276 of file fl.h.

TFileId TFIn::FileId [private]

Definition at line 274 of file fl.h.

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

Definition at line 273 of file fl.h.


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