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