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
TFRnd Class Reference

#include <fl.h>

Collaboration diagram for TFRnd:

List of all members.

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 491 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 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+"'.");
}

Here is the call graph for this function:

Definition at line 777 of file fl.cpp.

References EAssertR, FileId, and FNm.

             {
  EAssertR(fclose(FileId)==0, "Can not close file '"+TStr(FNm)+"'.");
}

Member Function Documentation

bool TFRnd::Empty ( ) [inline]

Definition at line 519 of file fl.h.

Referenced by TGBlobBs::TGBlobBs().

{return GetFLen()==0;}

Here is the caller graph for this function:

bool TFRnd::Eof ( ) [inline]

Definition at line 520 of file fl.h.

{return GetFPos()==GetFLen();}
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().

                 {
  EAssertR(fflush(FileId)==0, "Can not flush file '"+TStr(FNm)+"'.");
}

Here is the caller graph for this function:

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)+"'.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;}

Here is the caller graph for this function:

TCs TFRnd::GetCs ( ) [inline]

Definition at line 540 of file fl.h.

Referenced by TGBlobBs::FNextBlobPt(), and TGBlobBs::GetBlob().

{TCs Cs; GetBf(&Cs, sizeof(Cs)); return Cs;}

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

TStr TFRnd::GetFNm ( ) const

Definition at line 781 of file fl.cpp.

References TSStr::CStr(), and FNm.

                         {
  return FNm.CStr();
}

Here is the call graph for this function:

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;
}

Here is the caller graph for this function:

void TFRnd::GetHd ( void *  Hd) [inline]

Definition at line 530 of file fl.h.

References IAssert.

Referenced by TFRec< THd, TRec >::GetHd().

                      {IAssert(RecAct);
    int FPos=GetFPos(); SetFPos(0); GetBf(Hd, HdLen); SetFPos(FPos);}

Here is the caller graph for this function:

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;}

Here is the caller graph for this function:

void TFRnd::GetRec ( void *  Rec,
const int &  RecN = -1 
) [inline]

Definition at line 534 of file fl.h.

References IAssert.

Referenced by TFRec< THd, TRec >::GetRec().

                                            {
    IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} GetBf(Rec, RecLen);}

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

TStr TFRnd::GetStrFromFAccess ( const TFAccess FAccess) [static]

Definition at line 899 of file fl.cpp.

References faAppend, faCreate, Fail, faRdOnly, faRestore, and faUpdate.

                                                    {
  switch (FAccess){
    case faCreate: return "Create";
    case faUpdate: return "Update";
    case faAppend: return "Append";
    case faRdOnly: return "ReadOnly";
    case faRestore: return "Restore";
    default: Fail; return TStr();
  }
}
uchar TFRnd::GetUCh ( ) [inline]

Definition at line 545 of file fl.h.

Referenced by TBlobPt::Load().

{uchar UCh; GetBf(&UCh, sizeof(UCh)); return UCh;}

Here is the caller graph for this function:

uint TFRnd::GetUInt ( ) [inline]

Definition at line 549 of file fl.h.

Referenced by TBlobBs::AssertBlobTag(), TBlobPt::Load(), and TBlobPt::LoadAddr().

{uint UInt; GetBf(&UInt, sizeof(UInt)); return UInt;}

Here is the caller graph for this function:

void TFRnd::MoveFPos ( const int &  DFPos)

Definition at line 791 of file fl.cpp.

References EAssertR, FileId, FNm, and SEEK_CUR.

Referenced by TGBlobBs::FNextBlobPt(), and TGBlobBs::GetBlob().

                                    {
  EAssertR(
   fseek(FileId, DFPos, SEEK_CUR)==0,
   "Error seeking into file '"+TStr(FNm)+"'.");
}

Here is the caller graph for this function:

static PFRnd TFRnd::New ( const TStr FNm,
const TFAccess FAccess,
const bool &  CreateIfNo = true,
const int &  HdLen = -1,
const int &  RecLen = -1 
) [inline, static]

Definition at line 505 of file fl.h.

                                             {
    return new TFRnd(FNm, FAccess, CreateIfNo, HdLen, RecLen);}
TFRnd& TFRnd::operator= ( const TFRnd ) [private]
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)+"'.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

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));}

Here is the caller graph for this function:

void TFRnd::PutCh ( const char &  Ch,
const int &  Chs 
)

Definition at line 848 of file fl.cpp.

References PutBf().

                                               {
  if (Chs>0){
    char* CStr=new char[Chs];
    for (int ChN=0; ChN<Chs; ChN++){CStr[ChN]=Ch;}
    PutBf(CStr, Chs);
    delete[] CStr;
  }
}

Here is the call graph for this function:

void TFRnd::PutCs ( const TCs Cs) [inline]

Definition at line 539 of file fl.h.

Referenced by TGBlobBs::PutBlob().

{PutBf(&Cs, sizeof(Cs));}

Here is the caller graph for this function:

void TFRnd::PutHd ( const void *  Hd) [inline]

Definition at line 532 of file fl.h.

References IAssert.

Referenced by TFRec< THd, TRec >::PutHd().

                            {IAssert(RecAct);
    int FPos=GetFPos(); SetFPos(0); PutBf(Hd, HdLen); SetFPos(FPos);}

Here is the caller graph for this function:

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));}

Here is the caller graph for this function:

void TFRnd::PutRec ( const void *  Rec,
const int &  RecN = -1 
) [inline]

Definition at line 536 of file fl.h.

References IAssert.

Referenced by TFRec< THd, TRec >::PutRec().

                                                  {
    IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} PutBf(Rec, RecLen);}

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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().

                                 {
  PutBf(Str.CStr(), Str.Len()+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TFRnd::PutUCh ( const uchar UCh) [inline]

Definition at line 544 of file fl.h.

Referenced by TBlobPt::Save().

{PutBf(&UCh, sizeof(UCh));}

Here is the caller graph for this function:

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));}

Here is the caller graph for this function:

void TFRnd::RefreshFPos ( ) [private]

Definition at line 753 of file fl.cpp.

References EAssertR, FileId, FNm, and SEEK_CUR.

Referenced by GetBf(), and PutBf().

                       {
  EAssertR(
   fseek(FileId, 0, SEEK_CUR)==0,
   "Error seeking into file '"+TStr(FNm)+"'.");
}

Here is the caller graph for this function:

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().

                                  {
  EAssertR(
   fseek(FileId, FPos, SEEK_SET)==0,
   "Error seeking into file '"+TStr(FNm)+"'.");
}

Here is the caller graph for this function:

void TFRnd::SetHdRecLen ( const int &  _HdLen,
const int &  _RecLen 
) [inline]

Definition at line 512 of file fl.h.

                                                         {
    HdLen=_HdLen; RecLen=_RecLen; RecAct=(HdLen>=0)&&(RecLen>0);}
void TFRnd::SetRecN ( const int &  RecN)

Definition at line 811 of file fl.cpp.

References HdLen, IAssert, RecAct, RecLen, and SetFPos().

Referenced by TFRec< THd, TRec >::SetRecN().

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class TPt< TFRnd > [friend]

Definition at line 491 of file fl.h.


Member Data Documentation

TCRef TFRnd::CRef [private]

Definition at line 491 of file fl.h.

Definition at line 493 of file fl.h.

Referenced by Flush(), GetBf(), GetFLen(), GetFPos(), MoveFPos(), PutBf(), RefreshFPos(), SetFPos(), TFRnd(), and ~TFRnd().

int TFRnd::HdLen [private]

Definition at line 496 of file fl.h.

Referenced by GetRecN(), GetRecs(), SetRecN(), and TFRnd().

bool TFRnd::RecAct [private]

Definition at line 495 of file fl.h.

Referenced by GetRecN(), GetRecs(), SetRecN(), and TFRnd().

int TFRnd::RecLen [private]

Definition at line 496 of file fl.h.

Referenced by GetRecN(), GetRecs(), SetRecN(), and TFRnd().


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