SNAP Library 2.2, Developer Reference  2014-03-11 19:15:55
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
TFInOut Class Reference

#include <fl.h>

Inheritance diagram for TFInOut:
Collaboration diagram for TFInOut:

List of all members.

Public Member Functions

 TFInOut (const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
 ~TFInOut ()
TStr GetFNm () const
TFileId GetFileId () const
bool Eof ()
int Len () const
char GetCh ()
char PeekCh ()
int GetBf (const void *LBf, const TSize &LBfL)
bool GetNextLnBf (TChA &LnChA)
void SetPos (const int &Pos)
void MovePos (const int &DPos)
int GetPos () const
int GetSize () const
void Clr ()
int PutCh (const char &Ch)
int PutBf (const void *LBf, const TSize &LBfL)
void Flush ()

Static Public Member Functions

static PSInOut New (const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)

Private Member Functions

 TFInOut ()
 TFInOut (const TFIn &)
TFInOutoperator= (const TFIn &)

Private Attributes

TFileId FileId

Detailed Description

Definition at line 349 of file fl.h.


Constructor & Destructor Documentation

TFInOut::TFInOut ( ) [private]

Referenced by New().

Here is the caller graph for this function:

TFInOut::TFInOut ( const TFIn ) [private]
TFInOut::TFInOut ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo 
)

Definition at line 475 of file fl.cpp.

References TStr::CStr(), faAppend, faCreate, Fail, faRdOnly, faUpdate, FileId, IAssert, and SEEK_END.

                                                                                 :
 TSBase(TSStr(FNm.CStr())), FileId(NULL) {
  switch (FAccess){
    case faCreate: FileId=fopen(FNm.CStr(), "w+b"); break;
    case faUpdate: FileId=fopen(FNm.CStr(), "r+b"); break;
    case faAppend: FileId=fopen(FNm.CStr(), "r+b");
      if (FileId!=NULL){fseek(FileId, SEEK_END, 0);} break;
    case faRdOnly: FileId=fopen(FNm.CStr(), "rb"); break;
    default: Fail;
  }
  if ((FileId==NULL)&&(CreateIfNo)){FileId=fopen(FNm.CStr(), "w+b");}
  IAssert(FileId!=NULL);
}

Here is the call graph for this function:

TFInOut::~TFInOut ( ) [inline]

Definition at line 359 of file fl.h.

References FileId, and IAssert.

{ if (FileId!=NULL) IAssert(fclose(FileId) == 0); }

Member Function Documentation

void TFInOut::Clr ( ) [inline, virtual]

Implements TSInOut.

Definition at line 375 of file fl.h.

References Fail.

{ Fail; }
bool TFInOut::Eof ( ) [inline, virtual]

Implements TSIn.

Definition at line 364 of file fl.h.

References FileId.

{ return feof(FileId) != 0; }
void TFInOut::Flush ( ) [inline, virtual]

Implements TSOut.

Definition at line 379 of file fl.h.

References FileId, and IAssert.

{ IAssert(fflush(FileId) == 0); }
int TFInOut::GetBf ( const void *  LBf,
const TSize LBfL 
) [virtual]

Implements TSIn.

Definition at line 510 of file fl.cpp.

References FileId, and IAssert.

                                                     {
  IAssert(fread((void *)LBf, sizeof(char), LBfL, FileId) == (size_t) LBfL);
  int LBfS = 0;
  for (TSize i = 0; i < LBfL; i++) {
    LBfS += ((char *)LBf)[i];
  }
  return LBfS;
}
char TFInOut::GetCh ( ) [inline, virtual]

Implements TSIn.

Definition at line 366 of file fl.h.

References FileId.

Referenced by PeekCh().

{ return char(fgetc(FileId)); }

Here is the caller graph for this function:

TFileId TFInOut::GetFileId ( ) const [inline, virtual]

Reimplemented from TSOut.

Definition at line 362 of file fl.h.

References FileId.

{return FileId;}
TStr TFInOut::GetFNm ( ) const

Definition at line 525 of file fl.cpp.

References TSBase::GetSNm().

                           {
  return GetSNm();
}

Here is the call graph for this function:

bool TFInOut::GetNextLnBf ( TChA LnChA) [virtual]

Implements TSIn.

Definition at line 519 of file fl.cpp.

References FailR, and TStr::Fmt().

                                    {
  // not implemented
  FailR(TStr::Fmt("TFInOut::GetNextLnBf: not implemented").CStr());
  return false;
}

Here is the call graph for this function:

int TFInOut::GetPos ( ) const [inline, virtual]

Implements TSInOut.

Definition at line 373 of file fl.h.

References FileId.

Referenced by GetSize(), and Len().

{ return (int) ftell(FileId); }

Here is the caller graph for this function:

int TFInOut::GetSize ( ) const [virtual]

Implements TSInOut.

Definition at line 493 of file fl.cpp.

References FileId, GetPos(), IAssert, SEEK_END, and SEEK_SET.

Referenced by Len().

                           {
  const int FPos = GetPos();
  IAssert(fseek(FileId, 0, SEEK_END) == 0);
  const int FLen = GetPos();
  IAssert(fseek(FileId, FPos, SEEK_SET) == 0);
  return FLen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements TSIn.

Definition at line 365 of file fl.h.

References GetPos(), and GetSize().

{ return GetSize() - GetPos(); } // bytes till eof

Here is the call graph for this function:

void TFInOut::MovePos ( const int &  DPos) [inline, virtual]

Implements TSInOut.

Definition at line 372 of file fl.h.

References FileId, IAssert, and SEEK_CUR.

Referenced by PeekCh().

{ IAssert(fseek(FileId, DPos, SEEK_CUR)==0); }

Here is the caller graph for this function:

PSInOut TFInOut::New ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo 
) [static]

Definition at line 489 of file fl.cpp.

References TFInOut().

                                                                                     {
  return PSInOut(new TFInOut(FNm, FAccess, CreateIfNo));
}

Here is the call graph for this function:

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

Implements TSIn.

Definition at line 367 of file fl.h.

References GetCh(), and MovePos().

{ const char Ch = GetCh();  MovePos(-1);  return Ch; }

Here is the call graph for this function:

int TFInOut::PutBf ( const void *  LBf,
const TSize LBfL 
) [virtual]

Implements TSOut.

Definition at line 501 of file fl.cpp.

References FileId, and IAssert.

Referenced by PutCh().

                                                     {
  int LBfS = 0;
  for (TSize i = 0; i < LBfL; i++) {
    LBfS += ((char *)LBf)[i];
  }
  IAssert(fwrite(LBf, sizeof(char), LBfL, FileId) == (size_t) LBfL);
  return LBfS;
}

Here is the caller graph for this function:

int TFInOut::PutCh ( const char &  Ch) [inline, virtual]

Implements TSOut.

Definition at line 377 of file fl.h.

References PutBf().

{ return PutBf(&Ch, sizeof(Ch)); }

Here is the call graph for this function:

void TFInOut::SetPos ( const int &  Pos) [inline, virtual]

Implements TSInOut.

Definition at line 371 of file fl.h.

References FileId, IAssert, and SEEK_SET.

{ IAssert(fseek(FileId, Pos, SEEK_SET)==0); }

Member Data Documentation

Definition at line 351 of file fl.h.

Referenced by Eof(), Flush(), GetBf(), GetCh(), GetFileId(), GetPos(), GetSize(), MovePos(), PutBf(), SetPos(), TFInOut(), and ~TFInOut().


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