SNAP Library 2.0, User Reference  2013-05-13 16:33:57
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>

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.

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

Definition at line 777 of file fl.cpp.

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

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

                 {
  EAssertR(fflush(FileId)==0, "Can not flush file '"+TStr(FNm)+"'.");
}
void TFRnd::GetBf ( void *  Bf,
const TSize BfL 
)

Definition at line 830 of file fl.cpp.

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

{char Ch; GetBf(&Ch, sizeof(Ch)); return Ch;}
TCs TFRnd::GetCs ( ) [inline]

Definition at line 540 of file fl.h.

{TCs Cs; GetBf(&Cs, sizeof(Cs)); return Cs;}
TFAccess TFRnd::GetFAccessFromStr ( const TStr Str) [static]

Definition at line 910 of file fl.cpp.

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

                  {
  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

Definition at line 781 of file fl.cpp.

                         {
  return FNm.CStr();
}
int TFRnd::GetFPos ( )

Definition at line 797 of file fl.cpp.

                  {
  int FPos= (int) ftell(FileId);
  EAssertR(FPos!=-1, "Error seeking into file '"+TStr(FNm)+"'.");
  return FPos;
}
void TFRnd::GetHd ( void *  Hd) [inline]

Definition at line 530 of file fl.h.

                      {IAssert(RecAct);
    int FPos=GetFPos(); SetFPos(0); GetBf(Hd, HdLen); SetFPos(FPos);}
int TFRnd::GetInt ( ) [inline]

Definition at line 547 of file fl.h.

{int Int; GetBf(&Int, sizeof(Int)); return Int;}
void TFRnd::GetRec ( void *  Rec,
const int &  RecN = -1 
) [inline]

Definition at line 534 of file fl.h.

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

Definition at line 816 of file fl.cpp.

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

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

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

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

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

Definition at line 899 of file fl.cpp.

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

{uchar UCh; GetBf(&UCh, sizeof(UCh)); return UCh;}
uint TFRnd::GetUInt ( ) [inline]

Definition at line 549 of file fl.h.

{uint UInt; GetBf(&UInt, sizeof(UInt)); return UInt;}
void TFRnd::MoveFPos ( const int &  DFPos)

Definition at line 791 of file fl.cpp.

                                    {
  EAssertR(
   fseek(FileId, DFPos, SEEK_CUR)==0,
   "Error seeking into file '"+TStr(FNm)+"'.");
}
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.

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

{PutBf(&Ch, sizeof(Ch));}
void TFRnd::PutCh ( const char &  Ch,
const int &  Chs 
)

Definition at line 848 of file fl.cpp.

                                               {
  if (Chs>0){
    char* CStr=new char[Chs];
    for (int ChN=0; ChN<Chs; ChN++){CStr[ChN]=Ch;}
    PutBf(CStr, Chs);
    delete[] CStr;
  }
}
void TFRnd::PutCs ( const TCs Cs) [inline]

Definition at line 539 of file fl.h.

{PutBf(&Cs, sizeof(Cs));}
void TFRnd::PutHd ( const void *  Hd) [inline]

Definition at line 532 of file fl.h.

                            {IAssert(RecAct);
    int FPos=GetFPos(); SetFPos(0); PutBf(Hd, HdLen); SetFPos(FPos);}
void TFRnd::PutInt ( const int &  Int) [inline]

Definition at line 546 of file fl.h.

{PutBf(&Int, sizeof(Int));}
void TFRnd::PutRec ( const void *  Rec,
const int &  RecN = -1 
) [inline]

Definition at line 536 of file fl.h.

                                                  {
    IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} PutBf(Rec, RecLen);}
void TFRnd::PutSIn ( const PSIn SIn,
TCs Cs 
)

Definition at line 882 of file fl.cpp.

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

                                 {
  PutBf(Str.CStr(), Str.Len()+1);
}
void TFRnd::PutUCh ( const uchar UCh) [inline]

Definition at line 544 of file fl.h.

{PutBf(&UCh, sizeof(UCh));}
void TFRnd::PutUInt ( const uint UInt) [inline]

Definition at line 548 of file fl.h.

{PutBf(&UInt, sizeof(UInt));}
void TFRnd::RefreshFPos ( ) [private]

Definition at line 753 of file fl.cpp.

                       {
  EAssertR(
   fseek(FileId, 0, SEEK_CUR)==0,
   "Error seeking into file '"+TStr(FNm)+"'.");
}
void TFRnd::SetFPos ( const int &  FPos)

Definition at line 785 of file fl.cpp.

                                  {
  EAssertR(
   fseek(FileId, FPos, SEEK_SET)==0,
   "Error seeking into file '"+TStr(FNm)+"'.");
}
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.


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.

TSStr TFRnd::FNm [private]

Definition at line 494 of file fl.h.

int TFRnd::HdLen [private]

Definition at line 496 of file fl.h.

bool TFRnd::RecAct [private]

Definition at line 495 of file fl.h.

int TFRnd::RecLen [private]

Definition at line 496 of file fl.h.


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