SNAP Library 2.2, User 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>

Inherits TSInOut.

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]
TFInOut::TFInOut ( const TFIn ) [private]
TFInOut::TFInOut ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo 
)

Definition at line 475 of file fl.cpp.

                                                                                 :
 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);
}
TFInOut::~TFInOut ( ) [inline]

Definition at line 359 of file fl.h.

{ 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.

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

Implements TSIn.

Definition at line 364 of file fl.h.

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

Implements TSOut.

Definition at line 379 of file fl.h.

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

Implements TSIn.

Definition at line 510 of file fl.cpp.

                                                     {
  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.

{ return char(fgetc(FileId)); }
TFileId TFInOut::GetFileId ( ) const [inline, virtual]

Reimplemented from TSOut.

Definition at line 362 of file fl.h.

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

Definition at line 525 of file fl.cpp.

                           {
  return GetSNm();
}
bool TFInOut::GetNextLnBf ( TChA LnChA) [virtual]

Implements TSIn.

Definition at line 519 of file fl.cpp.

                                    {
  // not implemented
  FailR(TStr::Fmt("TFInOut::GetNextLnBf: not implemented").CStr());
  return false;
}
int TFInOut::GetPos ( ) const [inline, virtual]

Implements TSInOut.

Definition at line 373 of file fl.h.

{ return (int) ftell(FileId); }
int TFInOut::GetSize ( ) const [virtual]

Implements TSInOut.

Definition at line 493 of file fl.cpp.

                           {
  const int FPos = GetPos();
  IAssert(fseek(FileId, 0, SEEK_END) == 0);
  const int FLen = GetPos();
  IAssert(fseek(FileId, FPos, SEEK_SET) == 0);
  return FLen;
}
int TFInOut::Len ( ) const [inline, virtual]

Implements TSIn.

Definition at line 365 of file fl.h.

{ return GetSize() - GetPos(); } // bytes till eof
void TFInOut::MovePos ( const int &  DPos) [inline, virtual]

Implements TSInOut.

Definition at line 372 of file fl.h.

{ IAssert(fseek(FileId, DPos, SEEK_CUR)==0); }
PSInOut TFInOut::New ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo 
) [static]

Definition at line 489 of file fl.cpp.

                                                                                     {
  return PSInOut(new TFInOut(FNm, FAccess, CreateIfNo));
}
TFInOut& TFInOut::operator= ( const TFIn ) [private]
char TFInOut::PeekCh ( ) [inline, virtual]

Implements TSIn.

Definition at line 367 of file fl.h.

{ const char Ch = GetCh();  MovePos(-1);  return Ch; }
int TFInOut::PutBf ( const void *  LBf,
const TSize LBfL 
) [virtual]

Implements TSOut.

Definition at line 501 of file fl.cpp.

                                                     {
  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;
}
int TFInOut::PutCh ( const char &  Ch) [inline, virtual]

Implements TSOut.

Definition at line 377 of file fl.h.

{ return PutBf(&Ch, sizeof(Ch)); }
void TFInOut::SetPos ( const int &  Pos) [inline, virtual]

Implements TSInOut.

Definition at line 371 of file fl.h.

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

Member Data Documentation

Definition at line 351 of file fl.h.


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