SNAP Library, Developer Reference
2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
|
00001 00002 // Spread-Sheet 00003 typedef enum {ssfUndef, 00004 ssfTabSep, ssfCommaSep, ssfSemicolonSep, ssfVBar, ssfSpaceSep, ssfWhiteSep, ssfMx} TSsFmt; 00005 00006 ClassTP(TSs, PSs)//{ 00007 private: 00008 TVec<PStrV> CellStrVV; 00009 public: 00010 TSs(): CellStrVV(){} 00011 static PSs New(){return PSs(new TSs());} 00012 ~TSs(){} 00013 TSs(TSIn& SIn): CellStrVV(SIn){} 00014 static PSs Load(TSIn& SIn){return new TSs(SIn);} 00015 void Save(TSOut& SOut){CellStrVV.Save(SOut);} 00016 00017 TSs& operator=(const TSs& Ss){ 00018 if (this!=&Ss){CellStrVV=Ss.CellStrVV;} return *this;} 00019 00020 // values 00021 TStr& At(const int& X, const int& Y); 00022 void PutVal(const int& X, const int& Y, const TStr& Str); 00023 TStr GetVal(const int& X, const int& Y) const; 00024 00025 // row & column 00026 int GetXLen() const; 00027 int GetXLen(const int& Y) const; 00028 int GetYLen() const; 00029 void DelX(const int& X); 00030 void DelY(const int& Y); 00031 int SearchX(const int& Y, const TStr& Str) const; 00032 int SearchY(const int& X, const TStr& Str) const; 00033 00034 // fields 00035 int GetFlds() const {return GetXLen(0);} 00036 int GetFldX(const TStr& FldNm, const TStr& NewFldNm="", const int& Y=0) const; 00037 int GetFldY(const TStr& FldNm, const TStr& NewFldNm="", const int& X=0) const; 00038 TStr GetFldNm(const int& FldX) const {return GetVal(FldX, 0);} 00039 00040 // files 00041 static PSs LoadTxt( 00042 const TSsFmt& SsFmt, const TStr& FNm, 00043 const PNotify& Notify=NULL, const bool& IsExcelEoln=true, 00044 const int& MxY=-1, const TIntV& AllowedColNV=TIntV(), const bool& IsQStr=true); 00045 void SaveTxt(const TStr& FNm, const PNotify& Notify=NULL) const; 00046 static void LoadTxtFldV( 00047 const TSsFmt& SsFmt, const PSIn& SIn, char& Ch, 00048 TStrV& FldValV, const bool& IsExcelEoln=true, const bool& IsQStr=true); 00049 00050 // format 00051 static TSsFmt GetSsFmtFromStr(const TStr& SsFmtNm); 00052 static TStr GetStrFromSsFmt(const TSsFmt& SsFmt); 00053 static TStr GetSsFmtNmVStr(); 00054 }; 00055 00058 ClassTP(TSsParser, PSsParser)//{ 00059 private: 00060 TSsFmt SsFmt; 00061 bool SkipLeadBlanks, SkipCmt, SkipEmptyFld; // skip emptry fields 00062 uint64 LineCnt; 00063 char SplitCh; 00064 TChA LineStr; 00065 TVec<char*> FldV; 00066 PSIn FInPt; 00067 UndefDefaultCopyAssign(TSsParser); 00068 public: 00069 TSsParser(const TStr& FNm, const TSsFmt _SsFmt=ssfTabSep, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false); 00070 TSsParser(const TStr& FNm, const char& Separator, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false); 00071 ~TSsParser(); 00072 static PSsParser New(const TStr& FNm, const TSsFmt SsFmt) { return new TSsParser(FNm, SsFmt); } 00073 00074 bool Next(); 00075 int Len() const { return FldV.Len(); } 00076 int GetFlds() const { return Len(); } 00077 uint64 GetLineNo() const { return LineCnt; } 00078 bool IsCmt() const { return Len()>0 && GetFld(0)[0] == '#'; } 00079 bool Eof() const { return FInPt->Eof(); } 00080 const TChA& GetLnStr() const { return LineStr; } 00081 void ToLc(); 00082 00083 const char* GetFld(const int& FldN) const { return FldV[FldN]; } 00084 char* GetFld(const int& FldN) { return FldV[FldN]; } 00085 const char* operator [] (const int& FldN) const { return FldV[FldN]; } 00086 char* operator [] (const int& FldN) { return FldV[FldN]; } 00087 bool GetInt(const int& FldN, int& Val) const; 00088 int GetInt(const int& FldN) const { 00089 int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; } 00090 bool IsInt(const int& FldN) const { int v; return GetInt(FldN, v); } 00091 bool GetFlt(const int& FldN, double& Val) const; 00092 bool IsFlt(const int& FldN) const { double v; return GetFlt(FldN, v); } 00093 double GetFlt(const int& FldN) const { 00094 double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; } 00095 00096 const char* DumpStr() const; 00097 }; 00098