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
Go to the documentation of this file.
1 #include "bd.h"
4 // Forward-Definitions
5 class TMem;
6 class TChA;
7 class TStr;
10 // Check-Sum
11 class TCs{
12 private:
13  static const int MxMask;
14  int Val;
15 public:
16  TCs(): Val(0){}
17  TCs(const TCs& Cs): Val(Cs.Val&MxMask){}
18  TCs(const int& Int): Val(Int&MxMask){}
20  TCs& operator=(const TCs& Cs){Val=Cs.Val; return *this;}
21  bool operator==(const TCs& Cs) const {return Val==Cs.Val;}
22  TCs& operator+=(const TCs& Cs){Val=(Val+Cs.Val)&MxMask; return *this;}
23  TCs& operator+=(const char& Ch){Val=(Val+Ch)&MxMask; return *this;}
24  TCs& operator+=(const int& Int){Val=(Val+Int)&MxMask; return *this;}
25  int Get() const {return Val;}
27  static TCs GetCsFromBf(char* Bf, const int& BfL);
28 };
31 // Output-stream-manipulator
32 class TSOutMnp {
33 public:
34  virtual TSOut& operator()(TSOut& SOut) const=0;
35  virtual ~TSOutMnp();
36 };
39 // Stream-base
40 class TSBase{
41 protected:
45 //protected:
46 // TSBase();
47 // TSBase(const TSBase&);
48 // TSBase& operator=(const TSBase&);
49 public:
50  TSBase(const TSStr& Nm): SNm(Nm){}
51  virtual ~TSBase(){}
53  virtual TStr GetSNm() const;
54 };
57 // Input-Stream
58 class TSIn: virtual public TSBase{
59 private:
60  bool FastMode;
61 private:
62  TSIn(const TSIn&);
63  TSIn& operator=(const TSIn&);
64 public:
65  TSIn(): TSBase("Input-Stream"), FastMode(false){}
66  TSIn(const TStr& Str);
67  virtual ~TSIn(){}
69  virtual bool Eof()=0; // if end-of-file
70  virtual int Len() const=0; // get number of bytes till eof
71  virtual char GetCh()=0; // get one char and advance
72  virtual char PeekCh()=0; // get one char and do NOT advance
73  virtual int GetBf(const void* Bf, const TSize& BfL)=0; // get BfL chars and advance
74  virtual bool GetNextLnBf(TChA& LnChA)=0; // get the next line and advance
75  virtual void Reset(){Fail;}
77  bool IsFastMode() const {return FastMode;}
78  void SetFastMode(const bool& _FastMode){FastMode=_FastMode;}
80  virtual void LoadCs();
81  void LoadBf(const void* Bf, const TSize& BfL){Cs+=GetBf(Bf, BfL);}
82  void* LoadNewBf(const int& BfL){
83  void* Bf=(void*)new char[BfL]; Cs+=GetBf(Bf, BfL); return Bf;}
84  void Load(bool& Bool){Cs+=GetBf(&Bool, sizeof(Bool));}
85  void Load(uchar& UCh){Cs+=GetBf(&UCh, sizeof(UCh));}
86  void Load(char& Ch){Cs+=GetBf(&Ch, sizeof(Ch));}
87  void Load(short& Short){Cs+=GetBf(&Short, sizeof(Short));} //J:
88  void Load(ushort& UShort){Cs+=GetBf(&UShort, sizeof(UShort));} //J:
89  void Load(int& Int){Cs+=GetBf(&Int, sizeof(Int));}
90  void Load(uint& UInt){Cs+=GetBf(&UInt, sizeof(UInt));}
91  void Load(int64& Int){Cs+=GetBf(&Int, sizeof(Int));}
92  void Load(uint64& UInt){Cs+=GetBf(&UInt, sizeof(UInt));}
93  void Load(double& Flt){Cs+=GetBf(&Flt, sizeof(Flt));}
94  void Load(sdouble& SFlt){Cs+=GetBf(&SFlt, sizeof(SFlt));}
95  void Load(ldouble& LFlt){Cs+=GetBf(&LFlt, sizeof(LFlt));}
96  void Load(char*& CStr, const int& MxCStrLen, const int& CStrLen){
97  CStr=new char[MxCStrLen+1]; Cs+=GetBf(CStr, CStrLen+1);}
98  void Load(char*& CStr);
100  TSIn& operator>>(bool& Bool){Cs+=GetBf(&Bool, sizeof(Bool)); return *this;}
101  TSIn& operator>>(uchar& UCh){Cs+=GetBf(&UCh, sizeof(UCh)); return *this;}
102  TSIn& operator>>(char& Ch){Cs+=GetBf(&Ch, sizeof(Ch)); return *this;}
103  TSIn& operator>>(short& Sh){Cs+=GetBf(&Sh, sizeof(Sh)); return *this;}
104  TSIn& operator>>(ushort& USh){Cs+=GetBf(&USh, sizeof(USh)); return *this;}
105  TSIn& operator>>(int& Int){Cs+=GetBf(&Int, sizeof(Int)); return *this;}
106  TSIn& operator>>(uint& UInt){Cs+=GetBf(&UInt, sizeof(UInt)); return *this;}
107  TSIn& operator>>(int64& Int){Cs+=GetBf(&Int, sizeof(Int)); return *this;}
108  TSIn& operator>>(uint64& UInt){Cs+=GetBf(&UInt, sizeof(UInt)); return *this;}
109  TSIn& operator>>(float& Flt){Cs+=GetBf(&Flt, sizeof(Flt)); return *this;}
110  TSIn& operator>>(double& Double){Cs+=GetBf(&Double, sizeof(Double)); return *this;}
111  TSIn& operator>>(long double& LDouble){Cs+=GetBf(&LDouble, sizeof(LDouble)); return *this;}
113  bool GetNextLn(TStr& LnStr);
114  bool GetNextLn(TChA& LnChA);
116  static const TPt<TSIn> StdIn;
117  friend class TPt<TSIn>;
118 };
119 typedef TPt<TSIn> PSIn;
121 template <class T>
122 TSIn& operator>>(TSIn& SIn, T& Val) {
123  Val.Load(SIn); return SIn;
124 }
127 // Output-Stream
128 class TSOut: virtual public TSBase{
129 private:
131  int UpdateLnLen(const int& StrLen, const bool& ForceInLn=false);
132 private:
133  TSOut(const TSIn&);
134  TSOut& operator = (const TSOut&);
135 public:
136  TSOut(): TSBase("Output-Stream"), MxLnLen(-1), LnLen(0){}
137  TSOut(const TStr& Str);
138  virtual ~TSOut(){}
140  void EnableLnTrunc(const int& _MxLnLen){MxLnLen=_MxLnLen;}
141  void DisableLnTrunc(){MxLnLen=-1;}
143  virtual int PutCh(const char& Ch)=0;
144  virtual int PutBf(const void* LBf, const TSize& LBfL)=0;
145  virtual void Flush()=0;
146  virtual TFileId GetFileId() const {return NULL;}
148  int PutMem(const TMem& Mem);
149  int PutCh(const char& Ch, const int& Chs);
150  int PutBool(const bool& Bool);
151  int PutInt(const int& Int);
152  int PutInt(const int& Int, const char* FmtStr);
153  int PutUInt(const uint& Int);
154  int PutUInt(const uint& Int, const char* FmtStr);
155  int PutFlt(const double& Flt);
156  int PutFlt(const double& Flt, const char* FmtStr);
157  int PutStr(const char* CStr);
158  int PutStr(const TChA& ChA);
159  int PutStr(const TStr& Str, const char* FmtStr);
160  int PutStr(const TStr& Str, const bool& ForceInLn=false);
161  int PutStrLn(const TStr& Str, const bool& ForceInLn=false){
162  int Cs=PutStr(Str,ForceInLn); Cs+=PutLn(); return Cs;}
163  int PutStrFmt(const char *FmtStr, ...);
164  int PutStrFmtLn(const char *FmtStr, ...);
165  int PutIndent(const int& IndentLev=1);
166  int PutLn(const int& Lns=1);
167  int PutDosLn(const int& Lns=1);
168  int PutSep(const int& NextStrLen=0);
169  int PutSepLn(const int& Lns=0);
171  void SaveCs(){Cs+=PutBf(&Cs, sizeof(Cs));}
172  void SaveBf(const void* Bf, const TSize& BfL){Cs+=PutBf(Bf, BfL);}
173  void Save(const bool& Bool){Cs+=PutBf(&Bool, sizeof(Bool));}
174  void Save(const char& Ch){Cs+=PutBf(&Ch, sizeof(Ch));}
175  void Save(const uchar& UCh){Cs+=PutBf(&UCh, sizeof(UCh));}
176  void Save(const short& Short){Cs+=PutBf(&Short, sizeof(Short));}
177  void Save(const ushort& UShort){Cs+=PutBf(&UShort, sizeof(UShort));}
178  void Save(const int& Int){Cs+=PutBf(&Int, sizeof(Int));}
179  void Save(const uint& UInt){Cs+=PutBf(&UInt, sizeof(UInt));}
180  void Save(const int64& Int){Cs+=PutBf(&Int, sizeof(Int));}
181  void Save(const uint64& UInt){Cs+=PutBf(&UInt, sizeof(UInt));}
182  void Save(const double& Flt){Cs+=PutBf(&Flt, sizeof(Flt));}
183  void Save(const sdouble& SFlt){Cs+=PutBf(&SFlt, sizeof(SFlt));}
184  void Save(const ldouble& LFlt){Cs+=PutBf(&LFlt, sizeof(LFlt));}
185  void Save(const char* CStr, const TSize& CStrLen){Cs+=PutBf(CStr, CStrLen+1);}
186  void Save(const char* CStr);
187  void Save(TSIn& SIn, const TSize& BfL=-1);
188  void Save(const PSIn& SIn, const TSize& BfL=-1){Save(*SIn, BfL);}
189  void Save(const void* Bf, const TSize& BfL){Cs+=PutBf(Bf, BfL);}
191  TSOut& operator<<(const bool& Bool){Cs+=PutBf(&Bool, sizeof(Bool)); return *this;}
192  TSOut& operator<<(const uchar& UCh){Cs+=PutBf(&UCh, sizeof(UCh)); return *this;}
193  TSOut& operator<<(const char& Ch){Cs+=PutBf(&Ch, sizeof(Ch)); return *this;}
194  TSOut& operator<<(const short& Sh){Cs+=PutBf(&Sh, sizeof(Sh)); return *this;}
195  TSOut& operator<<(const ushort& USh){Cs+=PutBf(&USh, sizeof(USh)); return *this;}
196  TSOut& operator<<(const int& Int){Cs+=PutBf(&Int, sizeof(Int)); return *this;}
197  TSOut& operator<<(const uint& Int){Cs+=PutBf(&Int, sizeof(Int)); return *this;}
198  TSOut& operator<<(const int64& Int){Cs+=PutBf(&Int, sizeof(Int)); return *this;}
199  TSOut& operator<<(const uint64& UInt){Cs+=PutBf(&UInt, sizeof(UInt)); return *this;}
200  TSOut& operator<<(const float& Flt){Cs+=PutBf(&Flt, sizeof(Flt)); return *this;}
201  TSOut& operator<<(const double& Double){Cs+=PutBf(&Double, sizeof(Double)); return *this;}
202  TSOut& operator<<(const long double& LDouble){Cs+=PutBf(&LDouble, sizeof(LDouble)); return *this;}
203  TSOut& operator<<(const TSOutMnp& Mnp){return Mnp(*this);}
204  TSOut& operator<<(TSOut&(*FuncPt)(TSOut&)){return FuncPt(*this);}
205  TSOut& operator<<(TSIn& SIn);
206  TSOut& operator<<(PSIn& SIn){return operator<<(*SIn);}
208  static const TPt<TSOut> StdOut;
209  friend class TPt<TSOut>;
210 };
213 template <class T>
214 TSOut& operator<<(TSOut& SOut, const T& Val){
215  Val.Save(SOut); return SOut;
216 }
219 // Input-Output-Stream-Base
220 class TSInOut: public TSIn, public TSOut{
221 private:
222  TSInOut(const TSInOut&);
223  TSInOut& operator=(const TSInOut&);
224 public:
225  TSInOut(): TSBase("Input-Output-Stream"), TSIn(), TSOut() {}
226  virtual ~TSInOut(){}
228  virtual void SetPos(const int& Pos)=0;
229  virtual void MovePos(const int& DPos)=0;
230  virtual int GetPos() const=0;
231  virtual int GetSize() const=0; // size of whole stream
232  virtual void Clr()=0; // clear IO buffer
234  friend class TPt<TSInOut>;
235 };
239 // Standard-Input
240 class TStdIn: public TSIn{
241 private:
242  TStdIn(const TStdIn&);
243  TStdIn& operator=(const TStdIn&);
244 public:
245  TStdIn();
246  static TPt<TSIn> New(){return new TStdIn();}
248  bool Eof(){return feof(stdin)!=0;}
249  int Len() const {return -1;}
250  char GetCh(){return char(getchar());}
251  char PeekCh(){
252  int Ch=getchar(); ungetc(Ch, stdin); return char(Ch);}
253  int GetBf(const void* LBf, const TSize& LBfL);
254  void Reset(){Cs=TCs();}
255  bool GetNextLnBf(TChA& LnChA);
256 };
259 // Standard-Output
260 class TStdOut: public TSOut{
261 private:
262  TStdOut(const TStdOut&);
263  TStdOut& operator=(const TStdOut&);
264 public:
265  TStdOut();
266  static TPt<TSOut> New(){return new TStdOut();}
268  int PutCh(const char& Ch){putchar(Ch); return Ch;}
269  int PutBf(const void *LBf, const TSize& LBfL);
270  void Flush(){fflush(stdout);}
271 };
274 // Input-File
275 class TFIn: public TSIn{
276 private:
277  static const int MxBfL;
279  char* Bf;
280  int BfC, BfL;
281 private:
282  void SetFPos(const int& FPos) const;
283  int GetFPos() const;
284  int GetFLen() const;
285  void FillBf();
286  int FindEol(int& BfN, bool& CrEnd);
287 private:
288  TFIn();
289  TFIn(const TFIn&);
290  TFIn& operator=(const TFIn&);
291 public:
292  TFIn(const TStr& FNm);
293  TFIn(const TStr& FNm, bool& OpenedP);
294  static PSIn New(const TStr& FNm);
295  static PSIn New(const TStr& FNm, bool& OpenedP);
296  ~TFIn();
298  bool Eof(){
299  if ((BfC==BfL)&&(BfL==MxBfL)){FillBf();}
300  return (BfC==BfL)&&(BfL<MxBfL);}
301  int Len() const {return GetFLen()-(GetFPos()-BfL+BfC);}
302  char GetCh(){
303  if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC++];}
304  else {return Bf[BfC++];}}
305  char PeekCh(){
306  if (BfC==BfL){if (Eof()){return 0;} return Bf[BfC];}
307  else {return Bf[BfC];}}
308  int GetBf(const void* LBf, const TSize& LBfL);
309  void Reset(){rewind(FileId); Cs=TCs(); BfC=BfL=-1; FillBf();}
310  bool GetNextLnBf(TChA& LnChA);
312  //J:not needed
313  //TFileId GetFileId() const {return FileId;} //J:
314  //void SetFileId(const FileId& FlId) {FileId=FlId; BfC=BfL=-1; FillBf(); } //J: for low level manipulations
315 };
318 // Output-File
319 class TFOut: public TSOut{
320 private:
321  static const TSize MxBfL;
323  char* Bf;
325 private:
326  void FlushBf();
327 private:
328  TFOut();
329  TFOut(const TFOut&);
330  TFOut& operator=(const TFOut&);
331 public:
332  TFOut(const TStr& _FNm, const bool& Append=false);
333  TFOut(const TStr& _FNm, const bool& Append, bool& OpenedP);
334  static PSOut New(const TStr& FNm, const bool& Append=false);
335  static PSOut New(const TStr& FNm, const bool& Append, bool& OpenedP);
336  ~TFOut();
338  int PutCh(const char& Ch);
339  int PutBf(const void* LBf, const TSize& LBfL);
340  void Flush();
342  TFileId GetFileId() const {return FileId;}
343 };
346 // Input-Output-File
349 class TFInOut : public TSInOut {
350 private:
352 private:
353  TFInOut();
354  TFInOut(const TFIn&);
355  TFInOut& operator=(const TFIn&);
356 public:
357  TFInOut(const TStr& FNm, const TFAccess& FAccess, const bool& CreateIfNo);
358  static PSInOut New(const TStr& FNm, const TFAccess& FAccess, const bool& CreateIfNo);
359  ~TFInOut() { if (FileId!=NULL) IAssert(fclose(FileId) == 0); }
361  TStr GetFNm() const;
362  TFileId GetFileId() const {return FileId;}
364  bool Eof(){ return feof(FileId) != 0; }
365  int Len() const { return GetSize() - GetPos(); } // bytes till eof
366  char GetCh() { return char(fgetc(FileId)); }
367  char PeekCh() { const char Ch = GetCh(); MovePos(-1); return Ch; }
368  int GetBf(const void* LBf, const TSize& LBfL);
369  bool GetNextLnBf(TChA& LnChA);
371  void SetPos(const int& Pos) { IAssert(fseek(FileId, Pos, SEEK_SET)==0); }
372  void MovePos(const int& DPos) { IAssert(fseek(FileId, DPos, SEEK_CUR)==0); }
373  int GetPos() const { return (int) ftell(FileId); }
374  int GetSize() const;
375  void Clr() { Fail; }
377  int PutCh(const char& Ch) { return PutBf(&Ch, sizeof(Ch)); }
378  int PutBf(const void* LBf, const TSize& LBfL);
379  void Flush() { IAssert(fflush(FileId) == 0); }
380 };
383 // Shared Memory
384 class TShMIn : public TSIn {
385 private:
389  char* Cursor;
391 public:
392  TShMIn(const TStr& Str);
393  TShMIn(void* _Bf, const TSize& _BfL);
394  ~TShMIn() {}
395  bool Eof() { return SizeLeft<=0; }
396  int Len() const { return TotalLength; }
397  char GetCh() {
398  char c;
399  LoadAndAdvance(&c, sizeof(c));
400  return c;
401  }
402  char* getCursor() {
403  return Cursor;
404  }
405  char PeekCh() {
406  return ((char*)Cursor)[0];
407  }
408  void LoadCs() {
409  TCs TestCs;
410  GetBf(&TestCs, sizeof(TestCs));
411  }
412  int GetBf(const void* LBf, const TSize& LBfL){
413  LoadAndAdvance((char*)LBf, LBfL);
414  return 0;
415  }
416  bool GetNextLnBf(TChA& LnChA){
417  return false;
418  }
420  void LoadAndAdvance(void* Dest, TSize ElemSize) {
421  memcpy(Dest, Cursor, ElemSize);
422  AdvanceCursor(ElemSize);
423  }
425  char* AdvanceCursor(TSize N) {
426  char* TempCursor = Cursor;
427  Cursor += N;
428  SizeLeft -= N;
429  return TempCursor;
430  }
432  void CloseMapping();
433 };
436 // Input-Memory
437 class TMIn: public TSIn{
438 private:
439  char* Bf;
442 private:
443  TMIn();
444  TMIn(const TMIn&);
445  TMIn& operator=(const TMIn&);
446 private:
447  int FindEol(uint64& BfN, bool& CrEnd);
448 public:
449  TMIn(const void* _Bf, const uint64& _BfL, const bool& TakeBf=false);
450  TMIn(TSIn& SIn);
451  TMIn(const char* CStr);
453  TMIn(const TStr& Str, bool FromFile);
454  TMIn(const TChA& ChA);
455  static PSIn New(const void* _Bf, const uint64& _BfL, const bool& TakeBf=false);
456  static PSIn New(const char* CStr);
457  static PSIn New(const TStr& Str);
458  static PSIn New(const TChA& ChA);
459  static TPt<TMIn> New(const TStr& Str, bool FromFile);
460  //static TPt<TMIn> New(const TStr& Str, uint64);
462  ~TMIn();
464  bool Eof(){return BfC==BfL;}
465  int Len() const {return static_cast<int>(BfL-BfC);}
466  char GetCh();
467  char PeekCh();
468  int GetBf(const void* LBf, const TSize& LBfL);
469  void Reset(){Cs=TCs(); BfC=0;}
470  bool GetNextLnBf(TChA& LnChA);
472  uint64 GetBfC();
473  uint64 GetBfL();
474  void SetBfC(uint64 Pos);
482  char* GetLine(uint64 Ind);
484  void SkipCommentLines();
486  char* GetBfAddr(){return Bf;}
488  friend class TPt<TMIn>;
489 };
491 typedef TPt<TMIn> PMIn;
494 // Output-Memory
495 class TMOut: public TSOut{
496 private:
497  char* Bf;
498  int BfL, MxBfL;
499  bool OwnBf;
500  void Resize(const int& ReqLen = -1);
501 private:
502  TMOut(const TMOut&);
503  TMOut& operator=(const TMOut&);
504 public:
505  TMOut(const int& _MxBfL=1024);
506  static PSOut New(const int& MxBfL=1024){
507  return PSOut(new TMOut(MxBfL));}
508  TMOut(char* _Bf, const int& _MxBfL);
509  ~TMOut(){if (OwnBf&&(Bf!=NULL)){delete[] Bf;}}
511  int PutCh(const char& Ch){if (BfL==MxBfL){
512  Resize();} return Bf[BfL++]=Ch;}
513  int PutBf(const void* LBf, const TSize& LBfL);
514  void AppendBf(const void* LBf, const TSize& LBfL);
515  void Flush(){}
517  int Len() const {return BfL;}
518  void Clr(){BfL=0;}
519  char GetCh(const int& ChN) const {
520  IAssert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
521  TStr GetAsStr() const;
522  void CutBf(const int& CutBfL);
523  PSIn GetSIn(const bool& IsCut=true, const int& CutBfL=-1);
524  char* GetBfAddr() const {return Bf;}
526  bool IsCrLfLn() const;
527  TStr GetCrLfLn();
528  bool IsEolnLn() const;
529  TStr GetEolnLn(const bool& DoAddEoln, const bool& DoCutBf);
530  void MkEolnLn();
531 };
534 // Character-Returner
535 class TChRet{
536 private:
538  char EofCh;
539  char Ch;
540 private:
541  TChRet();
542  TChRet(const TChRet&);
543  TChRet& operator=(const TChRet&);
544 public:
545  TChRet(const PSIn& _SIn, const char& _EofCh=0):
546  SIn(_SIn), EofCh(_EofCh), Ch(_EofCh){}
548  bool Eof() const {return Ch==EofCh;}
549  char GetCh(){
550  if (SIn->Eof()){return Ch=EofCh;} else {return Ch=SIn->GetCh();}}
551  char operator()(){return Ch;}
552 };
555 // Line-Returner
556 // J: after talking to BlazF -- can be removed from GLib
557 class TLnRet{
558 private:
561 public:
562  TLnRet(const PSIn& _SIn): SIn(_SIn) {}
564  bool NextLn(TStr& LnStr);
565 };
568 // Random-Access-File
570 private:
571  TFileId FileId;
572  TSStr FNm;
573  bool RecAct;
574  int HdLen, RecLen;
575 private:
576  void RefreshFPos();
577 private:
578  TFRnd(const TFRnd&);
579  TFRnd& operator=(const TFRnd&);
580 public:
581  TFRnd(const TStr& _FNm, const TFAccess& FAccess,
582  const bool& CreateIfNo=true, const int& _HdLen=-1, const int& _RecLen=-1);
583  static PFRnd New(const TStr& FNm,
584  const TFAccess& FAccess, const bool& CreateIfNo=true,
585  const int& HdLen=-1, const int& RecLen=-1){
586  return new TFRnd(FNm, FAccess, CreateIfNo, HdLen, RecLen);}
587  ~TFRnd();
589  TStr GetFNm() const;
590  void SetHdRecLen(const int& _HdLen, const int& _RecLen){
591  HdLen=_HdLen; RecLen=_RecLen; RecAct=(HdLen>=0)&&(RecLen>0);}
593  void SetFPos(const int& FPos);
594  void MoveFPos(const int& DFPos);
595  int GetFPos();
596  int GetFLen();
597  bool Empty(){return GetFLen()==0;}
598  bool Eof(){return GetFPos()==GetFLen();}
600  void SetRecN(const int& RecN);
601  int GetRecN();
602  int GetRecs();
604  void GetBf(void* Bf, const TSize& BfL);
605  void PutBf(const void* Bf, const TSize& BfL);
606  void Flush();
608  void GetHd(void* Hd){IAssert(RecAct);
609  int FPos=GetFPos(); SetFPos(0); GetBf(Hd, HdLen); SetFPos(FPos);}
610  void PutHd(const void* Hd){IAssert(RecAct);
611  int FPos=GetFPos(); SetFPos(0); PutBf(Hd, HdLen); SetFPos(FPos);}
612  void GetRec(void* Rec, const int& RecN=-1){
613  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} GetBf(Rec, RecLen);}
614  void PutRec(const void* Rec, const int& RecN=-1){
615  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} PutBf(Rec, RecLen);}
617  void PutCs(const TCs& Cs){PutBf(&Cs, sizeof(Cs));}
618  TCs GetCs(){TCs Cs; GetBf(&Cs, sizeof(Cs)); return Cs;}
619  void PutCh(const char& Ch){PutBf(&Ch, sizeof(Ch));}
620  void PutCh(const char& Ch, const int& Chs);
621  char GetCh(){char Ch; GetBf(&Ch, sizeof(Ch)); return Ch;}
622  void PutUCh(const uchar& UCh){PutBf(&UCh, sizeof(UCh));}
623  uchar GetUCh(){uchar UCh; GetBf(&UCh, sizeof(UCh)); return UCh;}
624  void PutInt(const int& Int){PutBf(&Int, sizeof(Int));}
625  int GetInt(){int Int; GetBf(&Int, sizeof(Int)); return Int;}
626  void PutUInt(const uint& UInt){PutBf(&UInt, sizeof(UInt));}
627  uint GetUInt(){uint UInt; GetBf(&UInt, sizeof(UInt)); return UInt;}
628  void PutStr(const TStr& Str);
629  TStr GetStr(const int& StrLen);
630  TStr GetStr(const int& MxStrLen, bool& IsOk);
631  void PutSIn(const PSIn& SIn, TCs& Cs);
632  PSIn GetSIn(const int& SInLen, TCs& Cs);
634  static TStr GetStrFromFAccess(const TFAccess& FAccess);
635  static TFAccess GetFAccessFromStr(const TStr& Str);
636 };
639 // Files
640 class TFile{
641 public:
642  static const TStr TxtFExt;
643  static const TStr HtmlFExt;
644  static const TStr HtmFExt;
645  static const TStr GifFExt;
646  static const TStr JarFExt;
647 public:
648  static bool Exists(const TStr& FNm);
649  static void Copy(const TStr& SrcFNm, const TStr& DstFNm,
650  const bool& ThrowExceptP=true, const bool& FailIfExistsP=false);
651  static void Del(const TStr& FNm, const bool& ThrowExceptP=true);
652  static void DelWc(const TStr& WcStr, const bool& RecurseDirP=false);
653  static void Rename(const TStr& SrcFNm, const TStr& DstFNm);
654  static TStr GetUniqueFNm(const TStr& FNm);
655  static uint64 GetSize(const TStr& FNm);
656  static uint64 GetCreateTm(const TStr& FNm);
657  static uint64 GetLastAccessTm(const TStr& FNm);
658  static uint64 GetLastWriteTm(const TStr& FNm);
659 };
int PutMem(const TMem &Mem)
Definition: fl.cpp:79
Definition: bd.h:440
#define IAssert(Cond)
Definition: bd.h:262
virtual ~TSIn()
Definition: fl.h:67
virtual ~TSOutMnp()
Definition: bd.h:514
void Save(const uint &UInt)
Definition: fl.h:179
Definition: fl.cpp:451
TCs & operator+=(const TCs &Cs)
Definition: fl.h:22
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:711
virtual int Len() const =0
int Val
Definition: fl.h:14
void Reset()
Definition: fl.h:469
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
TSIn & operator>>(bool &Bool)
Definition: fl.h:100
Definition: fl.h:347
TStr GetFNm() const
Definition: fl.cpp:532
TFInOut & operator=(const TFIn &)
int PutStrFmtLn(const char *FmtStr,...)
Definition: fl.cpp:145
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:311
int BfL
Definition: fl.h:498
int Len() const
Definition: fl.h:249
TSIn & operator>>(double &Double)
Definition: fl.h:110
TSBase(const TSStr &Nm)
Definition: fl.h:50
void Load(ldouble &LFlt)
Definition: fl.h:95
virtual int PutCh(const char &Ch)=0
bool IsMemoryMapped
Definition: fl.h:390
char operator()()
Definition: fl.h:551
Definition: fl.h:557
int BfL
Definition: fl.h:280
virtual int PutBf(const void *LBf, const TSize &LBfL)=0
static void Rename(const TStr &SrcFNm, const TStr &DstFNm)
Definition: fl.cpp:1275
static bool Exists(const TStr &FNm)
Definition: fl.cpp:1156
bool FastMode
Definition: fl.h:60
TSOut & operator<<(const short &Sh)
Definition: fl.h:194
TSOut & operator<<(TSOut &SOut, const T &Val)
Definition: fl.h:214
long double ldouble
Definition: bd.h:16
TMOut(const TMOut &)
TPt< TMIn > PMIn
Definition: fl.h:491
char PeekCh()
Definition: fl.h:367
Definition: fl.h:537
static const TStr GifFExt
Definition: fl.h:645
void Save(const char *CStr, const TSize &CStrLen)
Definition: fl.h:185
TShMIn(const TStr &Str)
Definition: fl.cpp:538
Definition: fl.cpp:213
int PutCh(const char &Ch)
Definition: fl.cpp:458
void AppendBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:851
void LoadAndAdvance(void *Dest, TSize ElemSize)
Copy memory into the destination and advance the cursor.
Definition: fl.h:420
unsigned int uint
Definition: bd.h:11
#define SEEK_CUR
Definition: fl.cpp:968
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
Definition: fl.cpp:881
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:508
TSOut & operator<<(const uint64 &UInt)
Definition: fl.h:199
void FillBf()
Definition: fl.cpp:264
Definition: fl.h:640
#define Fail
Definition: bd.h:238
void PutInt(const int &Int)
Definition: fl.h:624
int FindEol(int &BfN, bool &CrEnd)
Definition: fl.cpp:367
char * AdvanceCursor(TSize N)
Return the current pointer and advance the cursor.
Definition: fl.h:425
uint64 GetBfL()
Definition: fl.cpp:773
int PutCh(const char &Ch)
Definition: fl.h:511
void Save(const void *Bf, const TSize &BfL)
Definition: fl.h:189
bool IsEolnLn() const
Definition: fl.cpp:915
uchar GetUCh()
Definition: fl.h:623
int LnLen
Definition: fl.h:130
Definition: fl.h:319
TSIn & operator>>(float &Flt)
Definition: fl.h:109
TSIn & operator>>(TSIn &SIn, T &Val)
Definition: fl.h:122
TSIn & operator>>(uint &UInt)
Definition: fl.h:106
virtual ~TSBase()
Definition: fl.h:51
TCs(const int &Int)
Definition: fl.h:18
void Load(int &Int)
Definition: fl.h:89
Definition: fl.cpp:63
TSOut & operator<<(const int64 &Int)
Definition: fl.h:198
void Load(uint &UInt)
Definition: fl.h:90
void PutRec(const void *Rec, const int &RecN=-1)
Definition: fl.h:614
void MkEolnLn()
Definition: fl.cpp:947
void CutBf(const int &CutBfL)
Definition: fl.cpp:875
TFileId FileId
Definition: fl.h:278
TSOut & operator<<(const char &Ch)
Definition: fl.h:193
bool Eof()
Definition: fl.h:248
Definition: fl.h:32
#define SEEK_SET
Definition: fl.cpp:970
int Len() const
Definition: fl.h:465
void Load(char *&CStr, const int &MxCStrLen, const int &CStrLen)
Definition: fl.h:96
char PeekCh()
Definition: fl.h:251
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:463
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static const TStr HtmlFExt
Definition: fl.h:643
int PutCh(const char &Ch)
Definition: fl.h:377
static TPt< TSOut > New()
Definition: fl.h:266
Definition: fl.h:347
TStr GetCrLfLn()
Definition: fl.cpp:901
char PeekCh()
Definition: fl.h:405
TSOut & operator<<(const double &Double)
Definition: fl.h:201
int Get() const
Definition: fl.h:25
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:232
Definition: fl.h:384
Definition: fl.cpp:305
char * GetBfAddr() const
Definition: fl.h:524
char * Cursor
Definition: fl.h:389
void Save(const int64 &Int)
Definition: fl.h:180
char PeekCh()
Definition: fl.cpp:706
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:763
void PutUInt(const uint &UInt)
Definition: fl.h:626
TSOut & operator<<(const ushort &USh)
Definition: fl.h:195
int PutSepLn(const int &Lns=0)
Definition: fl.cpp:182
int PutLn(const int &Lns=1)
Definition: fl.cpp:158
void Load(char &Ch)
Definition: fl.h:86
Definition: fl.h:275
void Clr()
Definition: fl.h:375
static PSOut New(const int &MxBfL=1024)
Definition: fl.h:506
Definition: fl.h:359
TStr GetAsStr() const
Definition: fl.cpp:869
TSIn & operator>>(uint64 &UInt)
Definition: fl.h:108
void Load(uchar &UCh)
Definition: fl.h:85
bool Eof()
Definition: fl.h:364
Definition: fl.h:40
virtual void LoadCs()
Definition: fl.cpp:28
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:328
char * Bf
Definition: fl.h:323
virtual void SetPos(const int &Pos)=0
int GetFPos() const
Definition: fl.cpp:249
char * GetBfAddr()
Definition: fl.h:486
void Load(int64 &Int)
Definition: fl.h:91
Definition: fl.h:437
void FlushBf()
Definition: fl.cpp:410
Definition: fl.h:58
TFileId FileId
Definition: fl.h:322
int UpdateLnLen(const int &StrLen, const bool &ForceInLn=false)
Definition: fl.cpp:70
Definition: dt.h:77
Definition: fl.h:16
void SetFastMode(const bool &_FastMode)
Definition: fl.h:78
char GetCh()
Definition: fl.h:621
#define ClassTP(TNm, PNm)
Definition: bd.h:126
void PutCs(const TCs &Cs)
Definition: fl.h:617
static uint64 GetSize(const TStr &FNm)
void Flush()
Definition: fl.cpp:475
TFOut & operator=(const TFOut &)
int Len() const
Definition: fl.h:301
char * Bf
Definition: fl.h:439
virtual int GetSize() const =0
TSize SizeLeft
Definition: fl.h:388
Definition: fl.h:240
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
void Load(double &Flt)
Definition: fl.h:93
void Reset()
Definition: fl.h:254
void SkipCommentLines()
Move stream pointer along until a non commented line is found.
Definition: fl.cpp:814
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:217
TMOut & operator=(const TMOut &)
TCs & operator=(const TCs &Cs)
Definition: fl.h:20
void SaveCs()
Definition: fl.h:171
void PutHd(const void *Hd)
Definition: fl.h:610
static const int MxMask
Definition: fl.h:13
static const TStr TxtFExt
Definition: fl.h:642
static TPt< TSIn > New()
Definition: fl.h:246
char Ch
Definition: fl.h:539
static TCs GetCsFromBf(char *Bf, const int &BfL)
Definition: fl.cpp:12
static void DelWc(const TStr &WcStr, const bool &RecurseDirP=false)
Definition: fl.cpp:1264
Definition: fl.h:347
static TStr GetUniqueFNm(const TStr &FNm)
Definition: fl.cpp:1281
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:224
virtual bool Eof()=0
Definition: fl.h:225
virtual TFileId GetFileId() const
Definition: fl.h:146
void Load(sdouble &SFlt)
Definition: fl.h:94
static const TStr HtmFExt
Definition: fl.h:644
TFIn & operator=(const TFIn &)
unsigned long long uint64
Definition: bd.h:38
void GetHd(void *Hd)
Definition: fl.h:608
char EofCh
Definition: fl.h:538
uint64 BfL
Definition: fl.h:440
TLnRet(const PSIn &_SIn)
Definition: fl.h:562
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.h:412
void Load(bool &Bool)
Definition: fl.h:84
bool Eof() const
Definition: fl.h:548
TSOut & operator=(const TSOut &)
char GetCh()
Definition: fl.h:302
void Save(const uint64 &UInt)
Definition: fl.h:181
void Flush()
Definition: fl.h:379
void * LoadNewBf(const int &BfL)
Definition: fl.h:82
void Save(const double &Flt)
Definition: fl.h:182
int Len() const
Definition: fl.h:396
char GetCh()
Definition: fl.h:397
TCs & operator+=(const char &Ch)
Definition: fl.h:23
size_t TSize
Definition: bd.h:58
int PutBool(const bool &Bool)
Definition: fl.cpp:89
TCs & operator+=(const int &Int)
Definition: fl.h:24
void Save(const PSIn &SIn, const TSize &BfL=-1)
Definition: fl.h:188
static void Copy(const TStr &SrcFNm, const TStr &DstFNm, const bool &ThrowExceptP=true, const bool &FailIfExistsP=false)
char * Bf
Definition: fl.h:279
static void Del(const TStr &FNm, const bool &ThrowExceptP=true)
Definition: fl.cpp:1254
Definition: fl.h:347
uint64 CountNewLinesInRange(uint64 Lb, uint64 Ub)
Finds number of new line chars in interval [Lb, Ub)
Definition: fl.cpp:782
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:857
int PutSep(const int &NextStrLen=0)
Definition: fl.cpp:170
void SetHdRecLen(const int &_HdLen, const int &_RecLen)
Definition: fl.h:590
int PutInt(const int &Int)
Definition: fl.cpp:93
bool Eof()
Definition: fl.h:298
int MxBfL
Definition: fl.h:498
uint64 GetBfC()
Definition: fl.cpp:769
bool Eof()
Definition: fl.h:395
TSIn & operator>>(short &Sh)
Definition: fl.h:103
TSOut & operator<<(TSOut &(*FuncPt)(TSOut &))
Definition: fl.h:204
Definition: fl.h:220
bool IsMemoryMapped
Definition: fl.h:441
void Reset()
Definition: fl.h:309
TSOut & operator<<(const long double &LDouble)
Definition: fl.h:202
TPt< TSInOut > PSInOut
Definition: fl.h:236
TCRef CRef
Definition: fl.h:42
TSIn & operator=(const TSIn &)
int GetInt()
Definition: fl.h:625
TFileId FileId
Definition: fl.h:351
Definition: fl.h:569
void MovePos(const int &DPos)
Definition: fl.h:372
unsigned char uchar
Definition: bd.h:10
void SaveBf(const void *Bf, const TSize &BfL)
Definition: fl.h:172
void PutCh(const char &Ch)
Definition: fl.h:619
static const TPt< TSOut > StdOut
Definition: fl.h:208
int FindEol(uint64 &BfN, bool &CrEnd)
Definition: fl.cpp:725
Definition: fl.h:128
TChRet(const PSIn &_SIn, const char &_EofCh=0)
Definition: fl.h:545
bool OwnBf
Definition: fl.h:499
TCs GetCs()
Definition: fl.h:618
int PutIndent(const int &IndentLev=1)
Definition: fl.cpp:154
static PSIn New(const void *_Bf, const uint64 &_BfL, const bool &TakeBf=false)
Definition: fl.cpp:668
void Save(const uchar &UCh)
Definition: fl.h:175
int PutFlt(const double &Flt)
Definition: fl.cpp:109
Definition: fl.h:260
virtual void Reset()
Definition: fl.h:75
void Save(const bool &Bool)
Definition: fl.h:173
virtual void Flush()=0
int Len() const
Definition: fl.h:365
void Save(const ushort &UShort)
Definition: fl.h:177
bool GetNextLnBf(TChA &LnChA)
Definition: fl.h:416
unsigned short ushort
Definition: bd.h:13
TFileId GetFileId() const
Definition: fl.h:342
static PSInOut New(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
Definition: fl.cpp:496
uint64 GetLineEndPos(uint64 Ind)
Finds end of line in which Ind is present.
Definition: fl.cpp:802
int BfC
Definition: fl.h:280
Definition: fl.h:495
TSIn & operator>>(int &Int)
Definition: fl.h:105
TSInOut & operator=(const TSInOut &)
TFileId GetFileId() const
Definition: fl.h:362
TSOut & operator<<(const uint &Int)
Definition: fl.h:197
Definition: fl.h:347
Definition: dt.h:201
uint64 GetLineStartPos(uint64 Ind)
Finds beginning of line in which Ind is present.
Definition: fl.cpp:795
virtual void Clr()=0
TSOut & operator<<(const TSOutMnp &Mnp)
Definition: fl.h:203
int PutDosLn(const int &Lns=1)
Definition: fl.cpp:164
void GetRec(void *Rec, const int &RecN=-1)
Definition: fl.h:612
virtual int GetPos() const =0
float sdouble
Definition: bd.h:15
Definition: fl.h:349
void Save(const short &Short)
Definition: fl.h:176
virtual void MovePos(const int &DPos)=0
char * GetLine(uint64 Ind)
Definition: fl.cpp:810
static const TPt< TSIn > StdIn
Definition: fl.h:116
static const TSize MxBfL
Definition: fl.h:321
TStdOut & operator=(const TStdOut &)
void Save(const ldouble &LFlt)
Definition: fl.h:184
virtual ~TSOut()
Definition: fl.h:138
Definition: fl.h:65
void Clr()
Definition: fl.h:518
char GetCh()
Definition: fl.h:250
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:517
void Load(uint64 &UInt)
Definition: fl.h:92
int MxLnLen
Definition: fl.h:130
long long int64
Definition: bd.h:27
int GetPos() const
Definition: fl.h:373
virtual ~TSInOut()
Definition: fl.h:226
bool IsFastMode() const
Definition: fl.h:77
Definition: dt.h:412
char GetCh()
Definition: fl.h:549
bool Eof()
Definition: fl.h:464
void Save(const sdouble &SFlt)
Definition: fl.h:183
void Load(ushort &UShort)
Definition: fl.h:88
int PutStr(const char *CStr)
Definition: fl.cpp:117
TMIn & operator=(const TMIn &)
void LoadBf(const void *Bf, const TSize &BfL)
Definition: fl.h:81
Definition: fl.h:394
Definition: fl.h:559
uint64 BfC
Definition: fl.h:440
FILE * TFileId
Definition: bd.h:17
void Load(short &Short)
Definition: fl.h:87
TSIn & operator>>(long double &LDouble)
Definition: fl.h:111
virtual TStr GetSNm() const
Definition: fl.cpp:20
TStdIn & operator=(const TStdIn &)
TSOut & operator<<(PSIn &SIn)
Definition: fl.h:206
int PutCh(const char &Ch)
Definition: fl.h:268
void SetPos(const int &Pos)
Definition: fl.h:371
TChRet & operator=(const TChRet &)
char * getCursor()
Definition: fl.h:402
TSIn & operator>>(char &Ch)
Definition: fl.h:102
void Flush()
Definition: fl.h:515
static uint64 GetLastWriteTm(const TStr &FNm)
static uint64 GetCreateTm(const TStr &FNm)
TSOut & operator<<(const float &Flt)
Definition: fl.h:200
void SetBfC(uint64 Pos)
Definition: fl.cpp:777
static const int MxBfL
Definition: fl.h:277
Definition: fl.h:136
char PeekCh()
Definition: fl.h:305
virtual TSOut & operator()(TSOut &SOut) const =0
int GetSize() const
Definition: fl.cpp:500
TPt< TSIn > PSIn
Definition: fl.h:119
void Resize(const int &ReqLen=-1)
Definition: fl.cpp:825
bool IsCrLfLn() const
Definition: fl.cpp:895
TSize BfL
Definition: fl.h:324
char * Bf
Definition: fl.h:497
virtual char GetCh()=0
virtual char PeekCh()=0
TCs(const TCs &Cs)
Definition: fl.h:17
void Save(const char &Ch)
Definition: fl.h:174
char GetCh(const int &ChN) const
Definition: fl.h:519
int Len() const
Definition: fl.h:517
void CloseMapping()
munmap the mapping. Note that munmap is not called by the destructor
Definition: fl.cpp:577
TSize TotalLength
Definition: fl.h:387
virtual bool GetNextLnBf(TChA &LnChA)=0
int PutStrLn(const TStr &Str, const bool &ForceInLn=false)
Definition: fl.h:161
int GetFLen() const
Definition: fl.cpp:255
Definition: fl.h:11
int PutStrFmt(const char *FmtStr,...)
Definition: fl.cpp:136
bool Eof()
Definition: fl.h:598
bool operator==(const TCs &Cs) const
Definition: fl.h:21
void Flush()
Definition: fl.h:270
void EnableLnTrunc(const int &_MxLnLen)
Definition: fl.h:140
Definition: fl.cpp:688
TSOut & operator<<(const bool &Bool)
Definition: fl.h:191
Definition: fl.h:347
int PutUInt(const uint &Int)
Definition: fl.cpp:101
char GetCh()
Definition: fl.h:366
void PutUCh(const uchar &UCh)
Definition: fl.h:622
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:526
TPt< TSOut > PSOut
Definition: fl.h:211
Definition: fl.h:347
TStr GetEolnLn(const bool &DoAddEoln, const bool &DoCutBf)
Definition: fl.cpp:922
void DisableLnTrunc()
Definition: fl.h:141
void Save(const int &Int)
Definition: fl.h:178
Definition: fl.h:43
uint GetUInt()
Definition: fl.h:627
TSOut & operator<<(const int &Int)
Definition: fl.h:196
TSIn & operator>>(int64 &Int)
Definition: fl.h:107
char GetCh()
Definition: fl.cpp:701
void SetFPos(const int &FPos) const
Definition: fl.cpp:243
TCs Cs
Definition: fl.h:44
void LoadCs()
Definition: fl.h:408
TSIn & operator>>(uchar &UCh)
Definition: fl.h:101
TSOut & operator<<(const uchar &UCh)
Definition: fl.h:192
bool Empty()
Definition: fl.h:597
Definition: fl.h:535
static const TStr JarFExt
Definition: fl.h:646
bool NextLn(TStr &LnStr)
Definition: fl.cpp:955
Definition: fl.h:509
bool GetNextLn(TStr &LnStr)
Definition: fl.cpp:43
static uint64 GetLastAccessTm(const TStr &FNm)
char * OriginalBuffer
Definition: fl.h:386
TSIn & operator>>(ushort &USh)
Definition: fl.h:104