SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TMBlobBs Class Reference

#include <blobbs.h>

Inherits TBlobBs.

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)
 
- Public Member Functions inherited from TBlobBs
 UndefCopyAssign (TBlobBs)
 
 TBlobBs ()
 
virtual ~TBlobBs ()
 
 TBlobBs (TSIn &)
 
void Save (TSOut &) const
 
void PutVersionStr (const PFRnd &FBlobBs)
 
void AssertVersionStr (const PFRnd &FBlobBs)
 
TStr GetBlobBsStateStr (const TBlobBsState &BlobBsState)
 
int GetStateStrLen ()
 
void PutBlobBsStateStr (const PFRnd &FBlobBs, const TBlobBsState &State)
 
void AssertBlobBsStateStr (const PFRnd &FBlobBs, const TBlobBsState &State)
 
void PutMxSegLen (const PFRnd &FBlobBs, const int &MxSegLen)
 
int GetMxSegLen (const PFRnd &FBlobBs)
 
void GenBlockLenV (TIntV &BlockLenV)
 
void PutBlockLenV (const PFRnd &FBlobBs, const TIntV &BlockLenV)
 
void GetBlockLenV (const PFRnd &FBlobBs, TIntV &BlockLenV)
 
void GenFFreeBlobPtV (const TIntV &BlockLenV, TBlobPtV &FFreeBlobPtV)
 
void PutFFreeBlobPtV (const PFRnd &FBlobBs, const TBlobPtV &FFreeBlobPtV)
 
void GetFFreeBlobPtV (const PFRnd &FBlobBs, TBlobPtV &FFreeBlobPtV)
 
void GetAllocInfo (const int &BfL, const TIntV &BlockLenV, int &MxBfL, int &FFreeBlobPtN)
 
uint GetBeginBlobTag ()
 
uint GetEndBlobTag ()
 
void PutBlobTag (const PFRnd &FBlobBs, const TBlobTag &BlobTag)
 
void AssertBlobTag (const PFRnd &FBlobBs, const TBlobTag &BlobTag)
 
void PutBlobState (const PFRnd &FBlobBs, const TBlobState &State)
 
TBlobState GetBlobState (const PFRnd &FBlobBs)
 
void AssertBlobState (const PFRnd &FBlobBs, const TBlobState &State)
 
void AssertBfCsEqFlCs (const TCs &BfCs, const TCs &FCs)
 
TBlobPt PutBlob (const TStr &Str)
 
bool FNextBlobPt (TBlobPt &TrvBlobPt, 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)
 
- Static Public Member Functions inherited from TBlobBs
static PBlobBs Load (TSIn &)
 

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
 

Additional Inherited Members

- Static Public Attributes inherited from TBlobBs
static const int MnBlobBfL =16
 
static const int MxBlobFLen =1000000000
 
static const TStr MxSegLenVNm ="MxSegLen"
 
static const TStr BlockLenVNm ="BlockLenV"
 
static const TStr FFreeBlobPtVNm ="FFreeBlobPtV"
 

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.

450  :
451  TBlobBs(), Access(_Access), MxSegLen(_MxSegLen),
452  NrFPath(), NrFMid(), SegV(), CurSegN(0){
453  if (MxSegLen==-1){MxSegLen=MxBlobFLen;}
454  GetNrFPathFMid(BlobBsFNm, NrFPath, NrFMid);
455  switch (Access){
456  case faCreate:{
457  TFile::DelWc(BlobBsFNm+".*");
458  TStr SegFNm=GetSegFNm(NrFPath, NrFMid, 0);
459  PBlobBs Seg=TGBlobBs::New(SegFNm, faCreate, MxSegLen);
460  SegV.Add(Seg);
461  SaveMain(); break;}
462  case faUpdate:
463  case faRdOnly:{
464  int Segs; LoadMain(Segs);
465  for (int SegN=0; SegN<Segs; SegN++){
466  TStr SegFNm=GetSegFNm(NrFPath, NrFMid, SegN);
467  SegV.Add(TGBlobBs::New(SegFNm, Access, MxSegLen));
468  }
469  break;}
470  case faRestore:{
471  // assume no segments
472  int Segs=-1;
473  // if main-file exists
475  // load main file
476  int _Segs; LoadMain(_Segs);
477  // load segment-files which exist
478  Segs=0;
479  forever {
480  // get segment file-name
481  TStr SegFNm=GetSegFNm(NrFPath, NrFMid, Segs);
482  // if segment-file exists then add segment else break check-loop
483  if (TFile::Exists(SegFNm)){
484  SegV.Add(TGBlobBs::New(SegFNm, Access, MxSegLen));
485  Segs++;
486  } else {
487  break;
488  }
489  }
490  }
491  // if no segments exist then create blob-base from scratch
492  if (Segs==-1){
493  TStr SegFNm=GetSegFNm(NrFPath, NrFMid, 0);
494  PBlobBs Seg=TGBlobBs::New(SegFNm, faCreate, MxSegLen);
495  SegV.Add(Seg);
496  SaveMain();
497  }
498  break;}
499  default: Fail;
500  }
501 }
static void GetNrFPathFMid(const TStr &BlobBsFNm, TStr &NrFPath, TStr &NrFMid)
Definition: blobbs.cpp:417
Definition: fl.h:347
void SaveMain() const
Definition: blobbs.cpp:441
static bool Exists(const TStr &FNm)
Definition: fl.cpp:1156
#define forever
Definition: bd.h:6
static TStr GetSegFNm(const TStr &NrFPath, const TStr &NrFMid, const int &SegN)
Definition: blobbs.cpp:428
#define Fail
Definition: bd.h:238
Definition: fl.h:347
void LoadMain(int &Segs)
Definition: blobbs.cpp:433
TBlobBs()
Definition: blobbs.h:95
static void DelWc(const TStr &WcStr, const bool &RecurseDirP=false)
Definition: fl.cpp:1264
Definition: fl.h:347
static PBlobBs New(const TStr &BlobBsFNm, const TFAccess &Access=faRdOnly, const int &MxSegLen=-1)
Definition: blobbs.h:166
TFAccess Access
Definition: blobbs.h:190
TStr NrFPath
Definition: blobbs.h:192
TBlobBsV SegV
Definition: blobbs.h:193
static TStr GetMainFNm(const TStr &NrFPath, const TStr &NrFMid)
Definition: blobbs.cpp:423
int CurSegN
Definition: blobbs.h:194
Definition: dt.h:412
TStr NrFMid
Definition: blobbs.h:192
Definition: bd.h:196
int MxSegLen
Definition: blobbs.h:191
static const int MxBlobFLen
Definition: blobbs.h:92
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
Definition: fl.h:347
TMBlobBs::~TMBlobBs ( )

Definition at line 503 of file blobbs.cpp.

503  {
504  if (Access!=faRdOnly){
505  SaveMain();
506  }
507 }
void SaveMain() const
Definition: blobbs.cpp:441
Definition: fl.h:347
TFAccess Access
Definition: blobbs.h:190

Member Function Documentation

void TMBlobBs::DelBlob ( const TBlobPt BlobPt)
virtual

Implements TBlobBs.

Definition at line 546 of file blobbs.cpp.

546  {
547  int SegN=BlobPt.GetSeg();
548  SegV[SegN]->DelBlob(BlobPt);
549 }
uchar GetSeg() const
Definition: blobbs.h:52
TBlobBsV SegV
Definition: blobbs.h:193
bool TMBlobBs::Exists ( const TStr BlobBsFNm)
static

Definition at line 576 of file blobbs.cpp.

576  {
577  TStr NrFPath; TStr NrFMid; GetNrFPathFMid(BlobBsFNm, NrFPath, NrFMid);
578  TStr MainFNm=GetMainFNm(NrFPath, NrFMid);
579  return TFile::Exists(MainFNm);
580 }
static void GetNrFPathFMid(const TStr &BlobBsFNm, TStr &NrFPath, TStr &NrFMid)
Definition: blobbs.cpp:417
static bool Exists(const TStr &FNm)
Definition: fl.cpp:1156
TStr NrFPath
Definition: blobbs.h:192
static TStr GetMainFNm(const TStr &NrFPath, const TStr &NrFMid)
Definition: blobbs.cpp:423
Definition: dt.h:412
TStr NrFMid
Definition: blobbs.h:192
TBlobPt TMBlobBs::FFirstBlobPt ( )
virtual

Implements TBlobBs.

Definition at line 555 of file blobbs.cpp.

555  {
556  return SegV[0]->FFirstBlobPt();
557 }
TBlobBsV SegV
Definition: blobbs.h:193
bool TMBlobBs::FNextBlobPt ( TBlobPt TrvBlobPt,
TBlobPt BlobPt,
PSIn BlobSIn 
)
virtual

Implements TBlobBs.

Definition at line 559 of file blobbs.cpp.

559  {
560  uchar SegN=TrvBlobPt.GetSeg();
561  if (SegV[SegN]->FNextBlobPt(TrvBlobPt, BlobPt, BlobSIn)){
562  TrvBlobPt.PutSeg(SegN);
563  BlobPt.PutSeg(SegN);
564  return true;
565  } else
566  if (SegN==SegV.Len()-1){
567  return false;
568  } else {
569  SegN++;
570  TrvBlobPt=SegV[SegN]->FFirstBlobPt();
571  TrvBlobPt.PutSeg(SegN);
572  return FNextBlobPt(TrvBlobPt, BlobPt, BlobSIn);
573  }
574 }
uchar GetSeg() const
Definition: blobbs.h:52
void PutSeg(const uchar &_Seg)
Definition: blobbs.h:51
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
unsigned char uchar
Definition: bd.h:10
TBlobBsV SegV
Definition: blobbs.h:193
bool FNextBlobPt(TBlobPt &TrvBlobPt, TBlobPt &BlobPt, PSIn &BlobSIn)
Definition: blobbs.cpp:559
PSIn TMBlobBs::GetBlob ( const TBlobPt BlobPt)
virtual

Implements TBlobBs.

Definition at line 541 of file blobbs.cpp.

541  {
542  int SegN=BlobPt.GetSeg();
543  return SegV[SegN]->GetBlob(BlobPt);
544 }
uchar GetSeg() const
Definition: blobbs.h:52
TBlobBsV SegV
Definition: blobbs.h:193
TBlobPt TMBlobBs::GetFirstBlobPt ( )
virtual

Implements TBlobBs.

Definition at line 551 of file blobbs.cpp.

551  {
552  return SegV[0]->GetFirstBlobPt();
553 }
TBlobBsV SegV
Definition: blobbs.h:193
TStr TMBlobBs::GetMainFNm ( const TStr NrFPath,
const TStr NrFMid 
)
staticprivate

Definition at line 423 of file blobbs.cpp.

424  {
425  return NrFPath+NrFMid+".mbb";
426 }
void TMBlobBs::GetNrFPathFMid ( const TStr BlobBsFNm,
TStr NrFPath,
TStr NrFMid 
)
staticprivate

Definition at line 417 of file blobbs.cpp.

418  {
419  NrFPath=TStr::GetNrFPath(BlobBsFNm.GetFPath());
420  NrFMid=TStr::GetNrFMid(BlobBsFNm.GetFMid());
421 }
TStr GetFMid() const
Definition: dt.cpp:1403
TStr GetFPath() const
Definition: dt.cpp:1389
static TStr GetNrFMid(const TStr &FMid)
Definition: dt.cpp:1445
static TStr GetNrFPath(const TStr &FPath)
Definition: dt.cpp:1430
TStr TMBlobBs::GetSegFNm ( const TStr NrFPath,
const TStr NrFMid,
const int &  SegN 
)
staticprivate

Definition at line 428 of file blobbs.cpp.

429  {
430  return NrFPath+NrFMid+".mbb"+""+TStr::GetNrNumFExt(SegN);
431 }
static TStr GetNrNumFExt(const int &FExtN)
Definition: dt.cpp:1460
TStr TMBlobBs::GetVersionStr ( ) const
inlinevirtual

Implements TBlobBs.

Definition at line 210 of file blobbs.h.

210  {
211  return TStr("Multiple-File Blob Base Format 1.0");}
Definition: dt.h:412
void TMBlobBs::LoadMain ( int &  Segs)
private

Definition at line 433 of file blobbs.cpp.

433  {
436  EAssert(Lx.GetVarStr("Version")==GetVersionStr());
437  MxSegLen=Lx.GetVarInt("MxSegLen");
438  Segs=Lx.GetVarInt("Segments");
439 }
Definition: lx.h:248
Definition: bits.h:119
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
Definition: lx.h:129
TStr NrFPath
Definition: blobbs.h:192
static TStr GetMainFNm(const TStr &NrFPath, const TStr &NrFMid)
Definition: blobbs.cpp:423
TStr GetVersionStr() const
Definition: blobbs.h:210
#define EAssert(Cond)
Definition: bd.h:280
Definition: lx.h:249
TStr NrFMid
Definition: blobbs.h:192
Definition: lx.h:248
int MxSegLen
Definition: blobbs.h:191
static PBlobBs TMBlobBs::New ( const TStr BlobBsFNm,
const TFAccess Access = faRdOnly,
const int &  MxSegLen = -1 
)
inlinestatic

Definition at line 203 of file blobbs.h.

204  {
205  return PBlobBs(new TMBlobBs(BlobBsFNm, Access, MxSegLen));}
TFAccess Access
Definition: blobbs.h:190
TPt< TBlobBs > PBlobBs
Definition: blobbs.h:89
int MxSegLen
Definition: blobbs.h:191
TMBlobBs(const TStr &BlobBsFNm, const TFAccess &_Access=faRdOnly, const int &_MxSegLen=-1)
Definition: blobbs.cpp:449
TMBlobBs& TMBlobBs::operator= ( const TMBlobBs )
inline

Definition at line 208 of file blobbs.h.

208 {Fail; return *this;}
#define Fail
Definition: bd.h:238
TBlobPt TMBlobBs::PutBlob ( const PSIn SIn)
virtual

Implements TBlobBs.

Definition at line 509 of file blobbs.cpp.

509  {
511  TBlobPt BlobPt=SegV[CurSegN]->PutBlob(SIn);
512  if (BlobPt.Empty()){
513  for (uchar SegN=0; SegN<SegV.Len(); SegN++){
514  BlobPt=SegV[CurSegN=SegN]->PutBlob(SIn);
515  if (!BlobPt.Empty()){break;}
516  }
517  if (BlobPt.Empty()){
518  TStr SegFNm=GetSegFNm(NrFPath, NrFMid, SegV.Len());
519  PBlobBs Seg=TGBlobBs::New(SegFNm, faCreate, MxSegLen);
520  CurSegN=SegV.Add(Seg); EAssert(CurSegN<=255);
521  BlobPt=SegV[CurSegN]->PutBlob(SIn);
522  }
523  }
524  if (!BlobPt.Empty()){
525  BlobPt.PutSeg(uchar(CurSegN));}
526  return BlobPt;
527 }
void PutSeg(const uchar &_Seg)
Definition: blobbs.h:51
Definition: fl.h:347
static TStr GetSegFNm(const TStr &NrFPath, const TStr &NrFMid, const int &SegN)
Definition: blobbs.cpp:428
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: fl.h:347
static PBlobBs New(const TStr &BlobBsFNm, const TFAccess &Access=faRdOnly, const int &MxSegLen=-1)
Definition: blobbs.h:166
TFAccess Access
Definition: blobbs.h:190
unsigned char uchar
Definition: bd.h:10
TStr NrFPath
Definition: blobbs.h:192
TBlobBsV SegV
Definition: blobbs.h:193
int CurSegN
Definition: blobbs.h:194
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: blobbs.h:49
Definition: dt.h:412
Definition: blobbs.h:5
TStr NrFMid
Definition: blobbs.h:192
Definition: bd.h:196
int MxSegLen
Definition: blobbs.h:191
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
Definition: fl.h:347
TBlobPt TMBlobBs::PutBlob ( const TBlobPt BlobPt,
const PSIn SIn 
)
virtual

Implements TBlobBs.

Definition at line 529 of file blobbs.cpp.

529  {
531  int SegN=BlobPt.GetSeg();
532  TBlobPt NewBlobPt=SegV[SegN]->PutBlob(BlobPt, SIn);
533  if (NewBlobPt.Empty()){
534  NewBlobPt=PutBlob(SIn);
535  } else {
536  NewBlobPt.PutSeg(BlobPt.GetSeg());
537  }
538  return NewBlobPt;
539 }
uchar GetSeg() const
Definition: blobbs.h:52
void PutSeg(const uchar &_Seg)
Definition: blobbs.h:51
Definition: fl.h:347
Definition: fl.h:347
TBlobPt PutBlob(const PSIn &SIn)
Definition: blobbs.cpp:509
TFAccess Access
Definition: blobbs.h:190
TBlobBsV SegV
Definition: blobbs.h:193
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: blobbs.h:49
Definition: blobbs.h:5
Definition: fl.h:347
void TMBlobBs::SaveMain ( ) const
private

Definition at line 441 of file blobbs.cpp.

441  {
444  Lx.PutVarStr("Version", GetVersionStr());
445  Lx.PutVarInt("MxSegLen", MxSegLen);
446  Lx.PutVarInt("Segments", SegV.Len());
447 }
Definition: lx.h:248
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
Definition: bits.h:119
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: lx.h:251
TStr NrFPath
Definition: blobbs.h:192
TBlobBsV SegV
Definition: blobbs.h:193
static TStr GetMainFNm(const TStr &NrFPath, const TStr &NrFMid)
Definition: blobbs.cpp:423
TStr GetVersionStr() const
Definition: blobbs.h:210
Definition: lx.h:249
TStr NrFMid
Definition: blobbs.h:192
Definition: bd.h:196
Definition: lx.h:248
int MxSegLen
Definition: blobbs.h:191

Member Data Documentation

TFAccess TMBlobBs::Access
private

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.

TStr TMBlobBs::NrFMid
private

Definition at line 192 of file blobbs.h.

TStr TMBlobBs::NrFPath
private

Definition at line 192 of file blobbs.h.

TBlobBsV TMBlobBs::SegV
private

Definition at line 193 of file blobbs.h.


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