SNAP Library 2.2, User 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
TMBlobBs Class Reference

#include <blobbs.h>

Inherits TBlobBs.

List of all members.

Public Member Functions

 TMBlobBs (const TStr &BlobBsFNm, const TFAccess &_Access=faRdOnly, const int &_MxSegLen=-1)
 ~TMBlobBs ()
TMBlobBsoperator= (const TMBlobBs &)
TStr GetVersionStr () const
TBlobPt PutBlob (const PSIn &SIn)
TBlobPt PutBlob (const TBlobPt &BlobPt, const PSIn &SIn)
PSIn GetBlob (const TBlobPt &BlobPt)
void DelBlob (const TBlobPt &BlobPt)
TBlobPt GetFirstBlobPt ()
TBlobPt FFirstBlobPt ()
bool FNextBlobPt (TBlobPt &TrvBlobPt, TBlobPt &BlobPt, PSIn &BlobSIn)

Static Public Member Functions

static PBlobBs New (const TStr &BlobBsFNm, const TFAccess &Access=faRdOnly, const int &MxSegLen=-1)
static bool Exists (const TStr &BlobBsFNm)

Private Member Functions

void LoadMain (int &Segs)
void SaveMain () const

Static Private Member Functions

static void GetNrFPathFMid (const TStr &BlobBsFNm, TStr &NrFPath, TStr &NrFMid)
static TStr GetMainFNm (const TStr &NrFPath, const TStr &NrFMid)
static TStr GetSegFNm (const TStr &NrFPath, const TStr &NrFMid, const int &SegN)

Private Attributes

TFAccess Access
int MxSegLen
TStr NrFPath
TStr NrFMid
TBlobBsV SegV
int CurSegN

Detailed Description

Definition at line 188 of file blobbs.h.


Constructor & Destructor Documentation

TMBlobBs::TMBlobBs ( const TStr BlobBsFNm,
const TFAccess _Access = faRdOnly,
const int &  _MxSegLen = -1 
)

Definition at line 449 of file blobbs.cpp.

                                                                      :
  TBlobBs(), Access(_Access), MxSegLen(_MxSegLen),
  NrFPath(), NrFMid(), SegV(), CurSegN(0){
  if (MxSegLen==-1){MxSegLen=MxBlobFLen;}
  GetNrFPathFMid(BlobBsFNm, NrFPath, NrFMid);
  switch (Access){
    case faCreate:{
      TFile::DelWc(BlobBsFNm+".*");
      TStr SegFNm=GetSegFNm(NrFPath, NrFMid, 0);
      PBlobBs Seg=TGBlobBs::New(SegFNm, faCreate, MxSegLen);
      SegV.Add(Seg);
      SaveMain(); break;}
    case faUpdate:
    case faRdOnly:{
      int Segs; LoadMain(Segs);
      for (int SegN=0; SegN<Segs; SegN++){
        TStr SegFNm=GetSegFNm(NrFPath, NrFMid, SegN);
        SegV.Add(TGBlobBs::New(SegFNm, Access, MxSegLen));
      }
      break;}
    case faRestore:{
      // assume no segments
      int Segs=-1;
      // if main-file exists
      if (TFile::Exists(GetMainFNm(NrFPath, NrFMid))){
        // load main file
        int _Segs; LoadMain(_Segs);
        // load segment-files which exist
        Segs=0;
        forever {
          // get segment file-name
          TStr SegFNm=GetSegFNm(NrFPath, NrFMid, Segs);
          // if segment-file exists then add segment else break check-loop
          if (TFile::Exists(SegFNm)){
            SegV.Add(TGBlobBs::New(SegFNm, Access, MxSegLen));
            Segs++;
          } else {
            break;
          }
        }
      }
      // if no segments exist then create blob-base from scratch
      if (Segs==-1){
        TStr SegFNm=GetSegFNm(NrFPath, NrFMid, 0);
        PBlobBs Seg=TGBlobBs::New(SegFNm, faCreate, MxSegLen);
        SegV.Add(Seg);
        SaveMain();
      }
      break;}
    default: Fail;
  }
}

Definition at line 503 of file blobbs.cpp.

                   {
  if (Access!=faRdOnly){
    SaveMain();
  }
}

Member Function Documentation

void TMBlobBs::DelBlob ( const TBlobPt BlobPt) [virtual]

Implements TBlobBs.

Definition at line 546 of file blobbs.cpp.

                                           {
  int SegN=BlobPt.GetSeg();
  SegV[SegN]->DelBlob(BlobPt);
}
bool TMBlobBs::Exists ( const TStr BlobBsFNm) [static]

Definition at line 576 of file blobbs.cpp.

                                          {
  TStr NrFPath; TStr NrFMid; GetNrFPathFMid(BlobBsFNm, NrFPath, NrFMid);
  TStr MainFNm=GetMainFNm(NrFPath, NrFMid);
  return TFile::Exists(MainFNm);
}

Implements TBlobBs.

Definition at line 555 of file blobbs.cpp.

                              {
  return SegV[0]->FFirstBlobPt();
}
bool TMBlobBs::FNextBlobPt ( TBlobPt TrvBlobPt,
TBlobPt BlobPt,
PSIn BlobSIn 
) [virtual]

Implements TBlobBs.

Definition at line 559 of file blobbs.cpp.

                                                                            {
  uchar SegN=TrvBlobPt.GetSeg();
  if (SegV[SegN]->FNextBlobPt(TrvBlobPt, BlobPt, BlobSIn)){
    TrvBlobPt.PutSeg(SegN);
    BlobPt.PutSeg(SegN);
    return true;
  } else
  if (SegN==SegV.Len()-1){
    return false;
  } else {
    SegN++;
    TrvBlobPt=SegV[SegN]->FFirstBlobPt();
    TrvBlobPt.PutSeg(SegN);
    return FNextBlobPt(TrvBlobPt, BlobPt, BlobSIn);
  }
}
PSIn TMBlobBs::GetBlob ( const TBlobPt BlobPt) [virtual]

Implements TBlobBs.

Definition at line 541 of file blobbs.cpp.

                                           {
  int SegN=BlobPt.GetSeg();
  return SegV[SegN]->GetBlob(BlobPt);
}

Implements TBlobBs.

Definition at line 551 of file blobbs.cpp.

                                {
  return SegV[0]->GetFirstBlobPt();
}
TStr TMBlobBs::GetMainFNm ( const TStr NrFPath,
const TStr NrFMid 
) [static, private]

Definition at line 423 of file blobbs.cpp.

                                         {
  return NrFPath+NrFMid+".mbb";
}
void TMBlobBs::GetNrFPathFMid ( const TStr BlobBsFNm,
TStr NrFPath,
TStr NrFMid 
) [static, private]

Definition at line 417 of file blobbs.cpp.

                                                    {
  NrFPath=TStr::GetNrFPath(BlobBsFNm.GetFPath());
  NrFMid=TStr::GetNrFMid(BlobBsFNm.GetFMid());
}
TStr TMBlobBs::GetSegFNm ( const TStr NrFPath,
const TStr NrFMid,
const int &  SegN 
) [static, private]

Definition at line 428 of file blobbs.cpp.

                                                          {
  return NrFPath+NrFMid+".mbb"+""+TStr::GetNrNumFExt(SegN);
}
TStr TMBlobBs::GetVersionStr ( ) const [inline, virtual]

Implements TBlobBs.

Definition at line 210 of file blobbs.h.

                             {
    return TStr("Multiple-File Blob Base Format 1.0");}
void TMBlobBs::LoadMain ( int &  Segs) [private]

Definition at line 433 of file blobbs.cpp.

                                {
  PSIn SIn=TFIn::New(GetMainFNm(NrFPath, NrFMid));
  TILx Lx(SIn, TFSet()|oloFrcEoln|oloSigNum|oloCsSens);
  EAssert(Lx.GetVarStr("Version")==GetVersionStr());
  MxSegLen=Lx.GetVarInt("MxSegLen");
  Segs=Lx.GetVarInt("Segments");
}
static PBlobBs TMBlobBs::New ( const TStr BlobBsFNm,
const TFAccess Access = faRdOnly,
const int &  MxSegLen = -1 
) [inline, static]

Definition at line 203 of file blobbs.h.

                          {
    return PBlobBs(new TMBlobBs(BlobBsFNm, Access, MxSegLen));}
TMBlobBs& TMBlobBs::operator= ( const TMBlobBs ) [inline]

Definition at line 208 of file blobbs.h.

{Fail; return *this;}
TBlobPt TMBlobBs::PutBlob ( const PSIn SIn) [virtual]

Implements TBlobBs.

Definition at line 509 of file blobbs.cpp.

                                        {
  EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
  TBlobPt BlobPt=SegV[CurSegN]->PutBlob(SIn);
  if (BlobPt.Empty()){
    for (uchar SegN=0; SegN<SegV.Len(); SegN++){
      BlobPt=SegV[CurSegN=SegN]->PutBlob(SIn);
      if (!BlobPt.Empty()){break;}
    }
    if (BlobPt.Empty()){
      TStr SegFNm=GetSegFNm(NrFPath, NrFMid, SegV.Len());
      PBlobBs Seg=TGBlobBs::New(SegFNm, faCreate, MxSegLen);
      CurSegN=SegV.Add(Seg); EAssert(CurSegN<=255);
      BlobPt=SegV[CurSegN]->PutBlob(SIn);
    }
  }
  if (!BlobPt.Empty()){
    BlobPt.PutSeg(uchar(CurSegN));}
  return BlobPt;
}
TBlobPt TMBlobBs::PutBlob ( const TBlobPt BlobPt,
const PSIn SIn 
) [virtual]

Implements TBlobBs.

Definition at line 529 of file blobbs.cpp.

                                                               {
  EAssert((Access==faCreate)||(Access==faUpdate)||(Access==faRestore));
  int SegN=BlobPt.GetSeg();
  TBlobPt NewBlobPt=SegV[SegN]->PutBlob(BlobPt, SIn);
  if (NewBlobPt.Empty()){
    NewBlobPt=PutBlob(SIn);
  } else {
    NewBlobPt.PutSeg(BlobPt.GetSeg());
  }
  return NewBlobPt;
}
void TMBlobBs::SaveMain ( ) const [private]

Definition at line 441 of file blobbs.cpp.

                              {
  PSOut SOut=TFOut::New(GetMainFNm(NrFPath, NrFMid));
  TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum|oloCsSens);
  Lx.PutVarStr("Version", GetVersionStr());
  Lx.PutVarInt("MxSegLen", MxSegLen);
  Lx.PutVarInt("Segments", SegV.Len());
}

Member Data Documentation

Definition at line 190 of file blobbs.h.

int TMBlobBs::CurSegN [private]

Definition at line 194 of file blobbs.h.

int TMBlobBs::MxSegLen [private]

Definition at line 191 of file blobbs.h.

Definition at line 192 of file blobbs.h.

Definition at line 192 of file blobbs.h.

Definition at line 193 of file blobbs.h.


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