SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
ssmp.h
Go to the documentation of this file.
1 #include "bd.h"
2 
3 //#//////////////////////////////////////////////
5 
8 private:
9  TSsFmt SsFmt;
10  bool SkipLeadBlanks;
11  bool SkipCmt;
12  bool SkipEmptyFld;
13  uint64 LineCnt;
14  char SplitCh;
15  TChA LineStr;
16  TVec<char*> FldV;
17  TPt<TMIn> FInPt;
19 public:
21 
27  TSsParserMP(const TStr& FNm, const TSsFmt _SsFmt=ssfTabSep, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false);
29 
35  TSsParserMP(const TStr& FNm, const char& Separator, const bool& _SkipLeadBlanks=false, const bool& _SkipCmt=true, const bool& _SkipEmptyFld=false);
36  ~TSsParserMP();
37  static PSsParserMP New(const TStr& FNm, const TSsFmt SsFmt) { return new TSsParserMP(FNm, SsFmt); }
38 
40 
42  bool Next();
44 
47  bool NextSlow();
49  int Len() const { return FldV.Len(); }
51  int GetFlds() const { return Len(); }
53  uint64 GetLineNo() const { return LineCnt; }
55  bool IsCmt() const { return Len()>0 && GetFld(0)[0] == '#'; }
57  void SkipCommentLines();
59  bool Eof() const { return FInPt->Eof(); }
61  TChA GetLnStr() const { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } if (LnOut.Len() > 0) LnOut.DelLastCh(); return LnOut; }
63  void ToLc();
64 
66  const char* GetFld(const int& FldN) const { return FldV[FldN]; }
68  char* GetFld(const int& FldN) { return FldV[FldN]; }
70  const char* operator [] (const int& FldN) const { return FldV[FldN]; }
72  char* operator [] (const int& FldN) { return FldV[FldN]; }
74  bool GetInt(const int& FldN, int& Val) const;
76  int GetInt(const int& FldN) const {
77  int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }
79  bool IsInt(const int& FldN) const { int v; return GetInt(FldN, v); }
81  bool GetFlt(const int& FldN, double& Val) const;
83  bool IsFlt(const int& FldN) const { double v; return GetFlt(FldN, v); }
85  double GetFlt(const int& FldN) const {
86  double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
87 
89  uint64 GetStreamPos() const {
90  return FInPt->GetBfC(); }
91 
93  uint64 GetStreamLen() const {
94  return FInPt->GetBfL(); }
95 
97  void SetStreamPos(uint64 Pos) {
98  return FInPt->SetBfC(Pos); }
99 
101  uint64 CountNewLinesInRange(uint64 Lb, uint64 Ub) const;
102 
104  TVec<uint64> GetStartPosV(uint64 Lb, uint64 Ub) const;
105 
107  void NextFromIndex(uint64 Index, TVec<char*>& FieldsV);
108 
110  int GetIntFromFldV(TVec<char*>& FieldsV, const int& FldN);
111 
113  double GetFltFromFldV(TVec<char*>& FieldsV, const int& FldN);
114 
115  const char* DumpStr() const;
116 };
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
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: ssmp.h:76
#define UndefDefaultCopyAssign(TNm)
Definition: bd.h:203
char * GetFld(const int &FldN)
Returns the contents of the field at index FldN.
Definition: ssmp.h:68
uint64 GetLineNo() const
Returns the line number of the current line.
Definition: ssmp.h:53
int GetFlds() const
Returns the number of fields in the current line.
Definition: ssmp.h:51
int Len() const
Returns the number of fields in the current line.
Definition: ssmp.h:49
uint64 GetStreamPos() const
Returns position of stream pointer.
Definition: ssmp.h:89
int Len() const
Definition: dt.h:259
bool IsFlt(const int &FldN) const
Checks whether fields FldN is a float.
Definition: ssmp.h:83
bool IsInt(const int &FldN) const
Checks whether fields FldN is an integer.
Definition: ssmp.h:79
Definition: fl.h:437
TSsFmt
Spread-Sheet Separator Format.
Definition: ss.h:5
#define ClassTP(TNm, PNm)
Definition: bd.h:126
void DelLastCh()
Definition: dt.h:263
unsigned long long uint64
Definition: bd.h:38
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
Definition: ssmp.h:66
Tab separated.
Definition: ss.h:6
bool Eof() const
Checks for end of file.
Definition: ssmp.h:59
TChA GetLnStr() const
Returns the current line.
Definition: ssmp.h:61
Definition: dt.h:201
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
void SetStreamPos(uint64 Pos)
Sets position of stream pointer.
Definition: ssmp.h:97
Definition: bd.h:196
bool IsCmt() const
Checks whether the current line is a comment (starts with '#').
Definition: ssmp.h:55
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: ssmp.h:85
uint64 GetStreamLen() const
Returns length of stream.
Definition: ssmp.h:93
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430