SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
ss.h
Go to the documentation of this file.
1 #include "bd.h"
2 
3 //#//////////////////////////////////////////////
5 typedef enum {ssfUndef,
13 
14 //#//////////////////////////////////////////////
16 
19 private:
20  TVec<PStrV> CellStrVV;
21 public:
22  TSs(): CellStrVV(){}
23  static PSs New(){return PSs(new TSs());}
24  ~TSs(){}
25  TSs(TSIn& SIn): CellStrVV(SIn){}
26  static PSs Load(TSIn& SIn){return new TSs(SIn);}
27  void Save(TSOut& SOut){CellStrVV.Save(SOut);}
28 
29  TSs& operator=(const TSs& Ss){
30  if (this!=&Ss){CellStrVV=Ss.CellStrVV;} return *this;}
31 
32  // values
33  TStr& At(const int& X, const int& Y);
34  void PutVal(const int& X, const int& Y, const TStr& Str);
35  TStr GetVal(const int& X, const int& Y) const;
36 
37  // row & column
38  int GetXLen() const;
39  int GetXLen(const int& Y) const;
40  int GetYLen() const;
41  void DelX(const int& X);
42  void DelY(const int& Y);
43  int SearchX(const int& Y, const TStr& Str) const;
44  int SearchY(const int& X, const TStr& Str) const;
45 
46  // fields
47  int GetFlds() const {return GetXLen(0);}
48  int GetFldX(const TStr& FldNm, const TStr& NewFldNm="", const int& Y=0) const;
49  int GetFldY(const TStr& FldNm, const TStr& NewFldNm="", const int& X=0) const;
50  TStr GetFldNm(const int& FldX) const {return GetVal(FldX, 0);}
51 
52  // files
53  static PSs LoadTxt(
54  const TSsFmt& SsFmt, const TStr& FNm,
55  const PNotify& Notify=NULL, const bool& IsExcelEoln=true,
56  const int& MxY=-1, const TIntV& AllowedColNV=TIntV(), const bool& IsQStr=true);
57  void SaveTxt(const TStr& FNm, const PNotify& Notify=NULL) const;
58  static void LoadTxtFldV(
59  const TSsFmt& SsFmt, const PSIn& SIn, char& Ch,
60  TStrV& FldValV, const bool& IsExcelEoln=true, const bool& IsQStr=true);
61 
62  // format
63  static TSsFmt GetSsFmtFromStr(const TStr& SsFmtNm);
64  static TStr GetStrFromSsFmt(const TSsFmt& SsFmt);
65  static TStr GetSsFmtNmVStr();
66 };
67 
68 //#//////////////////////////////////////////////
70 
73 private:
74  TSsFmt SsFmt;
75  bool SkipLeadBlanks;
76  bool SkipCmt;
77  bool SkipEmptyFld;
78  uint64 LineCnt;
79  char SplitCh;
80  TChA LineStr;
81  TVec<char*> FldV;
82  PSIn FInPt;
84 public:
86 
92  TSsParser(const TStr& FNm, const TSsFmt _SsFmt=ssfTabSep, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false);
94 
100  TSsParser(const TStr& FNm, const char& Separator, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false);
101  ~TSsParser();
102  static PSsParser New(const TStr& FNm, const TSsFmt SsFmt) { return new TSsParser(FNm, SsFmt); }
103 
105 
107  bool Next();
109 
112  bool NextSlow();
114  int Len() const { return FldV.Len(); }
116  int GetFlds() const { return Len(); }
118  uint64 GetLineNo() const { return LineCnt; }
120  bool IsCmt() const { return Len()>0 && GetFld(0)[0] == '#'; }
122  bool Eof() const { return FInPt->Eof(); }
124  TChA GetLnStr() const { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } if (LnOut.Len() > 0) LnOut.DelLastCh(); return LnOut; }
126  void ToLc();
127 
129  const char* GetFld(const int& FldN) const { return FldV[FldN]; }
131  char* GetFld(const int& FldN) { return FldV[FldN]; }
133  const char* operator [] (const int& FldN) const { return FldV[FldN]; }
135  char* operator [] (const int& FldN) { return FldV[FldN]; }
136 
138  bool GetInt(const int& FldN, int& Val) const;
140  int GetInt(const int& FldN) const {
141  int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }
143  bool IsInt(const int& FldN) const { int v; return GetInt(FldN, v); }
144 
146  bool GetFlt(const int& FldN, double& Val) const;
148  bool IsFlt(const int& FldN) const { double v; return GetFlt(FldN, v); }
150  double GetFlt(const int& FldN) const { double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
151 
153  bool GetUInt64(const int& FldN, uint64& Val) const;
155  bool IsUInt64(const int& FldN) const { uint64 v; return GetUInt64(FldN, v); }
157  uint64 GetUInt64(const int& FldN) const { uint64 Val=0; IAssert(GetUInt64(FldN, Val)); return Val; }
158 
159  const char* DumpStr() const;
160 };
161 
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
#define UndefDefaultCopyAssign(TNm)
Definition: bd.h:203
~TSs()
Definition: ss.h:24
Definition: ss.h:72
int Len() const
Definition: dt.h:259
void Save(TSOut &SOut)
Definition: ss.h:27
Semicolon separated.
Definition: ss.h:8
TChA GetLnStr() const
Returns the current line.
Definition: ss.h:124
Vertical bar separated.
Definition: ss.h:9
Definition: ss.h:12
int GetFlds() const
Returns the number of fields in the current line.
Definition: ss.h:116
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
Definition: ss.h:129
double GetFlt(const int &FldN) const
Assumes FldN is a floating point number its value is returned. If FldN is not an integer an exception...
Definition: ss.h:150
Definition: fl.h:58
TSsFmt
Spread-Sheet Separator Format.
Definition: ss.h:5
static PSs New()
Definition: ss.h:23
#define ClassTP(TNm, PNm)
Definition: bd.h:126
void DelLastCh()
Definition: dt.h:263
bool IsUInt64(const int &FldN) const
Checks whether fields FldN is unsigned 64-bit integer number.
Definition: ss.h:155
bool Eof() const
Checks for end of file.
Definition: ss.h:122
unsigned long long uint64
Definition: bd.h:38
TStr GetFldNm(const int &FldX) const
Definition: ss.h:50
Whitespace (space or tab) separated.
Definition: ss.h:11
Tab separated.
Definition: ss.h:6
int Len() const
Returns the number of fields in the current line.
Definition: ss.h:114
Definition: fl.h:128
int GetInt(const int &FldN) const
Assumes FldN is an integer its value is returned. If FldN is not an integer an exception is thrown...
Definition: ss.h:140
Space separated.
Definition: ss.h:10
uint64 GetUInt64(const int &FldN) const
Assumes FldN is a 64-bit unsigned integer point number its value is returned. If FldN is not a 64-bit...
Definition: ss.h:157
Definition: dt.h:201
TVec< PStrV > CellStrVV
Definition: ss.h:20
TSs(TSIn &SIn)
Definition: ss.h:25
Definition: dt.h:412
int GetFlds() const
Definition: ss.h:47
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
uint64 GetLineNo() const
Returns the line number of the current line.
Definition: ss.h:118
TPt< TSs > PSs
Definition: ss.h:18
TVec< TInt > TIntV
Definition: ds.h:1594
Definition: bd.h:196
static PSs Load(TSIn &SIn)
Definition: ss.h:26
char * GetFld(const int &FldN)
Returns the contents of the field at index FldN.
Definition: ss.h:131
bool IsInt(const int &FldN) const
Checks whether fields FldN is an integer.
Definition: ss.h:143
Definition: ss.h:18
Definition: ss.h:5
bool IsCmt() const
Checks whether the current line is a comment (starts with '#').
Definition: ss.h:120
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430
TSs & operator=(const TSs &Ss)
Definition: ss.h:29
Comma separated.
Definition: ss.h:7
bool IsFlt(const int &FldN) const
Checks whether fields FldN is a float.
Definition: ss.h:148