SNAP Library 4.0, User Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TFInOut Class Reference

#include <fl.h>

Inherits TSInOut.

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 ()
 
- Public Member Functions inherited from TSInOut
 TSInOut ()
 
virtual ~TSInOut ()
 
- Public Member Functions inherited from TSIn
 TSIn ()
 
 TSIn (const TStr &Str)
 
virtual ~TSIn ()
 
virtual void Reset ()
 
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
 
- Public Member Functions inherited from TSOut
 TSOut ()
 
 TSOut (const TStr &Str)
 
virtual ~TSOut ()
 
void EnableLnTrunc (const int &_MxLnLen)
 
void DisableLnTrunc ()
 
int PutMem (const TMem &Mem)
 
int PutCh (const char &Ch, const int &Chs)
 
int PutBool (const bool &Bool)
 
int PutInt (const int &Int)
 
int PutInt (const int &Int, const char *FmtStr)
 
int PutUInt (const uint &Int)
 
int PutUInt (const uint &Int, const char *FmtStr)
 
int PutFlt (const double &Flt)
 
int PutFlt (const double &Flt, const char *FmtStr)
 
int PutStr (const char *CStr)
 
int PutStr (const TChA &ChA)
 
int PutStr (const TStr &Str, const char *FmtStr)
 
int PutStr (const TStr &Str, const bool &ForceInLn=false)
 
int PutStrLn (const TStr &Str, const bool &ForceInLn=false)
 
int PutStrFmt (const char *FmtStr,...)
 
int PutStrFmtLn (const char *FmtStr,...)
 
int PutIndent (const int &IndentLev=1)
 
int PutLn (const int &Lns=1)
 
int PutDosLn (const int &Lns=1)
 
int PutSep (const int &NextStrLen=0)
 
int PutSepLn (const int &Lns=0)
 
void SaveCs ()
 
void SaveBf (const void *Bf, const TSize &BfL)
 
void Save (const bool &Bool)
 
void Save (const char &Ch)
 
void Save (const uchar &UCh)
 
void Save (const short &Short)
 
void Save (const ushort &UShort)
 
void Save (const int &Int)
 
void Save (const uint &UInt)
 
void Save (const int64 &Int)
 
void Save (const uint64 &UInt)
 
void Save (const double &Flt)
 
void Save (const sdouble &SFlt)
 
void Save (const ldouble &LFlt)
 
void Save (const char *CStr, const TSize &CStrLen)
 
void Save (const char *CStr)
 
void Save (TSIn &SIn, const TSize &BfL=-1)
 
void Save (const PSIn &SIn, const TSize &BfL=-1)
 
void Save (const void *Bf, const TSize &BfL)
 
TSOutoperator<< (const bool &Bool)
 
TSOutoperator<< (const uchar &UCh)
 
TSOutoperator<< (const char &Ch)
 
TSOutoperator<< (const short &Sh)
 
TSOutoperator<< (const ushort &USh)
 
TSOutoperator<< (const int &Int)
 
TSOutoperator<< (const uint &Int)
 
TSOutoperator<< (const int64 &Int)
 
TSOutoperator<< (const uint64 &UInt)
 
TSOutoperator<< (const float &Flt)
 
TSOutoperator<< (const double &Double)
 
TSOutoperator<< (const long double &LDouble)
 
TSOutoperator<< (const TSOutMnp &Mnp)
 
TSOutoperator<< (TSOut &(*FuncPt)(TSOut &))
 
TSOutoperator<< (TSIn &SIn)
 
TSOutoperator<< (PSIn &SIn)
 

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
 

Additional Inherited Members

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

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

482  :
483  TSBase(TSStr(FNm.CStr())), FileId(NULL) {
484  switch (FAccess){
485  case faCreate: FileId=fopen(FNm.CStr(), "w+b"); break;
486  case faUpdate: FileId=fopen(FNm.CStr(), "r+b"); break;
487  case faAppend: FileId=fopen(FNm.CStr(), "r+b");
488  if (FileId!=NULL){fseek(FileId, SEEK_END, 0);} break;
489  case faRdOnly: FileId=fopen(FNm.CStr(), "rb"); break;
490  default: Fail;
491  }
492  if ((FileId==NULL)&&(CreateIfNo)){FileId=fopen(FNm.CStr(), "w+b");}
493  IAssert(FileId!=NULL);
494 }
#define IAssert(Cond)
Definition: bd.h:262
Definition: bd.h:514
Definition: fl.h:347
TSBase(const TSStr &Nm)
Definition: fl.h:50
#define SEEK_END
Definition: fl.cpp:969
#define Fail
Definition: bd.h:238
Definition: fl.h:347
TFileId FileId
Definition: fl.h:351
Definition: fl.h:347
char * CStr()
Definition: dt.h:476
Definition: fl.h:347
TFInOut::~TFInOut ( )
inline

Definition at line 359 of file fl.h.

359 { if (FileId!=NULL) IAssert(fclose(FileId) == 0); }
#define IAssert(Cond)
Definition: bd.h:262
TFileId FileId
Definition: fl.h:351

Member Function Documentation

void TFInOut::Clr ( )
inlinevirtual

Implements TSInOut.

Definition at line 375 of file fl.h.

375 { Fail; }
#define Fail
Definition: bd.h:238
bool TFInOut::Eof ( )
inlinevirtual

Implements TSIn.

Definition at line 364 of file fl.h.

364 { return feof(FileId) != 0; }
TFileId FileId
Definition: fl.h:351
void TFInOut::Flush ( )
inlinevirtual

Implements TSOut.

Definition at line 379 of file fl.h.

379 { IAssert(fflush(FileId) == 0); }
#define IAssert(Cond)
Definition: bd.h:262
TFileId FileId
Definition: fl.h:351
int TFInOut::GetBf ( const void *  LBf,
const TSize LBfL 
)
virtual

Implements TSIn.

Definition at line 517 of file fl.cpp.

517  {
518  IAssert(fread((void *)LBf, sizeof(char), LBfL, FileId) == (size_t) LBfL);
519  int LBfS = 0;
520  for (TSize i = 0; i < LBfL; i++) {
521  LBfS += ((char *)LBf)[i];
522  }
523  return LBfS;
524 }
#define IAssert(Cond)
Definition: bd.h:262
size_t TSize
Definition: bd.h:58
TFileId FileId
Definition: fl.h:351
char TFInOut::GetCh ( )
inlinevirtual

Implements TSIn.

Definition at line 366 of file fl.h.

366 { return char(fgetc(FileId)); }
TFileId FileId
Definition: fl.h:351
TFileId TFInOut::GetFileId ( ) const
inlinevirtual

Reimplemented from TSOut.

Definition at line 362 of file fl.h.

362 {return FileId;}
TFileId FileId
Definition: fl.h:351
TStr TFInOut::GetFNm ( ) const

Definition at line 532 of file fl.cpp.

532  {
533  return GetSNm();
534 }
virtual TStr GetSNm() const
Definition: fl.cpp:20
bool TFInOut::GetNextLnBf ( TChA LnChA)
virtual

Implements TSIn.

Definition at line 526 of file fl.cpp.

526  {
527  // not implemented
528  FailR(TStr::Fmt("TFInOut::GetNextLnBf: not implemented").CStr());
529  return false;
530 }
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
int TFInOut::GetPos ( ) const
inlinevirtual

Implements TSInOut.

Definition at line 373 of file fl.h.

373 { return (int) ftell(FileId); }
TFileId FileId
Definition: fl.h:351
int TFInOut::GetSize ( ) const
virtual

Implements TSInOut.

Definition at line 500 of file fl.cpp.

500  {
501  const int FPos = GetPos();
502  IAssert(fseek(FileId, 0, SEEK_END) == 0);
503  const int FLen = GetPos();
504  IAssert(fseek(FileId, FPos, SEEK_SET) == 0);
505  return FLen;
506 }
#define IAssert(Cond)
Definition: bd.h:262
#define SEEK_END
Definition: fl.cpp:969
#define SEEK_SET
Definition: fl.cpp:970
TFileId FileId
Definition: fl.h:351
int GetPos() const
Definition: fl.h:373
int TFInOut::Len ( ) const
inlinevirtual

Implements TSIn.

Definition at line 365 of file fl.h.

365 { return GetSize() - GetPos(); } // bytes till eof
int GetPos() const
Definition: fl.h:373
int GetSize() const
Definition: fl.cpp:500
void TFInOut::MovePos ( const int &  DPos)
inlinevirtual

Implements TSInOut.

Definition at line 372 of file fl.h.

372 { IAssert(fseek(FileId, DPos, SEEK_CUR)==0); }
#define IAssert(Cond)
Definition: bd.h:262
#define SEEK_CUR
Definition: fl.cpp:968
TFileId FileId
Definition: fl.h:351
PSInOut TFInOut::New ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo 
)
static

Definition at line 496 of file fl.cpp.

496  {
497  return PSInOut(new TFInOut(FNm, FAccess, CreateIfNo));
498 }
TPt< TSInOut > PSInOut
Definition: fl.h:236
TFInOut& TFInOut::operator= ( const TFIn )
private
char TFInOut::PeekCh ( )
inlinevirtual

Implements TSIn.

Definition at line 367 of file fl.h.

367 { const char Ch = GetCh(); MovePos(-1); return Ch; }
void MovePos(const int &DPos)
Definition: fl.h:372
char GetCh()
Definition: fl.h:366
int TFInOut::PutBf ( const void *  LBf,
const TSize LBfL 
)
virtual

Implements TSOut.

Definition at line 508 of file fl.cpp.

508  {
509  int LBfS = 0;
510  for (TSize i = 0; i < LBfL; i++) {
511  LBfS += ((char *)LBf)[i];
512  }
513  IAssert(fwrite(LBf, sizeof(char), LBfL, FileId) == (size_t) LBfL);
514  return LBfS;
515 }
#define IAssert(Cond)
Definition: bd.h:262
size_t TSize
Definition: bd.h:58
TFileId FileId
Definition: fl.h:351
int TFInOut::PutCh ( const char &  Ch)
inlinevirtual

Implements TSOut.

Definition at line 377 of file fl.h.

377 { return PutBf(&Ch, sizeof(Ch)); }
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:508
void TFInOut::SetPos ( const int &  Pos)
inlinevirtual

Implements TSInOut.

Definition at line 371 of file fl.h.

371 { IAssert(fseek(FileId, Pos, SEEK_SET)==0); }
#define IAssert(Cond)
Definition: bd.h:262
#define SEEK_SET
Definition: fl.cpp:970
TFileId FileId
Definition: fl.h:351

Member Data Documentation

TFileId TFInOut::FileId
private

Definition at line 351 of file fl.h.


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