SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fl.h
Go to the documentation of this file.
1 #include "bd.h"
2 
4 // Forward-Definitions
5 class TMem;
6 class TChA;
7 class TStr;
8 
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){}
19 
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;}
26 
27  static TCs GetCsFromBf(char* Bf, const int& BfL);
28 };
29 
31 // Output-stream-manipulator
32 class TSOutMnp {
33 public:
34  virtual TSOut& operator()(TSOut& SOut) const=0;
35  virtual ~TSOutMnp();
36 };
37 
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(){}
52 
53  virtual TStr GetSNm() const;
54 };
55 
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(){}
68 
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;}
76 
77  bool IsFastMode() const {return FastMode;}
78  void SetFastMode(const bool& _FastMode){FastMode=_FastMode;}
79 
80  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);
99 
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;}
112 
113  bool GetNextLn(TStr& LnStr);
114  bool GetNextLn(TChA& LnChA);
115 
116  static const TPt<TSIn> StdIn;
117  friend class TPt<TSIn>;
118 };
119 typedef TPt<TSIn> PSIn;
120 
121 template <class T>
122 TSIn& operator>>(TSIn& SIn, T& Val) {
123  Val.Load(SIn); return SIn;
124 }
125 
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(){}
139 
140  void EnableLnTrunc(const int& _MxLnLen){MxLnLen=_MxLnLen;}
142 
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;}
147 
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);
170 
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);}
190 
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);}
207 
208  static const TPt<TSOut> StdOut;
209  friend class TPt<TSOut>;
210 };
212 
213 template <class T>
214 TSOut& operator<<(TSOut& SOut, const T& Val){
215  Val.Save(SOut); return SOut;
216 }
217 
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(){}
227 
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
233 
234  friend class TPt<TSInOut>;
235 };
237 
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();}
247 
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 };
257 
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();}
267 
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 };
272 
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();
297 
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);
311 
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 };
316 
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();
337 
338  int PutCh(const char& Ch);
339  int PutBf(const void* LBf, const TSize& LBfL);
340  void Flush();
341 
342  TFileId GetFileId() const {return FileId;}
343 };
344 
346 // Input-Output-File
348 
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); }
360 
361  TStr GetFNm() const;
362  TFileId GetFileId() const {return FileId;}
363 
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);
370 
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; }
376 
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 };
381 
383 // Input-Memory
384 class TMIn: public TSIn{
385 private:
386  char* Bf;
389 private:
390  TMIn();
391  TMIn(const TMIn&);
392  TMIn& operator=(const TMIn&);
393 private:
394  int FindEol(uint64& BfN, bool& CrEnd);
395 public:
396  TMIn(const void* _Bf, const uint64& _BfL, const bool& TakeBf=false);
397  TMIn(TSIn& SIn);
398  TMIn(const char* CStr);
400  TMIn(const TStr& Str, bool FromFile);
401  TMIn(const TChA& ChA);
402  static PSIn New(const void* _Bf, const uint64& _BfL, const bool& TakeBf=false);
403  static PSIn New(const char* CStr);
404  static PSIn New(const TStr& Str);
405  static PSIn New(const TChA& ChA);
406  static TPt<TMIn> New(const TStr& Str, bool FromFile);
407  //static TPt<TMIn> New(const TStr& Str, uint64);
408 
409  ~TMIn();
410 
411  bool Eof(){return BfC==BfL;}
412  int Len() const {return static_cast<int>(BfL-BfC);}
413  char GetCh();
414  char PeekCh();
415  int GetBf(const void* LBf, const TSize& LBfL);
416  void Reset(){Cs=TCs(); BfC=0;}
417  bool GetNextLnBf(TChA& LnChA);
418 
419  uint64 GetBfC();
420  uint64 GetBfL();
421  void SetBfC(uint64 Pos);
422 
429  char* GetLine(uint64 Ind);
431  void SkipCommentLines();
432 
433  char* GetBfAddr(){return Bf;}
434 
435  friend class TPt<TMIn>;
436 };
437 
438 typedef TPt<TMIn> PMIn;
439 
441 // Output-Memory
442 class TMOut: public TSOut{
443 private:
444  char* Bf;
445  int BfL, MxBfL;
446  bool OwnBf;
447  void Resize(const int& ReqLen = -1);
448 private:
449  TMOut(const TMOut&);
450  TMOut& operator=(const TMOut&);
451 public:
452  TMOut(const int& _MxBfL=1024);
453  static PSOut New(const int& MxBfL=1024){
454  return PSOut(new TMOut(MxBfL));}
455  TMOut(char* _Bf, const int& _MxBfL);
456  ~TMOut(){if (OwnBf&&(Bf!=NULL)){delete[] Bf;}}
457 
458  int PutCh(const char& Ch){if (BfL==MxBfL){
459  Resize();} return Bf[BfL++]=Ch;}
460  int PutBf(const void* LBf, const TSize& LBfL);
461  void AppendBf(const void* LBf, const TSize& LBfL);
462  void Flush(){}
463 
464  int Len() const {return BfL;}
465  void Clr(){BfL=0;}
466  char GetCh(const int& ChN) const {
467  IAssert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
468  TStr GetAsStr() const;
469  void CutBf(const int& CutBfL);
470  PSIn GetSIn(const bool& IsCut=true, const int& CutBfL=-1);
471  char* GetBfAddr() const {return Bf;}
472 
473  bool IsCrLfLn() const;
474  TStr GetCrLfLn();
475  bool IsEolnLn() const;
476  TStr GetEolnLn(const bool& DoAddEoln, const bool& DoCutBf);
477  void MkEolnLn();
478 };
479 
481 // Character-Returner
482 class TChRet{
483 private:
485  char EofCh;
486  char Ch;
487 private:
488  TChRet();
489  TChRet(const TChRet&);
490  TChRet& operator=(const TChRet&);
491 public:
492  TChRet(const PSIn& _SIn, const char& _EofCh=0):
493  SIn(_SIn), EofCh(_EofCh), Ch(_EofCh){}
494 
495  bool Eof() const {return Ch==EofCh;}
496  char GetCh(){
497  if (SIn->Eof()){return Ch=EofCh;} else {return Ch=SIn->GetCh();}}
498  char operator()(){return Ch;}
499 };
500 
502 // Line-Returner
503 // J: after talking to BlazF -- can be removed from GLib
504 class TLnRet{
505 private:
508 public:
509  TLnRet(const PSIn& _SIn): SIn(_SIn) {}
510 
511  bool NextLn(TStr& LnStr);
512 };
513 
515 // Random-Access-File
517 private:
518  TFileId FileId;
519  TSStr FNm;
520  bool RecAct;
521  int HdLen, RecLen;
522 private:
523  void RefreshFPos();
524 private:
525  TFRnd(const TFRnd&);
526  TFRnd& operator=(const TFRnd&);
527 public:
528  TFRnd(const TStr& _FNm, const TFAccess& FAccess,
529  const bool& CreateIfNo=true, const int& _HdLen=-1, const int& _RecLen=-1);
530  static PFRnd New(const TStr& FNm,
531  const TFAccess& FAccess, const bool& CreateIfNo=true,
532  const int& HdLen=-1, const int& RecLen=-1){
533  return new TFRnd(FNm, FAccess, CreateIfNo, HdLen, RecLen);}
534  ~TFRnd();
535 
536  TStr GetFNm() const;
537  void SetHdRecLen(const int& _HdLen, const int& _RecLen){
538  HdLen=_HdLen; RecLen=_RecLen; RecAct=(HdLen>=0)&&(RecLen>0);}
539 
540  void SetFPos(const int& FPos);
541  void MoveFPos(const int& DFPos);
542  int GetFPos();
543  int GetFLen();
544  bool Empty(){return GetFLen()==0;}
545  bool Eof(){return GetFPos()==GetFLen();}
546 
547  void SetRecN(const int& RecN);
548  int GetRecN();
549  int GetRecs();
550 
551  void GetBf(void* Bf, const TSize& BfL);
552  void PutBf(const void* Bf, const TSize& BfL);
553  void Flush();
554 
555  void GetHd(void* Hd){IAssert(RecAct);
556  int FPos=GetFPos(); SetFPos(0); GetBf(Hd, HdLen); SetFPos(FPos);}
557  void PutHd(const void* Hd){IAssert(RecAct);
558  int FPos=GetFPos(); SetFPos(0); PutBf(Hd, HdLen); SetFPos(FPos);}
559  void GetRec(void* Rec, const int& RecN=-1){
560  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} GetBf(Rec, RecLen);}
561  void PutRec(const void* Rec, const int& RecN=-1){
562  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} PutBf(Rec, RecLen);}
563 
564  void PutCs(const TCs& Cs){PutBf(&Cs, sizeof(Cs));}
565  TCs GetCs(){TCs Cs; GetBf(&Cs, sizeof(Cs)); return Cs;}
566  void PutCh(const char& Ch){PutBf(&Ch, sizeof(Ch));}
567  void PutCh(const char& Ch, const int& Chs);
568  char GetCh(){char Ch; GetBf(&Ch, sizeof(Ch)); return Ch;}
569  void PutUCh(const uchar& UCh){PutBf(&UCh, sizeof(UCh));}
570  uchar GetUCh(){uchar UCh; GetBf(&UCh, sizeof(UCh)); return UCh;}
571  void PutInt(const int& Int){PutBf(&Int, sizeof(Int));}
572  int GetInt(){int Int; GetBf(&Int, sizeof(Int)); return Int;}
573  void PutUInt(const uint& UInt){PutBf(&UInt, sizeof(UInt));}
574  uint GetUInt(){uint UInt; GetBf(&UInt, sizeof(UInt)); return UInt;}
575  void PutStr(const TStr& Str);
576  TStr GetStr(const int& StrLen);
577  TStr GetStr(const int& MxStrLen, bool& IsOk);
578  void PutSIn(const PSIn& SIn, TCs& Cs);
579  PSIn GetSIn(const int& SInLen, TCs& Cs);
580 
581  static TStr GetStrFromFAccess(const TFAccess& FAccess);
582  static TFAccess GetFAccessFromStr(const TStr& Str);
583 };
584 
586 // Files
587 class TFile{
588 public:
589  static const TStr TxtFExt;
590  static const TStr HtmlFExt;
591  static const TStr HtmFExt;
592  static const TStr GifFExt;
593  static const TStr JarFExt;
594 public:
595  static bool Exists(const TStr& FNm);
596  static void Copy(const TStr& SrcFNm, const TStr& DstFNm,
597  const bool& ThrowExceptP=true, const bool& FailIfExistsP=false);
598  static void Del(const TStr& FNm, const bool& ThrowExceptP=true);
599  static void DelWc(const TStr& WcStr, const bool& RecurseDirP=false);
600  static void Rename(const TStr& SrcFNm, const TStr& DstFNm);
601  static TStr GetUniqueFNm(const TStr& FNm);
602  static uint64 GetSize(const TStr& FNm);
603  static uint64 GetCreateTm(const TStr& FNm);
604  static uint64 GetLastAccessTm(const TStr& FNm);
605  static uint64 GetLastWriteTm(const TStr& FNm);
606 };
607 
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
~TFOut()
Definition: fl.cpp:451
TCs & operator+=(const TCs &Cs)
Definition: fl.h:22
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:655
int Val
Definition: fl.h:14
void Reset()
Definition: fl.h:416
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:445
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 TSOut & operator()(TSOut &SOut) const =0
virtual int PutCh(const char &Ch)=0
char operator()()
Definition: fl.h:498
Definition: fl.h:504
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:1219
static bool Exists(const TStr &FNm)
Definition: fl.cpp:1100
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:438
char PeekCh()
Definition: fl.h:367
PSIn SIn
Definition: fl.h:484
static const TStr GifFExt
Definition: fl.h:592
void Save(const char *CStr, const TSize &CStrLen)
Definition: fl.h:185
TStdOut()
Definition: fl.cpp:213
int PutCh(const char &Ch)
Definition: fl.cpp:458
void AppendBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:795
unsigned int uint
Definition: bd.h:11
#define SEEK_CUR
Definition: fl.cpp:912
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
Definition: fl.cpp:825
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:587
#define Fail
Definition: bd.h:238
void PutInt(const int &Int)
Definition: fl.h:571
int FindEol(int &BfN, bool &CrEnd)
Definition: fl.cpp:367
uint64 GetBfL()
Definition: fl.cpp:717
int PutCh(const char &Ch)
Definition: fl.h:458
void Save(const void *Bf, const TSize &BfL)
Definition: fl.h:189
bool IsEolnLn() const
Definition: fl.cpp:859
uchar GetUCh()
Definition: fl.h:570
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
TStdIn()
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:561
void MkEolnLn()
Definition: fl.cpp:891
void CutBf(const int &CutBfL)
Definition: fl.cpp:819
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:914
int Len() const
Definition: fl.h:412
void Load(char *&CStr, const int &MxCStrLen, const int &CStrLen)
Definition: fl.h:96
char PeekCh()
Definition: fl.h:251
UndefDefaultCopyAssign(TLnRet)
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:590
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:845
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
~TFIn()
Definition: fl.cpp:305
char * GetBfAddr() const
Definition: fl.h:471
void Save(const int64 &Int)
Definition: fl.h:180
char PeekCh()
Definition: fl.cpp:650
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:707
void PutUInt(const uint &UInt)
Definition: fl.h:573
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:453
~TFInOut()
Definition: fl.h:359
TStr GetAsStr() const
Definition: fl.cpp:813
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
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:433
void Load(int64 &Int)
Definition: fl.h:91
Definition: fl.h:384
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
TCs()
Definition: fl.h:16
void SetFastMode(const bool &_FastMode)
Definition: fl.h:78
char GetCh()
Definition: fl.h:568
#define ClassTP(TNm, PNm)
Definition: bd.h:126
void PutCs(const TCs &Cs)
Definition: fl.h:564
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:386
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:758
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:557
static const int MxMask
Definition: fl.h:13
static const TStr TxtFExt
Definition: fl.h:589
static TPt< TSIn > New()
Definition: fl.h:246
char Ch
Definition: fl.h:486
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:1208
Definition: fl.h:347
static TStr GetUniqueFNm(const TStr &FNm)
Definition: fl.cpp:1225
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:224
virtual bool Eof()=0
TSInOut()
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:591
TFIn & operator=(const TFIn &)
unsigned long long uint64
Definition: bd.h:38
void GetHd(void *Hd)
Definition: fl.h:555
char EofCh
Definition: fl.h:485
uint64 BfL
Definition: fl.h:387
TLnRet(const PSIn &_SIn)
Definition: fl.h:509
void Load(bool &Bool)
Definition: fl.h:84
bool Eof() const
Definition: fl.h:495
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
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:1198
Definition: fl.h:347
uint64 CountNewLinesInRange(uint64 Lb, uint64 Ub)
Finds number of new line chars in interval [Lb, Ub)
Definition: fl.cpp:726
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:801
int PutSep(const int &NextStrLen=0)
Definition: fl.cpp:170
void SetHdRecLen(const int &_HdLen, const int &_RecLen)
Definition: fl.h:537
int PutInt(const int &Int)
Definition: fl.cpp:93
bool Eof()
Definition: fl.h:298
int MxBfL
Definition: fl.h:445
uint64 GetBfC()
Definition: fl.cpp:713
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:388
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:572
TFileId FileId
Definition: fl.h:351
Definition: fl.h:516
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:566
static const TPt< TSOut > StdOut
Definition: fl.h:208
int FindEol(uint64 &BfN, bool &CrEnd)
Definition: fl.cpp:669
Definition: fl.h:128
TChRet(const PSIn &_SIn, const char &_EofCh=0)
Definition: fl.h:492
bool OwnBf
Definition: fl.h:446
TCs GetCs()
Definition: fl.h:565
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:612
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
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:746
int BfC
Definition: fl.h:280
Definition: fl.h:442
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:739
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:559
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:754
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
TSIn()
Definition: fl.h:65
void Clr()
Definition: fl.h:465
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:496
bool Eof()
Definition: fl.h:411
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
PSIn SIn
Definition: fl.h:506
uint64 BfC
Definition: fl.h:387
FILE * TFileId
Definition: bd.h:17
virtual int GetSize() const =0
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 &)
TSIn & operator>>(char &Ch)
Definition: fl.h:102
void Flush()
Definition: fl.h:462
virtual int GetPos() const =0
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:721
static const int MxBfL
Definition: fl.h:277
TSOut()
Definition: fl.h:136
char PeekCh()
Definition: fl.h:305
int GetSize() const
Definition: fl.cpp:500
TPt< TSIn > PSIn
Definition: fl.h:119
void Resize(const int &ReqLen=-1)
Definition: fl.cpp:769
bool IsCrLfLn() const
Definition: fl.cpp:839
TSize BfL
Definition: fl.h:324
char * Bf
Definition: fl.h:444
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:466
int Len() const
Definition: fl.h:464
virtual bool GetNextLnBf(TChA &LnChA)=0
virtual int Len() const =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:545
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
~TMIn()
Definition: fl.cpp:632
TSOut & operator<<(const bool &Bool)
Definition: fl.h:191
TFAccess
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:569
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:866
void DisableLnTrunc()
Definition: fl.h:141
void Save(const int &Int)
Definition: fl.h:178
TSStr SNm
Definition: fl.h:43
uint GetUInt()
Definition: fl.h:574
TSOut & operator<<(const int &Int)
Definition: fl.h:196
TSIn & operator>>(int64 &Int)
Definition: fl.h:107
char GetCh()
Definition: fl.cpp:645
void SetFPos(const int &FPos) const
Definition: fl.cpp:243
TCs Cs
Definition: fl.h:44
TSIn & operator>>(uchar &UCh)
Definition: fl.h:101
TSOut & operator<<(const uchar &UCh)
Definition: fl.h:192
bool Empty()
Definition: fl.h:544
Definition: fl.h:482
static const TStr JarFExt
Definition: fl.h:593
bool NextLn(TStr &LnStr)
Definition: fl.cpp:899
~TMOut()
Definition: fl.h:456
bool GetNextLn(TStr &LnStr)
Definition: fl.cpp:43
static uint64 GetLastAccessTm(const TStr &FNm)
TSIn & operator>>(ushort &USh)
Definition: fl.h:104