SNAP Library 2.4, Developer Reference  2015-05-11 19:40:56
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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+=' '; } 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]; }
137  bool GetInt(const int& FldN, int& Val) const;
139  int GetInt(const int& FldN) const {
140  int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }
142  bool IsInt(const int& FldN) const { int v; return GetInt(FldN, v); }
144  bool GetFlt(const int& FldN, double& Val) const;
146  bool IsFlt(const int& FldN) const { double v; return GetFlt(FldN, v); }
148  double GetFlt(const int& FldN) const {
149  double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
150 
151  const char* DumpStr() const;
152 };
#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
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:148
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
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:139
Space separated.
Definition: ss.h:10
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:1482
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:142
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:420
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:146