SNAP Library 3.0, User Reference  2016-07-20 17:56:49
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
TFRnd Class Reference

#include <fl.h>

Public Member Functions

 TFRnd (const TStr &_FNm, const TFAccess &FAccess, const bool &CreateIfNo=true, const int &_HdLen=-1, const int &_RecLen=-1)
 
 ~TFRnd ()
 
TStr GetFNm () const
 
void SetHdRecLen (const int &_HdLen, const int &_RecLen)
 
void SetFPos (const int &FPos)
 
void MoveFPos (const int &DFPos)
 
int GetFPos ()
 
int GetFLen ()
 
bool Empty ()
 
bool Eof ()
 
void SetRecN (const int &RecN)
 
int GetRecN ()
 
int GetRecs ()
 
void GetBf (void *Bf, const TSize &BfL)
 
void PutBf (const void *Bf, const TSize &BfL)
 
void Flush ()
 
void GetHd (void *Hd)
 
void PutHd (const void *Hd)
 
void GetRec (void *Rec, const int &RecN=-1)
 
void PutRec (const void *Rec, const int &RecN=-1)
 
void PutCs (const TCs &Cs)
 
TCs GetCs ()
 
void PutCh (const char &Ch)
 
void PutCh (const char &Ch, const int &Chs)
 
char GetCh ()
 
void PutUCh (const uchar &UCh)
 
uchar GetUCh ()
 
void PutInt (const int &Int)
 
int GetInt ()
 
void PutUInt (const uint &UInt)
 
uint GetUInt ()
 
void PutStr (const TStr &Str)
 
TStr GetStr (const int &StrLen)
 
TStr GetStr (const int &MxStrLen, bool &IsOk)
 
void PutSIn (const PSIn &SIn, TCs &Cs)
 
PSIn GetSIn (const int &SInLen, TCs &Cs)
 

Static Public Member Functions

static PFRnd New (const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo=true, const int &HdLen=-1, const int &RecLen=-1)
 
static TStr GetStrFromFAccess (const TFAccess &FAccess)
 
static TFAccess GetFAccessFromStr (const TStr &Str)
 

Private Member Functions

void RefreshFPos ()
 
 TFRnd (const TFRnd &)
 
TFRndoperator= (const TFRnd &)
 

Private Attributes

TCRef CRef
 
TFileId FileId
 
TSStr FNm
 
bool RecAct
 
int HdLen
 
int RecLen
 

Friends

class TPt< TFRnd >
 

Detailed Description

Definition at line 516 of file fl.h.

Constructor & Destructor Documentation

TFRnd::TFRnd ( const TFRnd )
private
TFRnd::TFRnd ( const TStr _FNm,
const TFAccess FAccess,
const bool &  CreateIfNo = true,
const int &  _HdLen = -1,
const int &  _RecLen = -1 
)

Definition at line 925 of file fl.cpp.

926  :
927  FileId(NULL), FNm(_FNm.CStr()),
928  RecAct(false), HdLen(_HdLen), RecLen(_RecLen){
929  RecAct=(HdLen>=0)&&(RecLen>0);
930  switch (FAccess){
931  case faCreate: FileId=fopen(FNm.CStr(), "w+b"); break;
932  case faUpdate: FileId=fopen(FNm.CStr(), "r+b"); break;
933  case faAppend: FileId=fopen(FNm.CStr(), "r+b");
934  if (FileId!=NULL){fseek(FileId, SEEK_END, 0);} break;
935  case faRdOnly: FileId=fopen(FNm.CStr(), "rb"); break;
936  default: Fail;
937  }
938  if ((FileId==NULL)&&(CreateIfNo)){
939  FileId=fopen(FNm.CStr(), "w+b");}
940  EAssertR(FileId!=NULL, "Can not open file '"+_FNm+"'.");
941 }
char * CStr()
Definition: bd.h:531
Definition: fl.h:347
#define SEEK_END
Definition: fl.cpp:913
bool RecAct
Definition: fl.h:520
#define Fail
Definition: bd.h:238
TFileId FileId
Definition: fl.h:518
Definition: fl.h:347
Definition: fl.h:347
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
int HdLen
Definition: fl.h:521
char * CStr()
Definition: dt.h:476
int RecLen
Definition: fl.h:521
Definition: fl.h:347
TFRnd::~TFRnd ( )

Definition at line 943 of file fl.cpp.

943  {
944  EAssertR(fclose(FileId)==0, "Can not close file '"+TStr(FNm)+"'.");
945 }
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519

Member Function Documentation

bool TFRnd::Empty ( )
inline

Definition at line 544 of file fl.h.

544 {return GetFLen()==0;}
int GetFLen()
Definition: fl.cpp:969
bool TFRnd::Eof ( )
inline

Definition at line 545 of file fl.h.

545 {return GetFPos()==GetFLen();}
int GetFLen()
Definition: fl.cpp:969
int GetFPos()
Definition: fl.cpp:963
void TFRnd::Flush ( )

Definition at line 1010 of file fl.cpp.

1010  {
1011  EAssertR(fflush(FileId)==0, "Can not flush file '"+TStr(FNm)+"'.");
1012 }
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void TFRnd::GetBf ( void *  Bf,
const TSize BfL 
)

Definition at line 996 of file fl.cpp.

996  {
997  RefreshFPos();
998  EAssertR(
999  fread(Bf, 1, BfL, FileId)==BfL,
1000  "Error reading file '"+TStr(FNm)+"'.");
1001 }
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void RefreshFPos()
Definition: fl.cpp:919
char TFRnd::GetCh ( )
inline

Definition at line 568 of file fl.h.

568 {char Ch; GetBf(&Ch, sizeof(Ch)); return Ch;}
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
TCs TFRnd::GetCs ( )
inline

Definition at line 565 of file fl.h.

565 {TCs Cs; GetBf(&Cs, sizeof(Cs)); return Cs;}
Definition: fl.h:11
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
TFAccess TFRnd::GetFAccessFromStr ( const TStr Str)
static

Definition at line 1076 of file fl.cpp.

1076  {
1077  TStr UcStr=Str.GetUc();
1078  if (UcStr=="CREATE"){return faCreate;}
1079  if (UcStr=="UPDATE"){return faUpdate;}
1080  if (UcStr=="APPEND"){return faAppend;}
1081  if (UcStr=="READONLY"){return faRdOnly;}
1082  if (UcStr=="RESTORE"){return faRestore;}
1083 
1084  if (UcStr=="NEW"){return faCreate;}
1085  if (UcStr=="CONT"){return faUpdate;}
1086  if (UcStr=="CONTINUE"){return faUpdate;}
1087  if (UcStr=="REST"){return faRestore;}
1088  if (UcStr=="RESTORE"){return faRestore;}
1089  return faUndef;
1090 }
Definition: fl.h:347
TStr GetUc() const
Definition: dt.h:493
Definition: fl.h:347
Definition: fl.h:347
Definition: fl.h:347
Definition: fl.h:347
Definition: dt.h:412
Definition: fl.h:347
int TFRnd::GetFLen ( )

Definition at line 969 of file fl.cpp.

969  {
970  int FPos=GetFPos();
971  EAssertR(
972  fseek(FileId, 0, SEEK_END)==0,
973  "Error seeking into file '"+TStr(FNm)+"'.");
974  int FLen=GetFPos(); SetFPos(FPos); return FLen;
975 }
#define SEEK_END
Definition: fl.cpp:913
TFileId FileId
Definition: fl.h:518
void SetFPos(const int &FPos)
Definition: fl.cpp:951
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
int GetFPos()
Definition: fl.cpp:963
TStr TFRnd::GetFNm ( ) const

Definition at line 947 of file fl.cpp.

947  {
948  return FNm.CStr();
949 }
char * CStr()
Definition: bd.h:531
TSStr FNm
Definition: fl.h:519
int TFRnd::GetFPos ( )

Definition at line 963 of file fl.cpp.

963  {
964  int FPos= (int) ftell(FileId);
965  EAssertR(FPos!=-1, "Error seeking into file '"+TStr(FNm)+"'.");
966  return FPos;
967 }
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void TFRnd::GetHd ( void *  Hd)
inline

Definition at line 555 of file fl.h.

555  {IAssert(RecAct);
556  int FPos=GetFPos(); SetFPos(0); GetBf(Hd, HdLen); SetFPos(FPos);}
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
void SetFPos(const int &FPos)
Definition: fl.cpp:951
int HdLen
Definition: fl.h:521
int GetFPos()
Definition: fl.cpp:963
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
int TFRnd::GetInt ( )
inline

Definition at line 572 of file fl.h.

572 {int Int; GetBf(&Int, sizeof(Int)); return Int;}
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
void TFRnd::GetRec ( void *  Rec,
const int &  RecN = -1 
)
inline

Definition at line 559 of file fl.h.

559  {
560  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} GetBf(Rec, RecLen);}
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
void SetRecN(const int &RecN)
Definition: fl.cpp:977
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
int RecLen
Definition: fl.h:521
int TFRnd::GetRecN ( )

Definition at line 982 of file fl.cpp.

982  {
983  IAssert(RecAct);
984  int FPos=GetFPos()-HdLen;
985  EAssertR(FPos%RecLen==0, "Invalid position in file'"+TStr(FNm)+"'.");
986  return FPos/RecLen;
987 }
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
int HdLen
Definition: fl.h:521
int GetFPos()
Definition: fl.cpp:963
int RecLen
Definition: fl.h:521
int TFRnd::GetRecs ( )

Definition at line 989 of file fl.cpp.

989  {
990  IAssert(RecAct);
991  int FLen=GetFLen()-HdLen;
992  EAssertR(FLen%RecLen==0, "Invalid length of file'"+TStr(FNm)+"'.");
993  return FLen/RecLen;
994 }
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
int GetFLen()
Definition: fl.cpp:969
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
int HdLen
Definition: fl.h:521
int RecLen
Definition: fl.h:521
PSIn TFRnd::GetSIn ( const int &  SInLen,
TCs Cs 
)

Definition at line 1057 of file fl.cpp.

1057  {
1058  char* Bf=new char[BfL];
1059  GetBf(Bf, BfL);
1060  Cs=TCs::GetCsFromBf(Bf, BfL);
1061  PSIn SIn=PSIn(new TMIn(Bf, BfL, true));
1062  return SIn;
1063 }
Definition: fl.h:384
static TCs GetCsFromBf(char *Bf, const int &BfL)
Definition: fl.cpp:12
TPt< TSIn > PSIn
Definition: fl.h:119
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
TStr TFRnd::GetStr ( const int &  StrLen)

Definition at line 1038 of file fl.cpp.

1038  {
1039  TStr Str;
1040  char* CStr=new char[StrLen+1];
1041  GetBf(CStr, StrLen+1);
1042  EAssertR(CStr[StrLen+1-1]==TCh::NullCh, "Error reading file '"+TStr(FNm)+"'.");
1043  Str=CStr;
1044  delete[] CStr;
1045  return Str;
1046 }
static const char NullCh
Definition: dt.h:943
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
TStr TFRnd::GetStr ( const int &  MxStrLen,
bool &  IsOk 
)

Definition at line 1027 of file fl.cpp.

1027  {
1028  IsOk=false; TStr Str;
1029  if (GetFPos()+StrLen+1<=GetFLen()){
1030  char* CStr=new char[StrLen+1];
1031  GetBf(CStr, StrLen+1);
1032  if (CStr[StrLen+1-1]==TCh::NullCh){IsOk=true; Str=CStr;}
1033  delete[] CStr;
1034  }
1035  return Str;
1036 }
int GetFLen()
Definition: fl.cpp:969
static const char NullCh
Definition: dt.h:943
Definition: dt.h:412
int GetFPos()
Definition: fl.cpp:963
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
TStr TFRnd::GetStrFromFAccess ( const TFAccess FAccess)
static

Definition at line 1065 of file fl.cpp.

1065  {
1066  switch (FAccess){
1067  case faCreate: return "Create";
1068  case faUpdate: return "Update";
1069  case faAppend: return "Append";
1070  case faRdOnly: return "ReadOnly";
1071  case faRestore: return "Restore";
1072  default: Fail; return TStr();
1073  }
1074 }
Definition: fl.h:347
#define Fail
Definition: bd.h:238
Definition: fl.h:347
Definition: fl.h:347
Definition: fl.h:347
Definition: dt.h:412
Definition: fl.h:347
uchar TFRnd::GetUCh ( )
inline

Definition at line 570 of file fl.h.

570 {uchar UCh; GetBf(&UCh, sizeof(UCh)); return UCh;}
unsigned char uchar
Definition: bd.h:10
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
uint TFRnd::GetUInt ( )
inline

Definition at line 574 of file fl.h.

574 {uint UInt; GetBf(&UInt, sizeof(UInt)); return UInt;}
unsigned int uint
Definition: bd.h:11
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:996
void TFRnd::MoveFPos ( const int &  DFPos)

Definition at line 957 of file fl.cpp.

957  {
958  EAssertR(
959  fseek(FileId, DFPos, SEEK_CUR)==0,
960  "Error seeking into file '"+TStr(FNm)+"'.");
961 }
#define SEEK_CUR
Definition: fl.cpp:912
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
static PFRnd TFRnd::New ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo = true,
const int &  HdLen = -1,
const int &  RecLen = -1 
)
inlinestatic

Definition at line 530 of file fl.h.

532  {
533  return new TFRnd(FNm, FAccess, CreateIfNo, HdLen, RecLen);}
TFRnd(const TFRnd &)
int HdLen
Definition: fl.h:521
int RecLen
Definition: fl.h:521
TFRnd& TFRnd::operator= ( const TFRnd )
private
void TFRnd::PutBf ( const void *  Bf,
const TSize BfL 
)

Definition at line 1003 of file fl.cpp.

1003  {
1004  RefreshFPos();
1005  EAssertR(
1006  fwrite(Bf, 1, BfL, FileId)==BfL,
1007  "Error writting to the file '"+TStr(FNm)+"'.");
1008 }
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void RefreshFPos()
Definition: fl.cpp:919
void TFRnd::PutCh ( const char &  Ch)
inline

Definition at line 566 of file fl.h.

566 {PutBf(&Ch, sizeof(Ch));}
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
void TFRnd::PutCh ( const char &  Ch,
const int &  Chs 
)

Definition at line 1014 of file fl.cpp.

1014  {
1015  if (Chs>0){
1016  char* CStr=new char[Chs];
1017  for (int ChN=0; ChN<Chs; ChN++){CStr[ChN]=Ch;}
1018  PutBf(CStr, Chs);
1019  delete[] CStr;
1020  }
1021 }
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
void TFRnd::PutCs ( const TCs Cs)
inline

Definition at line 564 of file fl.h.

564 {PutBf(&Cs, sizeof(Cs));}
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
void TFRnd::PutHd ( const void *  Hd)
inline

Definition at line 557 of file fl.h.

557  {IAssert(RecAct);
558  int FPos=GetFPos(); SetFPos(0); PutBf(Hd, HdLen); SetFPos(FPos);}
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
void SetFPos(const int &FPos)
Definition: fl.cpp:951
int HdLen
Definition: fl.h:521
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
int GetFPos()
Definition: fl.cpp:963
void TFRnd::PutInt ( const int &  Int)
inline

Definition at line 571 of file fl.h.

571 {PutBf(&Int, sizeof(Int));}
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
void TFRnd::PutRec ( const void *  Rec,
const int &  RecN = -1 
)
inline

Definition at line 561 of file fl.h.

561  {
562  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} PutBf(Rec, RecLen);}
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
void SetRecN(const int &RecN)
Definition: fl.cpp:977
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
int RecLen
Definition: fl.h:521
void TFRnd::PutSIn ( const PSIn SIn,
TCs Cs 
)

Definition at line 1048 of file fl.cpp.

1048  {
1049  int BfL=SIn->Len();
1050  char* Bf=new char[BfL];
1051  SIn->GetBf(Bf, BfL);
1052  Cs=TCs::GetCsFromBf(Bf, BfL);
1053  PutBf(Bf, BfL);
1054  delete[] Bf;
1055 }
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static TCs GetCsFromBf(char *Bf, const int &BfL)
Definition: fl.cpp:12
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
virtual int Len() const =0
void TFRnd::PutStr ( const TStr Str)

Definition at line 1023 of file fl.cpp.

1023  {
1024  PutBf(Str.CStr(), Str.Len()+1);
1025 }
int Len() const
Definition: dt.h:487
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
char * CStr()
Definition: dt.h:476
void TFRnd::PutUCh ( const uchar UCh)
inline

Definition at line 569 of file fl.h.

569 {PutBf(&UCh, sizeof(UCh));}
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
void TFRnd::PutUInt ( const uint UInt)
inline

Definition at line 573 of file fl.h.

573 {PutBf(&UInt, sizeof(UInt));}
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:1003
void TFRnd::RefreshFPos ( )
private

Definition at line 919 of file fl.cpp.

919  {
920  EAssertR(
921  fseek(FileId, 0, SEEK_CUR)==0,
922  "Error seeking into file '"+TStr(FNm)+"'.");
923 }
#define SEEK_CUR
Definition: fl.cpp:912
TFileId FileId
Definition: fl.h:518
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void TFRnd::SetFPos ( const int &  FPos)

Definition at line 951 of file fl.cpp.

951  {
952  EAssertR(
953  fseek(FileId, FPos, SEEK_SET)==0,
954  "Error seeking into file '"+TStr(FNm)+"'.");
955 }
TFileId FileId
Definition: fl.h:518
#define SEEK_SET
Definition: fl.cpp:914
Definition: dt.h:412
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TSStr FNm
Definition: fl.h:519
void TFRnd::SetHdRecLen ( const int &  _HdLen,
const int &  _RecLen 
)
inline

Definition at line 537 of file fl.h.

537  {
538  HdLen=_HdLen; RecLen=_RecLen; RecAct=(HdLen>=0)&&(RecLen>0);}
bool RecAct
Definition: fl.h:520
int HdLen
Definition: fl.h:521
int RecLen
Definition: fl.h:521
void TFRnd::SetRecN ( const int &  RecN)

Definition at line 977 of file fl.cpp.

977  {
978  IAssert(RecAct);
979  SetFPos(HdLen+RecN*RecLen);
980 }
#define IAssert(Cond)
Definition: bd.h:262
bool RecAct
Definition: fl.h:520
void SetFPos(const int &FPos)
Definition: fl.cpp:951
int HdLen
Definition: fl.h:521
int RecLen
Definition: fl.h:521

Friends And Related Function Documentation

friend class TPt< TFRnd >
friend

Definition at line 516 of file fl.h.

Member Data Documentation

TCRef TFRnd::CRef
private

Definition at line 516 of file fl.h.

TFileId TFRnd::FileId
private

Definition at line 518 of file fl.h.

TSStr TFRnd::FNm
private

Definition at line 519 of file fl.h.

int TFRnd::HdLen
private

Definition at line 521 of file fl.h.

bool TFRnd::RecAct
private

Definition at line 520 of file fl.h.

int TFRnd::RecLen
private

Definition at line 521 of file fl.h.


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