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
ss.h
Go to the documentation of this file.
00001 #include "bd.h"
00002 
00003 //#//////////////////////////////////////////////
00005 typedef enum {ssfUndef,
00006   ssfTabSep,       
00007   ssfCommaSep,     
00008   ssfSemicolonSep, 
00009   ssfVBar,         
00010   ssfSpaceSep,     
00011   ssfWhiteSep,     
00012   ssfMx} TSsFmt;
00013 
00014 //#//////////////////////////////////////////////
00016 
00018 ClassTP(TSs, PSs)//{
00019 private:
00020   TVec<PStrV> CellStrVV;
00021 public:
00022   TSs(): CellStrVV(){}
00023   static PSs New(){return PSs(new TSs());}
00024   ~TSs(){}
00025   TSs(TSIn& SIn): CellStrVV(SIn){}
00026   static PSs Load(TSIn& SIn){return new TSs(SIn);}
00027   void Save(TSOut& SOut){CellStrVV.Save(SOut);}
00028 
00029   TSs& operator=(const TSs& Ss){
00030     if (this!=&Ss){CellStrVV=Ss.CellStrVV;} return *this;}
00031 
00032   // values
00033   TStr& At(const int& X, const int& Y);
00034   void PutVal(const int& X, const int& Y, const TStr& Str);
00035   TStr GetVal(const int& X, const int& Y) const;
00036 
00037   // row & column
00038   int GetXLen() const;
00039   int GetXLen(const int& Y) const;
00040   int GetYLen() const;
00041   void DelX(const int& X);
00042   void DelY(const int& Y);
00043   int SearchX(const int& Y, const TStr& Str) const;
00044   int SearchY(const int& X, const TStr& Str) const;
00045 
00046   // fields
00047   int GetFlds() const {return GetXLen(0);}
00048   int GetFldX(const TStr& FldNm, const TStr& NewFldNm="", const int& Y=0) const;
00049   int GetFldY(const TStr& FldNm, const TStr& NewFldNm="", const int& X=0) const;
00050   TStr GetFldNm(const int& FldX) const {return GetVal(FldX, 0);}
00051 
00052   // files
00053   static PSs LoadTxt(
00054    const TSsFmt& SsFmt, const TStr& FNm,
00055    const PNotify& Notify=NULL, const bool& IsExcelEoln=true,
00056    const int& MxY=-1, const TIntV& AllowedColNV=TIntV(), const bool& IsQStr=true);
00057   void SaveTxt(const TStr& FNm, const PNotify& Notify=NULL) const;
00058   static void LoadTxtFldV(
00059    const TSsFmt& SsFmt, const PSIn& SIn, char& Ch,
00060    TStrV& FldValV, const bool& IsExcelEoln=true, const bool& IsQStr=true);
00061 
00062   // format
00063   static TSsFmt GetSsFmtFromStr(const TStr& SsFmtNm);
00064   static TStr GetStrFromSsFmt(const TSsFmt& SsFmt);
00065   static TStr GetSsFmtNmVStr();
00066 };
00067 
00068 //#//////////////////////////////////////////////
00070 
00072 ClassTP(TSsParser, PSsParser)//{
00073 private:
00074   TSsFmt SsFmt;  
00075   bool SkipLeadBlanks;  
00076   bool SkipCmt;         
00077   bool SkipEmptyFld;    
00078   uint64 LineCnt;       
00079   char SplitCh;         
00080   TChA LineStr;         
00081   TVec<char*> FldV;     
00082   PSIn FInPt;           
00083   UndefDefaultCopyAssign(TSsParser);
00084 public:
00086 
00092   TSsParser(const TStr& FNm, const TSsFmt _SsFmt=ssfTabSep, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false);
00094 
00100   TSsParser(const TStr& FNm, const char& Separator, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false);
00101   ~TSsParser();
00102   static PSsParser New(const TStr& FNm, const TSsFmt SsFmt) { return new TSsParser(FNm, SsFmt); }
00103 
00105 
00107   bool Next();
00109 
00112   bool NextSlow();
00114   int Len() const { return FldV.Len(); }
00116   int GetFlds() const { return Len(); }
00118   uint64 GetLineNo() const { return LineCnt; }
00120   bool IsCmt() const { return Len()>0 && GetFld(0)[0] == '#'; }
00122   bool Eof() const { return FInPt->Eof(); }
00124   const TChA& GetLnStr() const { return LineStr; }
00126   void ToLc();
00127 
00129   const char* GetFld(const int& FldN) const { return FldV[FldN]; }
00131   char* GetFld(const int& FldN) { return FldV[FldN]; }
00133   const char* operator [] (const int& FldN) const { return FldV[FldN]; }
00135   char* operator [] (const int& FldN) { return FldV[FldN]; }
00137   bool GetInt(const int& FldN, int& Val) const;
00139   int GetInt(const int& FldN) const {
00140     int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }
00142   bool IsInt(const int& FldN) const { int v; return GetInt(FldN, v); }
00144   bool GetFlt(const int& FldN, double& Val) const;
00146   bool IsFlt(const int& FldN) const { double v; return GetFlt(FldN, v); }
00148   double GetFlt(const int& FldN) const {
00149     double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
00150 
00151   const char* DumpStr() const;
00152 };