SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
blobbs.h
Go to the documentation of this file.
1 #include "bd.h"
2 
4 // Blob-Pointer
6 public:
7  static const int MnBlobBfL;
8  static const int Flags;
9  uchar Seg;
10  uint Addr;
11  TB8Set FSet1, FSet2, FSet3;
12 public:
14  Seg(0), Addr(TUInt::Mx), FSet1(), FSet2(), FSet3(){}
15  TBlobPt(const TBlobPt& Pt):
16  Seg(Pt.Seg), Addr(Pt.Addr),
17  FSet1(Pt.FSet1), FSet2(Pt.FSet2), FSet3(Pt.FSet3){}
18  TBlobPt(const uchar& _Seg, const uint& _Addr,
19  const TB8Set& _FSet1, const TB8Set& _FSet2, const TB8Set& _FSet3):
20  Seg(_Seg), Addr(_Addr), FSet1(_FSet1), FSet2(_FSet2), FSet3(_FSet3){}
21  TBlobPt(const uchar& _Seg, const uint& _Addr):
22  Seg(_Seg), Addr(_Addr), FSet1(), FSet2(), FSet3(){}
23  TBlobPt(const uint& _Addr):
24  Seg(0), Addr(_Addr), FSet1(), FSet2(), FSet3(){}
25  TBlobPt(const int& _Addr):
26  Seg(0), Addr(uint(_Addr)), FSet1(), FSet2(), FSet3(){IAssert(_Addr>=0);}
28  TBlobPt(TSIn& SIn){
29  SIn.Load(Seg); SIn.Load(Addr);
30  FSet1=TB8Set(SIn); FSet2=TB8Set(SIn); FSet3=TB8Set(SIn);}
31  void Save(TSOut& SOut) const {
32  SOut.Save(Seg); SOut.Save(Addr);
33  FSet1.Save(SOut); FSet2.Save(SOut); FSet3.Save(SOut);}
34 
35  TBlobPt& operator=(const TBlobPt& Pt){
36  if (this!=&Pt){
37  Seg=Pt.Seg; Addr=Pt.Addr;
38  FSet1=Pt.FSet1; FSet2=Pt.FSet2; FSet3=Pt.FSet3;}
39  return *this;}
40  bool operator==(const TBlobPt& Pt) const {
41  return (Seg==Pt.Seg)&&(Addr==Pt.Addr);}
42  bool operator<(const TBlobPt& Pt) const {
43  return (Seg<Pt.Seg)||((Seg==Pt.Seg)&&(Addr<Pt.Addr));}
44  int GetMemUsed() const {return sizeof(TBlobPt);}
45 
46  int GetPrimHashCd() const {return abs(int(Addr));}
47  int GetSecHashCd() const {return (abs(int(Addr))+int(Seg)*0x10);}
48 
49  bool Empty() const {return Addr==TUInt::Mx;}
50  void Clr(){Seg=0; Addr=TUInt::Mx;}
51  void PutSeg(const uchar& _Seg){Seg=_Seg;}
52  uchar GetSeg() const {return Seg;}
53  void PutAddr(const uint& _Addr){Addr=_Addr;}
54  uint GetAddr() const {return Addr;}
55  void PutFlag(const int& FlagN, const bool& Val);
56  bool IsFlag(const int& FlagN) const;
57  void MergeFlags(const TBlobPt& Pt){
58  FSet1|=Pt.FSet1; FSet2|=Pt.FSet2; FSet3|=Pt.FSet3;}
59  void PutFSet(const int& FSetN, const TB8Set& FSet);
60  TB8Set GetFSet(const int& FSetN);
61 
62  static TBlobPt Load(const PFRnd& FRnd){
63  uchar Seg=FRnd->GetUCh(); uint Addr=FRnd->GetUInt();
64  TB8Set B8Set1(FRnd->GetUCh()); TB8Set B8Set2(FRnd->GetUCh());
65  TB8Set B8Set3(FRnd->GetUCh());
66  return TBlobPt(Seg, Addr, B8Set1, B8Set2, B8Set3);}
67  void Save(const PFRnd& FRnd) const {
68  FRnd->PutUCh(Seg); FRnd->PutUInt(Addr);
69  FRnd->PutUCh(FSet1.GetUCh()); FRnd->PutUCh(FSet2.GetUCh());
70  FRnd->PutUCh(FSet3.GetUCh());}
71  static TBlobPt LoadAddr(const PFRnd& FRnd, const uchar& Seg=0){
72  return TBlobPt(Seg, FRnd->GetUInt());}
73  void SaveAddr(const PFRnd& FRnd) const {
74  FRnd->PutUInt(Addr);}
75 
76  TStr GetAddrStr() const {
77  TChA AddrChA; AddrChA+=TInt::GetStr(Seg); AddrChA+=':';
78  AddrChA+=TUInt::GetStr(Addr); return AddrChA;}
79 
80  TStr GetStr() const;
81 };
82 
84 // Blob-Base
86 typedef enum {btUndef, btBegin, btEnd} TBlobTag;
87 typedef enum {bsUndef, bsActive, bsFree} TBlobState;
88 
90 public:
91  static const int MnBlobBfL;
92  static const int MxBlobFLen;
94 public:
95  TBlobBs(){}
96  virtual ~TBlobBs(){}
98  static PBlobBs Load(TSIn&){Fail; return NULL;}
99  void Save(TSOut&) const {Fail;}
100 
101  virtual TStr GetVersionStr() const=0;
102  void PutVersionStr(const PFRnd& FBlobBs);
103  void AssertVersionStr(const PFRnd& FBlobBs);
104 
105  TStr GetBlobBsStateStr(const TBlobBsState& BlobBsState);
106  int GetStateStrLen(){return 6;}
107  void PutBlobBsStateStr(const PFRnd& FBlobBs, const TBlobBsState& State);
108  void AssertBlobBsStateStr(const PFRnd& FBlobBs, const TBlobBsState& State);
109 
110  static const TStr MxSegLenVNm;
111  void PutMxSegLen(const PFRnd& FBlobBs, const int& MxSegLen);
112  int GetMxSegLen(const PFRnd& FBlobBs);
113 
114  static const TStr BlockLenVNm;
115  void GenBlockLenV(TIntV& BlockLenV);
116  void PutBlockLenV(const PFRnd& FBlobBs, const TIntV& BlockLenV);
117  void GetBlockLenV(const PFRnd& FBlobBs, TIntV& BlockLenV);
118 
119  static const TStr FFreeBlobPtVNm;
120  void GenFFreeBlobPtV(const TIntV& BlockLenV, TBlobPtV& FFreeBlobPtV);
121  void PutFFreeBlobPtV(const PFRnd& FBlobBs, const TBlobPtV& FFreeBlobPtV);
122  void GetFFreeBlobPtV(const PFRnd& FBlobBs, TBlobPtV& FFreeBlobPtV);
123 
124  void GetAllocInfo(
125  const int& BfL, const TIntV& BlockLenV, int& MxBfL, int& FFreeBlobPtN);
126 
127  uint GetBeginBlobTag(){return 0xABCDEFFF;}
128  uint GetEndBlobTag(){return 0xFFFEDCBA;}
129  void PutBlobTag(const PFRnd& FBlobBs, const TBlobTag& BlobTag);
130  void AssertBlobTag(const PFRnd& FBlobBs, const TBlobTag& BlobTag);
131 
132  void PutBlobState(const PFRnd& FBlobBs, const TBlobState& State);
133  TBlobState GetBlobState(const PFRnd& FBlobBs);
134  void AssertBlobState(const PFRnd& FBlobBs, const TBlobState& State);
135 
136  void AssertBfCsEqFlCs(const TCs& BfCs, const TCs& FCs);
137 
138  virtual TBlobPt PutBlob(const PSIn& SIn)=0;
139  TBlobPt PutBlob(const TStr& Str){
140  PSIn SIn=TStrIn::New(Str); return PutBlob(SIn);}
141  virtual TBlobPt PutBlob(const TBlobPt& BlobPt, const PSIn& SIn)=0;
142  virtual PSIn GetBlob(const TBlobPt& BlobPt)=0;
143  virtual void DelBlob(const TBlobPt& BlobPt)=0;
144 
145  virtual TBlobPt GetFirstBlobPt()=0;
146  virtual TBlobPt FFirstBlobPt()=0;
147  virtual bool FNextBlobPt(TBlobPt& TrvBlobPt, TBlobPt& BlobPt, PSIn& BlobSIn)=0;
148  bool FNextBlobPt(TBlobPt& TrvBlobPt, PSIn& BlobSIn){
149  TBlobPt BlobPt; return FNextBlobPt(TrvBlobPt, BlobPt, BlobSIn);}
150 };
151 
153 // General-Blob-Base
154 class TGBlobBs: public TBlobBs{
155 private:
158  int MxSegLen;
162  static TStr GetNrBlobBsFNm(const TStr& BlobBsFNm);
163 public:
164  TGBlobBs(const TStr& BlobBsFNm, const TFAccess& _Access=faRdOnly,
165  const int& _MxSegLen=-1);
166  static PBlobBs New(const TStr& BlobBsFNm, const TFAccess& Access=faRdOnly,
167  const int& MxSegLen=-1){
168  return PBlobBs(new TGBlobBs(BlobBsFNm, Access, MxSegLen));}
169  ~TGBlobBs();
170 
171  TGBlobBs& operator=(const TGBlobBs&){Fail; return *this;}
172 
173  TStr GetVersionStr() const {return TStr("General Blob Base Format 1.0");}
174  TBlobPt PutBlob(const PSIn& SIn);
175  TBlobPt PutBlob(const TBlobPt& BlobPt, const PSIn& SIn);
176  PSIn GetBlob(const TBlobPt& BlobPt);
177  void DelBlob(const TBlobPt& BlobPt);
178 
181  bool FNextBlobPt(TBlobPt& TrvBlobPt, TBlobPt& BlobPt, PSIn& BlobSIn);
182 
183  static bool Exists(const TStr& BlobBsFNm);
184 };
185 
187 // Multiple-File-Blob-Base
188 class TMBlobBs: public TBlobBs{
189 private:
191  int MxSegLen;
194  int CurSegN;
195  static void GetNrFPathFMid(const TStr& BlobBsFNm, TStr& NrFPath, TStr& NrFMid);
196  static TStr GetMainFNm(const TStr& NrFPath, const TStr& NrFMid);
197  static TStr GetSegFNm(const TStr& NrFPath, const TStr& NrFMid, const int& SegN);
198  void LoadMain(int& Segs);
199  void SaveMain() const;
200 public:
201  TMBlobBs(const TStr& BlobBsFNm, const TFAccess& _Access=faRdOnly,
202  const int& _MxSegLen=-1);
203  static PBlobBs New(const TStr& BlobBsFNm, const TFAccess& Access=faRdOnly,
204  const int& MxSegLen=-1){
205  return PBlobBs(new TMBlobBs(BlobBsFNm, Access, MxSegLen));}
206  ~TMBlobBs();
207 
208  TMBlobBs& operator=(const TMBlobBs&){Fail; return *this;}
209 
210  TStr GetVersionStr() const {
211  return TStr("Multiple-File Blob Base Format 1.0");}
212  TBlobPt PutBlob(const PSIn& SIn);
213  TBlobPt PutBlob(const TBlobPt& BlobPt, const PSIn& SIn);
214  PSIn GetBlob(const TBlobPt& BlobPt);
215  void DelBlob(const TBlobPt& BlobPt);
216 
219  bool FNextBlobPt(TBlobPt& TrvBlobPt, TBlobPt& BlobPt, PSIn& BlobSIn);
220 
221  static bool Exists(const TStr& BlobBsFNm);
222 };
223 
#define IAssert(Cond)
Definition: bd.h:262
bool FNextBlobPt(TBlobPt &TrvBlobPt, PSIn &BlobSIn)
Definition: blobbs.h:148
void DelBlob(const TBlobPt &BlobPt)
Definition: blobbs.cpp:546
TGBlobBs(const TStr &BlobBsFNm, const TFAccess &_Access=faRdOnly, const int &_MxSegLen=-1)
Definition: blobbs.cpp:220
void DelBlob(const TBlobPt &BlobPt)
Definition: blobbs.cpp:353
TFAccess Access
Definition: blobbs.h:157
static PBlobBs New(const TStr &BlobBsFNm, const TFAccess &Access=faRdOnly, const int &MxSegLen=-1)
Definition: blobbs.h:203
uchar Seg
Definition: blobbs.h:9
void Clr()
Definition: blobbs.h:50
TStr GetStr() const
Definition: dt.h:1200
TB8Set FSet3
Definition: blobbs.h:11
Definition: bits.h:166
TBlobPt FFirstBlobPt()
Definition: blobbs.cpp:555
static void GetNrFPathFMid(const TStr &BlobBsFNm, TStr &NrFPath, TStr &NrFMid)
Definition: blobbs.cpp:417
static TBlobPt Load(const PFRnd &FRnd)
Definition: blobbs.h:62
TBlobPt(TSIn &SIn)
Definition: blobbs.h:28
uint GetBeginBlobTag()
Definition: blobbs.h:127
uchar GetSeg() const
Definition: blobbs.h:52
void PutSeg(const uchar &_Seg)
Definition: blobbs.h:51
TBlobPt & operator=(const TBlobPt &Pt)
Definition: blobbs.h:35
bool operator==(const TBlobPt &Pt) const
Definition: blobbs.h:40
void SaveMain() const
Definition: blobbs.cpp:441
Definition: blobbs.h:86
Definition: blobbs.h:86
void SaveAddr(const PFRnd &FRnd) const
Definition: blobbs.h:73
int GetSecHashCd() const
Definition: blobbs.h:47
static const uint Mx
Definition: dt.h:1247
Definition: blobbs.h:86
static TStr GetSegFNm(const TStr &NrFPath, const TStr &NrFMid, const int &SegN)
Definition: blobbs.cpp:428
unsigned int uint
Definition: bd.h:11
int GetStateStrLen()
Definition: blobbs.h:106
#define Fail
Definition: bd.h:238
bool FNextBlobPt(TBlobPt &TrvBlobPt, TBlobPt &BlobPt, PSIn &BlobSIn)
Definition: blobbs.cpp:377
uchar GetUCh()
Definition: fl.h:623
static bool Exists(const TStr &BlobBsFNm)
Definition: blobbs.cpp:410
TBlobTag
Definition: blobbs.h:86
TBlobPt(const uchar &_Seg, const uint &_Addr)
Definition: blobbs.h:21
void PutAddr(const uint &_Addr)
Definition: blobbs.h:53
Definition: blobbs.h:87
TBlobBsState
Definition: blobbs.h:85
uint Addr
Definition: blobbs.h:10
Definition: blobbs.h:89
void LoadMain(int &Segs)
Definition: blobbs.cpp:433
void PutUInt(const uint &UInt)
Definition: fl.h:626
uint GetEndBlobTag()
Definition: blobbs.h:128
#define UndefCopyAssign(TNm)
Definition: bd.h:209
TBlobPt(const uint &_Addr)
Definition: blobbs.h:23
TBlobPt(const uchar &_Seg, const uint &_Addr, const TB8Set &_FSet1, const TB8Set &_FSet2, const TB8Set &_FSet3)
Definition: blobbs.h:18
TBlobState
Definition: blobbs.h:87
Definition: fl.h:58
#define ClassTVQ(TNm, TNmV, TNmQ)
Definition: bd.h:120
int MxSegLen
Definition: blobbs.h:158
#define ClassTPV(TNm, PNm, TNmV)
Definition: bd.h:162
virtual ~TBlobBs()
Definition: blobbs.h:96
TBlobPt FirstBlobPt
Definition: blobbs.h:161
~TGBlobBs()
Definition: blobbs.cpp:262
static TStr GetNrBlobBsFNm(const TStr &BlobBsFNm)
Definition: blobbs.cpp:213
Definition: fl.h:347
TMBlobBs & operator=(const TMBlobBs &)
Definition: blobbs.h:208
uint GetAddr() const
Definition: blobbs.h:54
PFRnd FBlobBs
Definition: blobbs.h:156
void Load(bool &Bool)
Definition: fl.h:84
TIntV BlockLenV
Definition: blobbs.h:159
TBlobPt PutBlob(const PSIn &SIn)
Definition: blobbs.cpp:509
static PSIn New(const TStr &Str)
Definition: dt.h:711
TStr GetStr() const
Definition: dt.h:1282
int GetMemUsed() const
Definition: blobbs.h:44
TStr GetVersionStr() const
Definition: blobbs.h:173
static const TStr MxSegLenVNm
Definition: blobbs.h:110
PSIn GetBlob(const TBlobPt &BlobPt)
Definition: blobbs.cpp:541
PSIn GetBlob(const TBlobPt &BlobPt)
Definition: blobbs.cpp:339
TBlobPt PutBlob(const TStr &Str)
Definition: blobbs.h:139
static PBlobBs New(const TStr &BlobBsFNm, const TFAccess &Access=faRdOnly, const int &MxSegLen=-1)
Definition: blobbs.h:166
TFAccess Access
Definition: blobbs.h:190
TBlobPt GetFirstBlobPt()
Definition: blobbs.cpp:551
unsigned char uchar
Definition: bd.h:10
TStr NrFPath
Definition: blobbs.h:192
TBlobBsV SegV
Definition: blobbs.h:193
Definition: ds.h:2610
void Save(const PFRnd &FRnd) const
Definition: blobbs.h:67
static TStr GetMainFNm(const TStr &NrFPath, const TStr &NrFMid)
Definition: blobbs.cpp:423
TStr GetVersionStr() const
Definition: blobbs.h:210
Definition: fl.h:128
int CurSegN
Definition: blobbs.h:194
void Save(const bool &Bool)
Definition: fl.h:173
static PBlobBs Load(TSIn &)
Definition: blobbs.h:98
TB8Set FSet2
Definition: blobbs.h:11
bool FNextBlobPt(TBlobPt &TrvBlobPt, TBlobPt &BlobPt, PSIn &BlobSIn)
Definition: blobbs.cpp:559
~TBlobPt()
Definition: blobbs.h:27
TBlobPt(const int &_Addr)
Definition: blobbs.h:25
Definition: dt.h:201
static const TStr BlockLenVNm
Definition: blobbs.h:114
Definition: dt.h:1242
TBlobPt GetFirstBlobPt()
Definition: blobbs.h:179
bool Empty() const
Definition: blobbs.h:49
TBlobPt PutBlob(const PSIn &SIn)
Definition: blobbs.cpp:275
void Save(TSOut &) const
Definition: blobbs.h:99
bool operator<(const TBlobPt &Pt) const
Definition: blobbs.h:42
Definition: dt.h:412
Definition: blobbs.h:5
TBlobPt(const TBlobPt &Pt)
Definition: blobbs.h:15
void MergeFlags(const TBlobPt &Pt)
Definition: blobbs.h:57
int GetPrimHashCd() const
Definition: blobbs.h:46
TStr GetAddrStr() const
Definition: blobbs.h:76
TStr NrFMid
Definition: blobbs.h:192
static bool Exists(const TStr &BlobBsFNm)
Definition: blobbs.cpp:576
TGBlobBs & operator=(const TGBlobBs &)
Definition: blobbs.h:171
TPt< TBlobBs > PBlobBs
Definition: blobbs.h:89
~TMBlobBs()
Definition: blobbs.cpp:503
int MxSegLen
Definition: blobbs.h:191
TBlobPt FFirstBlobPt()
Definition: blobbs.cpp:373
static TBlobPt LoadAddr(const PFRnd &FRnd, const uchar &Seg=0)
Definition: blobbs.h:71
Definition: blobbs.h:87
Definition: fl.h:11
void Save(TSOut &SOut) const
Definition: blobbs.h:31
TFAccess
Definition: fl.h:347
void PutUCh(const uchar &UCh)
Definition: fl.h:622
uint GetUInt()
Definition: fl.h:627
static const TStr FFreeBlobPtVNm
Definition: blobbs.h:119
TMBlobBs(const TStr &BlobBsFNm, const TFAccess &_Access=faRdOnly, const int &_MxSegLen=-1)
Definition: blobbs.cpp:449
TB8Set FSet1
Definition: blobbs.h:11
TBlobPtV FFreeBlobPtV
Definition: blobbs.h:160
TBlobBs(TSIn &)
Definition: blobbs.h:97