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
|
#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 &) | |
TFRnd & | operator= (const TFRnd &) |
Private Attributes | |
TCRef | CRef |
TFileId | FileId |
TSStr | FNm |
bool | RecAct |
int | HdLen |
int | RecLen |
Friends | |
class | TPt< TFRnd > |
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 759 of file fl.cpp.
References TSStr::CStr(), EAssertR, faAppend, faCreate, Fail, faRdOnly, faUpdate, FileId, FNm, HdLen, RecAct, RecLen, and SEEK_END.
: FileId(NULL), FNm(_FNm.CStr()), RecAct(false), HdLen(_HdLen), RecLen(_RecLen){ RecAct=(HdLen>=0)&&(RecLen>0); 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");} EAssertR(FileId!=NULL, "Can not open file '"+_FNm+"'."); }
TFRnd::~TFRnd | ( | ) |
bool TFRnd::Empty | ( | ) | [inline] |
Definition at line 519 of file fl.h.
Referenced by TGBlobBs::TGBlobBs().
{return GetFLen()==0;}
bool TFRnd::Eof | ( | ) | [inline] |
void TFRnd::Flush | ( | ) |
Definition at line 844 of file fl.cpp.
References EAssertR, FileId, and FNm.
Referenced by TGBlobBs::DelBlob(), TGBlobBs::PutBlob(), TGBlobBs::TGBlobBs(), and TGBlobBs::~TGBlobBs().
void TFRnd::GetBf | ( | void * | Bf, |
const TSize & | BfL | ||
) |
Definition at line 830 of file fl.cpp.
References EAssertR, FileId, FNm, and RefreshFPos().
Referenced by GetSIn(), and GetStr().
{ RefreshFPos(); EAssertR( fread(Bf, 1, BfL, FileId)==BfL, "Error reading file '"+TStr(FNm)+"'."); }
char TFRnd::GetCh | ( | ) | [inline] |
Definition at line 543 of file fl.h.
Referenced by TBlobBs::AssertBlobState(), and TBlobBs::GetBlobState().
{char Ch; GetBf(&Ch, sizeof(Ch)); return Ch;}
TCs TFRnd::GetCs | ( | ) | [inline] |
Definition at line 540 of file fl.h.
Referenced by TGBlobBs::FNextBlobPt(), and TGBlobBs::GetBlob().
TFAccess TFRnd::GetFAccessFromStr | ( | const TStr & | Str | ) | [static] |
Definition at line 910 of file fl.cpp.
References faAppend, faCreate, faRdOnly, faRestore, faUndef, faUpdate, and TStr::GetUc().
{ TStr UcStr=Str.GetUc(); if (UcStr=="CREATE"){return faCreate;} if (UcStr=="UPDATE"){return faUpdate;} if (UcStr=="APPEND"){return faAppend;} if (UcStr=="READONLY"){return faRdOnly;} if (UcStr=="RESTORE"){return faRestore;} if (UcStr=="NEW"){return faCreate;} if (UcStr=="CONT"){return faUpdate;} if (UcStr=="CONTINUE"){return faUpdate;} if (UcStr=="REST"){return faRestore;} if (UcStr=="RESTORE"){return faRestore;} return faUndef; }
int TFRnd::GetFLen | ( | ) |
Definition at line 803 of file fl.cpp.
References EAssertR, FileId, FNm, GetFPos(), SEEK_END, and SetFPos().
Referenced by TGBlobBs::FNextBlobPt(), GetRecs(), GetStr(), and TGBlobBs::PutBlob().
{ int FPos=GetFPos(); EAssertR( fseek(FileId, 0, SEEK_END)==0, "Error seeking into file '"+TStr(FNm)+"'."); int FLen=GetFPos(); SetFPos(FPos); return FLen; }
TStr TFRnd::GetFNm | ( | ) | const |
int TFRnd::GetFPos | ( | ) |
Definition at line 797 of file fl.cpp.
References EAssertR, FileId, and FNm.
Referenced by TGBlobBs::DelBlob(), TGBlobBs::FNextBlobPt(), GetFLen(), GetRecN(), GetStr(), TGBlobBs::PutBlob(), and TGBlobBs::TGBlobBs().
{ int FPos= (int) ftell(FileId); EAssertR(FPos!=-1, "Error seeking into file '"+TStr(FNm)+"'."); return FPos; }
void TFRnd::GetHd | ( | void * | Hd | ) | [inline] |
int TFRnd::GetInt | ( | ) | [inline] |
Definition at line 547 of file fl.h.
Referenced by TGBlobBs::DelBlob(), TGBlobBs::FNextBlobPt(), TGBlobBs::GetBlob(), TBlobBs::GetBlockLenV(), TBlobBs::GetFFreeBlobPtV(), TBlobBs::GetMxSegLen(), and TGBlobBs::PutBlob().
{int Int; GetBf(&Int, sizeof(Int)); return Int;}
void TFRnd::GetRec | ( | void * | Rec, |
const int & | RecN = -1 |
||
) | [inline] |
int TFRnd::GetRecN | ( | ) |
Definition at line 816 of file fl.cpp.
References EAssertR, FNm, GetFPos(), HdLen, IAssert, RecAct, and RecLen.
Referenced by TFRec< THd, TRec >::GetRecN().
{ IAssert(RecAct); int FPos=GetFPos()-HdLen; EAssertR(FPos%RecLen==0, "Invalid position in file'"+TStr(FNm)+"'."); return FPos/RecLen; }
int TFRnd::GetRecs | ( | ) |
Definition at line 823 of file fl.cpp.
References EAssertR, FNm, GetFLen(), HdLen, IAssert, RecAct, and RecLen.
Referenced by TFRec< THd, TRec >::GetRecs().
{ IAssert(RecAct); int FLen=GetFLen()-HdLen; EAssertR(FLen%RecLen==0, "Invalid length of file'"+TStr(FNm)+"'."); return FLen/RecLen; }
PSIn TFRnd::GetSIn | ( | const int & | SInLen, |
TCs & | Cs | ||
) |
Definition at line 891 of file fl.cpp.
References GetBf(), and TCs::GetCsFromBf().
Referenced by TGBlobBs::FNextBlobPt(), and TGBlobBs::GetBlob().
{ char* Bf=new char[BfL]; GetBf(Bf, BfL); Cs=TCs::GetCsFromBf(Bf, BfL); PSIn SIn=PSIn(new TMIn(Bf, BfL, true)); return SIn; }
TStr TFRnd::GetStr | ( | const int & | StrLen | ) |
Definition at line 872 of file fl.cpp.
References EAssertR, FNm, GetBf(), and TCh::NullCh.
Referenced by TBlobBs::AssertBlobBsStateStr(), TBlobBs::AssertVersionStr(), TBlobBs::GetBlockLenV(), TBlobBs::GetFFreeBlobPtV(), and TBlobBs::GetMxSegLen().
{ TStr Str; char* CStr=new char[StrLen+1]; GetBf(CStr, StrLen+1); EAssertR(CStr[StrLen+1-1]==TCh::NullCh, "Error reading file '"+TStr(FNm)+"'."); Str=CStr; delete[] CStr; return Str; }
TStr TFRnd::GetStr | ( | const int & | MxStrLen, |
bool & | IsOk | ||
) |
Definition at line 861 of file fl.cpp.
References GetBf(), GetFLen(), GetFPos(), and TCh::NullCh.
{ IsOk=false; TStr Str; if (GetFPos()+StrLen+1<=GetFLen()){ char* CStr=new char[StrLen+1]; GetBf(CStr, StrLen+1); if (CStr[StrLen+1-1]==TCh::NullCh){IsOk=true; Str=CStr;} delete[] CStr; } return Str; }
TStr TFRnd::GetStrFromFAccess | ( | const TFAccess & | FAccess | ) | [static] |
uchar TFRnd::GetUCh | ( | ) | [inline] |
Definition at line 545 of file fl.h.
Referenced by TBlobPt::Load().
uint TFRnd::GetUInt | ( | ) | [inline] |
Definition at line 549 of file fl.h.
Referenced by TBlobBs::AssertBlobTag(), TBlobPt::Load(), and TBlobPt::LoadAddr().
void TFRnd::MoveFPos | ( | const int & | DFPos | ) |
static PFRnd TFRnd::New | ( | const TStr & | FNm, |
const TFAccess & | FAccess, | ||
const bool & | CreateIfNo = true , |
||
const int & | HdLen = -1 , |
||
const int & | RecLen = -1 |
||
) | [inline, static] |
void TFRnd::PutBf | ( | const void * | Bf, |
const TSize & | BfL | ||
) |
Definition at line 837 of file fl.cpp.
References EAssertR, FileId, FNm, and RefreshFPos().
Referenced by PutCh(), PutSIn(), and PutStr().
{ RefreshFPos(); EAssertR( fwrite(Bf, 1, BfL, FileId)==BfL, "Error writting to the file '"+TStr(FNm)+"'."); }
void TFRnd::PutCh | ( | const char & | Ch | ) | [inline] |
Definition at line 541 of file fl.h.
Referenced by TGBlobBs::DelBlob(), TGBlobBs::PutBlob(), and TBlobBs::PutBlobState().
{PutBf(&Ch, sizeof(Ch));}
void TFRnd::PutCh | ( | const char & | Ch, |
const int & | Chs | ||
) |
void TFRnd::PutCs | ( | const TCs & | Cs | ) | [inline] |
Definition at line 539 of file fl.h.
Referenced by TGBlobBs::PutBlob().
{PutBf(&Cs, sizeof(Cs));}
void TFRnd::PutHd | ( | const void * | Hd | ) | [inline] |
void TFRnd::PutInt | ( | const int & | Int | ) | [inline] |
Definition at line 546 of file fl.h.
Referenced by TGBlobBs::PutBlob(), TBlobBs::PutBlockLenV(), TBlobBs::PutFFreeBlobPtV(), and TBlobBs::PutMxSegLen().
{PutBf(&Int, sizeof(Int));}
void TFRnd::PutRec | ( | const void * | Rec, |
const int & | RecN = -1 |
||
) | [inline] |
void TFRnd::PutSIn | ( | const PSIn & | SIn, |
TCs & | Cs | ||
) |
Definition at line 882 of file fl.cpp.
References TSIn::GetBf(), TCs::GetCsFromBf(), TSIn::Len(), and PutBf().
Referenced by TGBlobBs::PutBlob().
{ int BfL=SIn->Len(); char* Bf=new char[BfL]; SIn->GetBf(Bf, BfL); Cs=TCs::GetCsFromBf(Bf, BfL); PutBf(Bf, BfL); delete[] Bf; }
void TFRnd::PutStr | ( | const TStr & | Str | ) |
Definition at line 857 of file fl.cpp.
References TStr::CStr(), TStr::Len(), and PutBf().
Referenced by TBlobBs::PutBlobBsStateStr(), TBlobBs::PutBlockLenV(), TBlobBs::PutFFreeBlobPtV(), TBlobBs::PutMxSegLen(), and TBlobBs::PutVersionStr().
void TFRnd::PutUCh | ( | const uchar & | UCh | ) | [inline] |
Definition at line 544 of file fl.h.
Referenced by TBlobPt::Save().
{PutBf(&UCh, sizeof(UCh));}
void TFRnd::PutUInt | ( | const uint & | UInt | ) | [inline] |
Definition at line 548 of file fl.h.
Referenced by TBlobBs::PutBlobTag(), TBlobPt::Save(), and TBlobPt::SaveAddr().
{PutBf(&UInt, sizeof(UInt));}
void TFRnd::RefreshFPos | ( | ) | [private] |
void TFRnd::SetFPos | ( | const int & | FPos | ) |
Definition at line 785 of file fl.cpp.
References EAssertR, FileId, FNm, and SEEK_SET.
Referenced by TGBlobBs::DelBlob(), TGBlobBs::FNextBlobPt(), TGBlobBs::GetBlob(), GetFLen(), TGBlobBs::PutBlob(), SetRecN(), TGBlobBs::TGBlobBs(), and TGBlobBs::~TGBlobBs().
void TFRnd::SetHdRecLen | ( | const int & | _HdLen, |
const int & | _RecLen | ||
) | [inline] |
void TFRnd::SetRecN | ( | const int & | RecN | ) |
TCRef TFRnd::CRef [private] |
TFileId TFRnd::FileId [private] |
TSStr TFRnd::FNm [private] |
int TFRnd::HdLen [private] |
bool TFRnd::RecAct [private] |
int TFRnd::RecLen [private] |