SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
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;
387  int BfC, BfL;
388 private:
389  TMIn();
390  TMIn(const TMIn&);
391  TMIn& operator=(const TMIn&);
392 public:
393  TMIn(const void* _Bf, const int& _BfL, const bool& TakeBf=false);
394  TMIn(TSIn& SIn);
395  TMIn(const char* CStr);
396  TMIn(const TStr& Str);
397  TMIn(const TChA& ChA);
398  static PSIn New(const void* _Bf, const int& _BfL, const bool& TakeBf=false);
399  static PSIn New(const char* CStr);
400  static PSIn New(const TStr& Str);
401  static PSIn New(const TChA& ChA);
402  ~TMIn(){if (Bf!=NULL){delete[] Bf;}}
403 
404  bool Eof(){return BfC==BfL;}
405  int Len() const {return BfL-BfC;}
406  char GetCh();
407  char PeekCh();
408  int GetBf(const void* LBf, const TSize& LBfL);
409  void Reset(){Cs=TCs(); BfC=0;}
410  bool GetNextLnBf(TChA& LnChA);
411 
412  char* GetBfAddr(){return Bf;}
413 };
414 
416 // Output-Memory
417 class TMOut: public TSOut{
418 private:
419  char* Bf;
420  int BfL, MxBfL;
421  bool OwnBf;
422  void Resize(const int& ReqLen = -1);
423 private:
424  TMOut(const TMOut&);
425  TMOut& operator=(const TMOut&);
426 public:
427  TMOut(const int& _MxBfL=1024);
428  static PSOut New(const int& MxBfL=1024){
429  return PSOut(new TMOut(MxBfL));}
430  TMOut(char* _Bf, const int& _MxBfL);
431  ~TMOut(){if (OwnBf&&(Bf!=NULL)){delete[] Bf;}}
432 
433  int PutCh(const char& Ch){if (BfL==MxBfL){
434  Resize();} return Bf[BfL++]=Ch;}
435  int PutBf(const void* LBf, const TSize& LBfL);
436  void AppendBf(const void* LBf, const TSize& LBfL);
437  void Flush(){}
438 
439  int Len() const {return BfL;}
440  void Clr(){BfL=0;}
441  char GetCh(const int& ChN) const {
442  IAssert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
443  TStr GetAsStr() const;
444  void CutBf(const int& CutBfL);
445  PSIn GetSIn(const bool& IsCut=true, const int& CutBfL=-1);
446  char* GetBfAddr() const {return Bf;}
447 
448  bool IsCrLfLn() const;
449  TStr GetCrLfLn();
450  bool IsEolnLn() const;
451  TStr GetEolnLn(const bool& DoAddEoln, const bool& DoCutBf);
452  void MkEolnLn();
453 };
454 
456 // Character-Returner
457 class TChRet{
458 private:
460  char EofCh;
461  char Ch;
462 private:
463  TChRet();
464  TChRet(const TChRet&);
465  TChRet& operator=(const TChRet&);
466 public:
467  TChRet(const PSIn& _SIn, const char& _EofCh=0):
468  SIn(_SIn), EofCh(_EofCh), Ch(_EofCh){}
469 
470  bool Eof() const {return Ch==EofCh;}
471  char GetCh(){
472  if (SIn->Eof()){return Ch=EofCh;} else {return Ch=SIn->GetCh();}}
473  char operator()(){return Ch;}
474 };
475 
477 // Line-Returner
478 // J: after talking to BlazF -- can be removed from GLib
479 class TLnRet{
480 private:
483 public:
484  TLnRet(const PSIn& _SIn): SIn(_SIn) {}
485 
486  bool NextLn(TStr& LnStr);
487 };
488 
490 // Random-Access-File
492 private:
493  TFileId FileId;
494  TSStr FNm;
495  bool RecAct;
496  int HdLen, RecLen;
497 private:
498  void RefreshFPos();
499 private:
500  TFRnd(const TFRnd&);
501  TFRnd& operator=(const TFRnd&);
502 public:
503  TFRnd(const TStr& _FNm, const TFAccess& FAccess,
504  const bool& CreateIfNo=true, const int& _HdLen=-1, const int& _RecLen=-1);
505  static PFRnd New(const TStr& FNm,
506  const TFAccess& FAccess, const bool& CreateIfNo=true,
507  const int& HdLen=-1, const int& RecLen=-1){
508  return new TFRnd(FNm, FAccess, CreateIfNo, HdLen, RecLen);}
509  ~TFRnd();
510 
511  TStr GetFNm() const;
512  void SetHdRecLen(const int& _HdLen, const int& _RecLen){
513  HdLen=_HdLen; RecLen=_RecLen; RecAct=(HdLen>=0)&&(RecLen>0);}
514 
515  void SetFPos(const int& FPos);
516  void MoveFPos(const int& DFPos);
517  int GetFPos();
518  int GetFLen();
519  bool Empty(){return GetFLen()==0;}
520  bool Eof(){return GetFPos()==GetFLen();}
521 
522  void SetRecN(const int& RecN);
523  int GetRecN();
524  int GetRecs();
525 
526  void GetBf(void* Bf, const TSize& BfL);
527  void PutBf(const void* Bf, const TSize& BfL);
528  void Flush();
529 
530  void GetHd(void* Hd){IAssert(RecAct);
531  int FPos=GetFPos(); SetFPos(0); GetBf(Hd, HdLen); SetFPos(FPos);}
532  void PutHd(const void* Hd){IAssert(RecAct);
533  int FPos=GetFPos(); SetFPos(0); PutBf(Hd, HdLen); SetFPos(FPos);}
534  void GetRec(void* Rec, const int& RecN=-1){
535  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} GetBf(Rec, RecLen);}
536  void PutRec(const void* Rec, const int& RecN=-1){
537  IAssert(RecAct); if (RecN!=-1){SetRecN(RecN);} PutBf(Rec, RecLen);}
538 
539  void PutCs(const TCs& Cs){PutBf(&Cs, sizeof(Cs));}
540  TCs GetCs(){TCs Cs; GetBf(&Cs, sizeof(Cs)); return Cs;}
541  void PutCh(const char& Ch){PutBf(&Ch, sizeof(Ch));}
542  void PutCh(const char& Ch, const int& Chs);
543  char GetCh(){char Ch; GetBf(&Ch, sizeof(Ch)); return Ch;}
544  void PutUCh(const uchar& UCh){PutBf(&UCh, sizeof(UCh));}
545  uchar GetUCh(){uchar UCh; GetBf(&UCh, sizeof(UCh)); return UCh;}
546  void PutInt(const int& Int){PutBf(&Int, sizeof(Int));}
547  int GetInt(){int Int; GetBf(&Int, sizeof(Int)); return Int;}
548  void PutUInt(const uint& UInt){PutBf(&UInt, sizeof(UInt));}
549  uint GetUInt(){uint UInt; GetBf(&UInt, sizeof(UInt)); return UInt;}
550  void PutStr(const TStr& Str);
551  TStr GetStr(const int& StrLen);
552  TStr GetStr(const int& MxStrLen, bool& IsOk);
553  void PutSIn(const PSIn& SIn, TCs& Cs);
554  PSIn GetSIn(const int& SInLen, TCs& Cs);
555 
556  static TStr GetStrFromFAccess(const TFAccess& FAccess);
557  static TFAccess GetFAccessFromStr(const TStr& Str);
558 };
559 
561 // Files
562 class TFile{
563 public:
564  static const TStr TxtFExt;
565  static const TStr HtmlFExt;
566  static const TStr HtmFExt;
567  static const TStr GifFExt;
568  static const TStr JarFExt;
569 public:
570  static bool Exists(const TStr& FNm);
571  static void Copy(const TStr& SrcFNm, const TStr& DstFNm,
572  const bool& ThrowExceptP=true, const bool& FailIfExistsP=false);
573  static void Del(const TStr& FNm, const bool& ThrowExceptP=true);
574  static void DelWc(const TStr& WcStr, const bool& RecurseDirP=false);
575  static void Rename(const TStr& SrcFNm, const TStr& DstFNm);
576  static TStr GetUniqueFNm(const TStr& FNm);
577  static uint64 GetSize(const TStr& FNm);
578  static uint64 GetCreateTm(const TStr& FNm);
579  static uint64 GetLastAccessTm(const TStr& FNm);
580  static uint64 GetLastWriteTm(const TStr& FNm);
581 };
582 
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:594
int Val
Definition: fl.h:14
void Reset()
Definition: fl.h:409
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:420
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:473
Definition: fl.h:479
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:1060
static bool Exists(const TStr &FNm)
Definition: fl.cpp:941
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 &)
char PeekCh()
Definition: fl.h:367
PSIn SIn
Definition: fl.h:459
static const TStr GifFExt
Definition: fl.h:567
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:636
unsigned int uint
Definition: bd.h:11
#define SEEK_CUR
Definition: fl.cpp:753
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
Definition: fl.cpp:666
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:562
#define Fail
Definition: bd.h:238
void PutInt(const int &Int)
Definition: fl.h:546
int FindEol(int &BfN, bool &CrEnd)
Definition: fl.cpp:367
int PutCh(const char &Ch)
Definition: fl.h:433
void Save(const void *Bf, const TSize &BfL)
Definition: fl.h:189
bool IsEolnLn() const
Definition: fl.cpp:700
uchar GetUCh()
Definition: fl.h:545
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:536
void MkEolnLn()
Definition: fl.cpp:732
void CutBf(const int &CutBfL)
Definition: fl.cpp:660
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:755
int Len() const
Definition: fl.h:405
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:565
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:686
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:446
void Save(const int64 &Int)
Definition: fl.h:180
char PeekCh()
Definition: fl.cpp:589
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:602
void PutUInt(const uint &UInt)
Definition: fl.h:548
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:428
~TFInOut()
Definition: fl.h:359
TStr GetAsStr() const
Definition: fl.cpp:654
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:412
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:543
#define ClassTP(TNm, PNm)
Definition: bd.h:126
void PutCs(const TCs &Cs)
Definition: fl.h:539
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
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:532
static const int MxMask
Definition: fl.h:13
static const TStr TxtFExt
Definition: fl.h:564
static TPt< TSIn > New()
Definition: fl.h:246
char Ch
Definition: fl.h:461
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:1049
Definition: fl.h:347
static TStr GetUniqueFNm(const TStr &FNm)
Definition: fl.cpp:1066
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:224
virtual bool Eof()=0
TSInOut()
Definition: fl.h:225
int BfC
Definition: fl.h:387
virtual TFileId GetFileId() const
Definition: fl.h:146
void Load(sdouble &SFlt)
Definition: fl.h:94
static const TStr HtmFExt
Definition: fl.h:566
TFIn & operator=(const TFIn &)
unsigned long long uint64
Definition: bd.h:38
void GetHd(void *Hd)
Definition: fl.h:530
char EofCh
Definition: fl.h:460
TLnRet(const PSIn &_SIn)
Definition: fl.h:484
void Load(bool &Bool)
Definition: fl.h:84
bool Eof() const
Definition: fl.h:470
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
static PSIn New(const void *_Bf, const int &_BfL, const bool &TakeBf=false)
Definition: fl.cpp:568
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:1039
Definition: fl.h:347
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:642
int PutSep(const int &NextStrLen=0)
Definition: fl.cpp:170
void SetHdRecLen(const int &_HdLen, const int &_RecLen)
Definition: fl.h:512
int PutInt(const int &Int)
Definition: fl.cpp:93
bool Eof()
Definition: fl.h:298
int MxBfL
Definition: fl.h:420
TSIn & operator>>(short &Sh)
Definition: fl.h:103
TSOut & operator<<(TSOut &(*FuncPt)(TSOut &))
Definition: fl.h:204
Definition: fl.h:220
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:547
TFileId FileId
Definition: fl.h:351
Definition: fl.h:491
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:541
static const TPt< TSOut > StdOut
Definition: fl.h:208
Definition: fl.h:128
TChRet(const PSIn &_SIn, const char &_EofCh=0)
Definition: fl.h:467
bool OwnBf
Definition: fl.h:421
TCs GetCs()
Definition: fl.h:540
int PutIndent(const int &IndentLev=1)
Definition: fl.cpp:154
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
int BfC
Definition: fl.h:280
Definition: fl.h:417
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
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:534
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
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:440
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:471
bool Eof()
Definition: fl.h:404
int BfL
Definition: fl.h:387
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:481
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:437
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
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:610
bool IsCrLfLn() const
Definition: fl.cpp:680
TSize BfL
Definition: fl.h:324
char * Bf
Definition: fl.h:419
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:441
int Len() const
Definition: fl.h:439
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:520
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.h:402
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:544
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:707
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:549
TSOut & operator<<(const int &Int)
Definition: fl.h:196
TSIn & operator>>(int64 &Int)
Definition: fl.h:107
char GetCh()
Definition: fl.cpp:584
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:519
Definition: fl.h:457
static const TStr JarFExt
Definition: fl.h:568
bool NextLn(TStr &LnStr)
Definition: fl.cpp:740
~TMOut()
Definition: fl.h:431
bool GetNextLn(TStr &LnStr)
Definition: fl.cpp:43
static uint64 GetLastAccessTm(const TStr &FNm)
TSIn & operator>>(ushort &USh)
Definition: fl.h:104