SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
zipfl.h
Go to the documentation of this file.
00001 #ifndef zipfl_h
00002 #define zipfl_h
00003 
00004 //#//////////////////////////////////////////////
00012 class TZipIn : public TSIn {
00013 private:
00014   static TStrStrH FExtToCmdH;
00015   static const int MxBfL;
00016   #ifdef GLib_WIN
00017     HANDLE ZipStdoutRd, ZipStdoutWr;
00018   #else 
00019     FILE* ZipStdoutRd, *ZipStdoutWr;
00020   #endif
00021   uint64 FLen, CurFPos;
00022   char* Bf;
00023   int BfC, BfL;
00024 private:
00025   void FillBf();
00026   int FindEol(int& BfN);
00027   void CreateZipProcess(const TStr& Cmd, const TStr& ZipFNm);
00028   static void FillFExtToCmdH();
00029 private:
00030   TZipIn();
00031   TZipIn(const TZipIn&);
00032   TZipIn& operator=(const TZipIn&);
00033 public:
00034   TZipIn(const TStr& FNm);
00035   TZipIn(const TStr& FNm, bool& OpenedP);
00036   static PSIn New(const TStr& FNm);
00037   static PSIn New(const TStr& FNm, bool& OpenedP);
00038   ~TZipIn();
00039 
00040   bool Eof() { return CurFPos==FLen && BfC==BfL; }
00041   int Len() const { return int(FLen-CurFPos+BfL-BfC); }
00042   char GetCh() { if (BfC==BfL){FillBf();} return Bf[BfC++]; }
00043   char PeekCh() { if (BfC==BfL){FillBf();} return Bf[BfC]; }
00044   int GetBf(const void* LBf, const TSize& LBfL);
00045   bool GetNextLnBf(TChA& LnChA);
00046 
00047   uint64 GetFLen() const { return FLen; }
00048   uint64 GetCurFPos() const { return CurFPos; }
00049 
00051   static bool IsZipFNm(const TStr& FNm) { return IsZipExt(FNm.GetFExt()); }
00053   static bool IsZipExt(const TStr& FNmExt);
00055   static TStr GetCmd(const TStr& ZipFNm);
00057   static uint64 GetFLen(const TStr& ZipFNm);
00058   static PSIn NewIfZip(const TStr& FNm) { return IsZipFNm(FNm) ? New(FNm) : TFIn::New(FNm); }
00059 };
00060 
00061 //#//////////////////////////////////////////////
00068 class TZipOut : public TSOut{
00069 private:
00070   static const TSize MxBfL;
00071   static TStrStrH FExtToCmdH;
00072   #ifdef GLib_WIN
00073     HANDLE ZipStdinRd, ZipStdinWr;
00074   #else 
00075     FILE *ZipStdinRd, *ZipStdinWr;
00076   #endif
00077   char* Bf;
00078   TSize BfL;
00079 private:
00080   void FlushBf();
00081   void CreateZipProcess(const TStr& Cmd, const TStr& ZipFNm);
00082   static void FillFExtToCmdH();
00083 private:
00084   TZipOut();
00085   TZipOut(const TZipOut&);
00086   TZipOut& operator=(const TZipOut&);
00087 public:
00088   TZipOut(const TStr& _FNm);
00089   static PSOut New(const TStr& FNm);
00090   ~TZipOut();
00091 
00092   int PutCh(const char& Ch);
00093   int PutBf(const void* LBf, const TSize& LBfL);
00094   void Flush();
00095 
00097   static bool IsZipFNm(const TStr& FNm) { return IsZipExt(FNm.GetFExt()); }
00099   static bool IsZipExt(const TStr& FNmExt);
00101   static TStr GetCmd(const TStr& ZipFNm);
00102   static PSOut NewIfZip(const TStr& FNm) { return IsZipFNm(FNm) ? New(FNm) : TFOut::New(FNm); }
00103 };
00104 
00105 #endif