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
TSsParserMP Class Reference

#include <ssmp.h>

Collaboration diagram for TSsParserMP:

Public Member Functions

 TSsParserMP (const TStr &FNm, const TSsFmt _SsFmt=ssfTabSep, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false)
 Constructor. More...
 
 TSsParserMP (const TStr &FNm, const char &Separator, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false)
 Constructor. More...
 
 ~TSsParserMP ()
 
bool Next ()
 Loads next line from the input file. More...
 
bool NextSlow ()
 Loads next line from the input file (older, slow implementation - deprecated). More...
 
int Len () const
 Returns the number of fields in the current line. More...
 
int GetFlds () const
 Returns the number of fields in the current line. More...
 
uint64 GetLineNo () const
 Returns the line number of the current line. More...
 
bool IsCmt () const
 Checks whether the current line is a comment (starts with '#'). More...
 
void SkipCommentLines ()
 Skips lines that begin with a comment character. More...
 
bool Eof () const
 Checks for end of file. More...
 
TChA GetLnStr () const
 Returns the current line. More...
 
void ToLc ()
 Transforms the current line to lower case. More...
 
const char * GetFld (const int &FldN) const
 Returns the contents of the field at index FldN. More...
 
char * GetFld (const int &FldN)
 Returns the contents of the field at index FldN. More...
 
const char * operator[] (const int &FldN) const
 Returns the contents of the field at index FldN. More...
 
char * operator[] (const int &FldN)
 Returns the contents of the field at index FldN. More...
 
bool GetInt (const int &FldN, int &Val) const
 If the field FldN is an integer its value is returned in Val and the function returns true. More...
 
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. More...
 
bool IsInt (const int &FldN) const
 Checks whether fields FldN is an integer. More...
 
bool GetFlt (const int &FldN, double &Val) const
 If the field FldN is a float its value is returned in Val and the function returns true. More...
 
bool IsFlt (const int &FldN) const
 Checks whether fields FldN is a float. More...
 
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 is thrown. More...
 
uint64 GetStreamPos () const
 Returns position of stream pointer. More...
 
uint64 GetStreamLen () const
 Returns length of stream. More...
 
void SetStreamPos (uint64 Pos)
 Sets position of stream pointer. More...
 
uint64 CountNewLinesInRange (uint64 Lb, uint64 Ub) const
 Counts number of occurences of '
' in [Lb, Ub) More...
 
TVec< uint64GetStartPosV (uint64 Lb, uint64 Ub) const
 Finds start positions of all lines ending somewhere in [Lb, Ub) More...
 
void NextFromIndex (uint64 Index, TVec< char * > &FieldsV)
 Loads next line starting from a given position. More...
 
int GetIntFromFldV (TVec< char * > &FieldsV, const int &FldN)
 Gets integer at field FldN. More...
 
double GetFltFromFldV (TVec< char * > &FieldsV, const int &FldN)
 Gets float at field FldN. More...
 
const char * DumpStr () const
 

Static Public Member Functions

static PSsParserMP New (const TStr &FNm, const TSsFmt SsFmt)
 

Private Member Functions

 UndefDefaultCopyAssign (TSsParserMP)
 

Private Attributes

TCRef CRef
 
TSsFmt SsFmt
 Separator type. More...
 
bool SkipLeadBlanks
 Ignore leading whitespace characters in a line. More...
 
bool SkipCmt
 Skip comments (lines starting with #). More...
 
bool SkipEmptyFld
 Skip empty fields (i.e., multiple consecutive separators are considered as one). More...
 
uint64 LineCnt
 Number of processed lines so far. More...
 
char SplitCh
 Separator character (if one of the non-started separators is used) More...
 
TChA LineStr
 Current line. More...
 
TVec< char * > FldV
 Pointers to fields of the current line. More...
 
TPt< TMInFInPt
 Pointer to the input file stream. More...
 

Friends

class TPt< TSsParserMP >
 

Detailed Description

Definition at line 7 of file ssmp.h.

Constructor & Destructor Documentation

TSsParserMP::TSsParserMP ( const TStr FNm,
const TSsFmt  _SsFmt = ssfTabSep,
const bool &  _SkipLeadBlanks = false,
const bool &  _SkipCmt = true,
const bool &  _SkipEmptyFld = false 
)

Constructor.

Parameters
FNmInput filename. Can be a text file or a compressed file.
_SsFmtSpread-sheet separator format. Each line will be broken in a set of fields, where the boundary between the fields is defined by the _SsFmt.
_SkipLeadBlanksIf true leading/trailing white-spaces of the line will be ignored.
_SkipCmtIf true lines starting with '#' will be considered as comments and will be skipped.
_SkipEmptyFldIf true then empty fields (consecutive occurrences of the separator) will be ignored.
TSsParserMP::TSsParserMP ( const TStr FNm,
const char &  Separator,
const bool &  _SkipLeadBlanks = false,
const bool &  _SkipCmt = true,
const bool &  _SkipEmptyFld = false 
)

Constructor.

Parameters
FNmInput filename. Can be a text file or a compressed file.
SeparatorSpread-sheet separator character. Each line will be broken in a set of fields, where the boundary between the fields is the Separator character.
_SkipLeadBlanksIf true leading/trailing white-spaces of the line will be ignored.
_SkipCmtIf true lines starting with '#' will be considered as comments and will be skipped.
_SkipEmptyFldIf true then empty fields (consecutive occurrences of the separator) will be ignored.

Definition at line 3 of file ssmp.cpp.

References FInPt, TMIn::New(), and SplitCh.

3  : SsFmt(ssfSpaceSep),
4  SkipLeadBlanks(_SkipLeadBlanks), SkipCmt(_SkipCmt), SkipEmptyFld(_SkipEmptyFld), LineCnt(0), /*Bf(NULL),*/ SplitCh('\t'), LineStr(), FldV(), FInPt(NULL) {
5  FInPt = TMIn::New(FNm, true);
6  SplitCh = Separator;
7 }
TChA LineStr
Current line.
Definition: ssmp.h:15
uint64 LineCnt
Number of processed lines so far.
Definition: ssmp.h:13
bool SkipLeadBlanks
Ignore leading whitespace characters in a line.
Definition: ssmp.h:10
bool SkipEmptyFld
Skip empty fields (i.e., multiple consecutive separators are considered as one).
Definition: ssmp.h:12
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
static PSIn New(const void *_Bf, const uint64 &_BfL, const bool &TakeBf=false)
Definition: fl.cpp:668
Space separated.
Definition: ss.h:10
bool SkipCmt
Skip comments (lines starting with #).
Definition: ssmp.h:11
char SplitCh
Separator character (if one of the non-started separators is used)
Definition: ssmp.h:14
TSsFmt SsFmt
Separator type.
Definition: ssmp.h:9

Here is the call graph for this function:

TSsParserMP::~TSsParserMP ( )

Definition at line 9 of file ssmp.cpp.

9  {
10 }

Member Function Documentation

uint64 TSsParserMP::CountNewLinesInRange ( uint64  Lb,
uint64  Ub 
) const

Counts number of occurences of '
' in [Lb, Ub)

Definition at line 102 of file ssmp.cpp.

References TMIn::CountNewLinesInRange(), and FInPt.

Referenced by TTable::LoadSSPar().

102  {
103  return FInPt->CountNewLinesInRange(Lb, Ub);
104 }
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
uint64 CountNewLinesInRange(uint64 Lb, uint64 Ub)
Finds number of new line chars in interval [Lb, Ub)
Definition: fl.cpp:782

Here is the call graph for this function:

Here is the caller graph for this function:

const char * TSsParserMP::DumpStr ( ) const

Definition at line 91 of file ssmp.cpp.

References TChA::Clr(), TChA::CStr(), FldV, TStr::Fmt(), and TVec< TVal, TSizeTy >::Len().

91  {
92  static TChA ChA(10*1024);
93  ChA.Clr();
94  for (int i = 0; i < FldV.Len(); i++) {
95  ChA += TStr::Fmt(" %d: '%s'\n", i, FldV[i]);
96  }
97  return ChA.CStr();
98 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
Definition: dt.h:201
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599

Here is the call graph for this function:

bool TSsParserMP::Eof ( ) const
inline

Checks for end of file.

Definition at line 59 of file ssmp.h.

59 { return FInPt->Eof(); }
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
bool Eof()
Definition: fl.h:464
const char* TSsParserMP::GetFld ( const int &  FldN) const
inline

Returns the contents of the field at index FldN.

Definition at line 66 of file ssmp.h.

Referenced by GetFlt(), and GetInt().

66 { return FldV[FldN]; }
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16

Here is the caller graph for this function:

char* TSsParserMP::GetFld ( const int &  FldN)
inline

Returns the contents of the field at index FldN.

Definition at line 68 of file ssmp.h.

68 { return FldV[FldN]; }
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
int TSsParserMP::GetFlds ( ) const
inline

Returns the number of fields in the current line.

Definition at line 51 of file ssmp.h.

Referenced by TTable::LoadSSPar().

51 { return Len(); }
int Len() const
Returns the number of fields in the current line.
Definition: ssmp.h:49

Here is the caller graph for this function:

bool TSsParserMP::GetFlt ( const int &  FldN,
double &  Val 
) const

If the field FldN is a float its value is returned in Val and the function returns true.

Definition at line 69 of file ssmp.cpp.

References GetFld(), TCh::IsNum(), and TCh::IsWs().

69  {
70  // parsing format {ws} [+/-] +{d} ([.]{d}) ([E|e] [+/-] +{d})
71  const char *c = GetFld(FldN);
72  while (TCh::IsWs(*c)) { c++; }
73  if (*c=='+' || *c=='-') { c++; }
74  if (! TCh::IsNum(*c) && *c!='.') { return false; }
75  while (TCh::IsNum(*c)) { c++; }
76  if (*c == '.') {
77  c++;
78  while (TCh::IsNum(*c)) { c++; }
79  }
80  if (*c=='e' || *c == 'E') {
81  c++;
82  if (*c == '+' || *c == '-' ) { c++; }
83  if (! TCh::IsNum(*c)) { return false; }
84  while (TCh::IsNum(*c)) { c++; }
85  }
86  if (*c != 0) { return false; }
87  Val = atof(GetFld(FldN));
88  return true;
89 }
static bool IsNum(const char &Ch)
Definition: dt.h:1067
static bool IsWs(const char &Ch)
Definition: dt.h:1063
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
Definition: ssmp.h:66

Here is the call graph for this function:

double TSsParserMP::GetFlt ( const int &  FldN) const
inline

Assumes FldN is a floating point number its value is returned. If FldN is not an integer an exception is thrown.

Definition at line 85 of file ssmp.h.

References IAssert.

85  {
86  double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
#define IAssert(Cond)
Definition: bd.h:262
bool GetFlt(const int &FldN, double &Val) const
If the field FldN is a float its value is returned in Val and the function returns true...
Definition: ssmp.cpp:69
double TSsParserMP::GetFltFromFldV ( TVec< char * > &  FieldsV,
const int &  FldN 
)

Gets float at field FldN.

Definition at line 170 of file ssmp.cpp.

References TCh::IsNum(), and TCh::IsWs().

Referenced by TTable::LoadSSPar().

170  {
171  // parsing format {ws} [+/-] +{d} ([.]{d}) ([E|e] [+/-] +{d})
172  const char *c = FieldsV[FldN];
173  /* skip whitespace at the beginning */
174  while (TCh::IsWs(*c)) { c++; }
175  /* skip the sign */
176  if (*c=='+' || *c=='-') { c++; }
177  /* error, if not a digit or '.' */
178  if (! TCh::IsNum(*c) && *c!='.') { return -1; }
179  /* skip digits */
180  while (TCh::IsNum(*c)) { c++; }
181  if (*c == '.') {
182  c++;
183  while (TCh::IsNum(*c)) { c++; }
184  }
185  /* skip exponent */
186  if (*c=='e' || *c == 'E') {
187  c++;
188  if (*c == '+' || *c == '-' ) { c++; }
189  if (! TCh::IsNum(*c)) { return -1; }
190  while (TCh::IsNum(*c)) { c++; }
191  }
192  if (*c != 0 && !TCh::IsWs(*c)) { return -1; }
193  return atof(FieldsV[FldN]);
194 }
static bool IsNum(const char &Ch)
Definition: dt.h:1067
static bool IsWs(const char &Ch)
Definition: dt.h:1063

Here is the call graph for this function:

Here is the caller graph for this function:

bool TSsParserMP::GetInt ( const int &  FldN,
int &  Val 
) const

If the field FldN is an integer its value is returned in Val and the function returns true.

Definition at line 50 of file ssmp.cpp.

References GetFld(), TCh::GetNum(), TCh::IsNum(), and TCh::IsWs().

50  {
51  // parsing format {ws} [+/-] +{ddd}
52  int _Val = -1;
53  bool Minus=false;
54  const char *c = GetFld(FldN);
55  while (TCh::IsWs(*c)) { c++; }
56  if (*c=='-') { Minus=true; c++; }
57  if (! TCh::IsNum(*c)) { return false; }
58  _Val = TCh::GetNum(*c); c++;
59  while (TCh::IsNum(*c)){
60  _Val = 10 * _Val + TCh::GetNum(*c);
61  c++;
62  }
63  if (Minus) { _Val = -_Val; }
64  if (*c != 0) { return false; }
65  Val = _Val;
66  return true;
67 }
static bool IsNum(const char &Ch)
Definition: dt.h:1067
static bool IsWs(const char &Ch)
Definition: dt.h:1063
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
Definition: ssmp.h:66
static int GetNum(const char &Ch)
Definition: dt.h:1069

Here is the call graph for this function:

int TSsParserMP::GetInt ( const int &  FldN) const
inline

Assumes FldN is an integer its value is returned. If FldN is not an integer an exception is thrown.

Definition at line 76 of file ssmp.h.

References TStr::Fmt(), and IAssertR.

76  {
77  int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
const char * DumpStr() const
Definition: ssmp.cpp:91
bool GetInt(const int &FldN, int &Val) const
If the field FldN is an integer its value is returned in Val and the function returns true...
Definition: ssmp.cpp:50
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599

Here is the call graph for this function:

int TSsParserMP::GetIntFromFldV ( TVec< char * > &  FieldsV,
const int &  FldN 
)

Gets integer at field FldN.

Definition at line 152 of file ssmp.cpp.

References TCh::GetNum(), TCh::IsNum(), and TCh::IsWs().

Referenced by TTable::LoadSSPar().

152  {
153  // parsing format {ws} [+/-] +{ddd}
154  int _Val = -1;
155  bool Minus=false;
156  const char *c = FieldsV[FldN];
157  while (TCh::IsWs(*c)) { c++; }
158  if (*c=='-') { Minus=true; c++; }
159  if (! TCh::IsNum(*c)) { return -1; }
160  _Val = TCh::GetNum(*c); c++;
161  while (TCh::IsNum(*c)){
162  _Val = 10 * _Val + TCh::GetNum(*c);
163  c++;
164  }
165  if (Minus) { _Val = -_Val; }
166  if (*c != 0 && !TCh::IsWs(*c)) { return -1; }
167  return _Val;
168 }
static bool IsNum(const char &Ch)
Definition: dt.h:1067
static bool IsWs(const char &Ch)
Definition: dt.h:1063
static int GetNum(const char &Ch)
Definition: dt.h:1069

Here is the call graph for this function:

Here is the caller graph for this function:

uint64 TSsParserMP::GetLineNo ( ) const
inline

Returns the line number of the current line.

Definition at line 53 of file ssmp.h.

53 { return LineCnt; }
uint64 LineCnt
Number of processed lines so far.
Definition: ssmp.h:13
TChA TSsParserMP::GetLnStr ( ) const
inline

Returns the current line.

Definition at line 61 of file ssmp.h.

References TChA::DelLastCh(), and TChA::Len().

61 { TChA LnOut; for (int i = 0; i < Len(); i++) { LnOut+=GetFld(i); LnOut+=' '; } if (LnOut.Len() > 0) LnOut.DelLastCh(); return LnOut; }
int Len() const
Returns the number of fields in the current line.
Definition: ssmp.h:49
int Len() const
Definition: dt.h:259
void DelLastCh()
Definition: dt.h:263
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
Definition: ssmp.h:66
Definition: dt.h:201

Here is the call graph for this function:

TVec< uint64 > TSsParserMP::GetStartPosV ( uint64  Lb,
uint64  Ub 
) const

Finds start positions of all lines ending somewhere in [Lb, Ub)

Definition at line 106 of file ssmp.cpp.

References TVec< TVal, TSizeTy >::Add(), FInPt, TMIn::GetLineEndPos(), TMIn::GetLineStartPos(), and GetStreamLen().

Referenced by TTable::LoadSSPar().

106  {
107  TVec<uint64> Ret;
108  if (Lb >= GetStreamLen()) {
109  return Ret;
110  }
111  while (Lb < Ub) {
112  // Find line corresponding to Lb
113  uint64 StartPos = FInPt->GetLineStartPos(Lb);
114  uint64 EndPos = FInPt->GetLineEndPos(Lb);
115 
116  // If line ends in given range, add to count
117  if (Lb <= EndPos && EndPos < Ub) {
118  Ret.Add(StartPos);
119  }
120  // Start at next line
121  Lb = EndPos + 1;
122  }
123  return Ret;
124 }
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
unsigned long long uint64
Definition: bd.h:38
uint64 GetLineEndPos(uint64 Ind)
Finds end of line in which Ind is present.
Definition: fl.cpp:802
uint64 GetLineStartPos(uint64 Ind)
Finds beginning of line in which Ind is present.
Definition: fl.cpp:795
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
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

Here is the call graph for this function:

Here is the caller graph for this function:

uint64 TSsParserMP::GetStreamLen ( ) const
inline

Returns length of stream.

Definition at line 93 of file ssmp.h.

Referenced by GetStartPosV(), and TTable::LoadSSPar().

93  {
94  return FInPt->GetBfL(); }
uint64 GetBfL()
Definition: fl.cpp:773
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17

Here is the caller graph for this function:

uint64 TSsParserMP::GetStreamPos ( ) const
inline

Returns position of stream pointer.

Definition at line 89 of file ssmp.h.

Referenced by TTable::LoadSSPar().

89  {
90  return FInPt->GetBfC(); }
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
uint64 GetBfC()
Definition: fl.cpp:769

Here is the caller graph for this function:

bool TSsParserMP::IsCmt ( ) const
inline

Checks whether the current line is a comment (starts with '#').

Definition at line 55 of file ssmp.h.

55 { return Len()>0 && GetFld(0)[0] == '#'; }
int Len() const
Returns the number of fields in the current line.
Definition: ssmp.h:49
const char * GetFld(const int &FldN) const
Returns the contents of the field at index FldN.
Definition: ssmp.h:66
bool TSsParserMP::IsFlt ( const int &  FldN) const
inline

Checks whether fields FldN is a float.

Definition at line 83 of file ssmp.h.

83 { double v; return GetFlt(FldN, v); }
bool GetFlt(const int &FldN, double &Val) const
If the field FldN is a float its value is returned in Val and the function returns true...
Definition: ssmp.cpp:69
bool TSsParserMP::IsInt ( const int &  FldN) const
inline

Checks whether fields FldN is an integer.

Definition at line 79 of file ssmp.h.

79 { int v; return GetInt(FldN, v); }
bool GetInt(const int &FldN, int &Val) const
If the field FldN is an integer its value is returned in Val and the function returns true...
Definition: ssmp.cpp:50
int TSsParserMP::Len ( ) const
inline

Returns the number of fields in the current line.

Definition at line 49 of file ssmp.h.

49 { return FldV.Len(); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
static PSsParserMP TSsParserMP::New ( const TStr FNm,
const TSsFmt  SsFmt 
)
inlinestatic

Definition at line 37 of file ssmp.h.

37 { return new TSsParserMP(FNm, SsFmt); }
TSsParserMP(const TStr &FNm, const TSsFmt _SsFmt=ssfTabSep, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false)
Constructor.
TSsFmt SsFmt
Separator type.
Definition: ssmp.h:9
bool TSsParserMP::Next ( )

Loads next line from the input file.

If end of file is reached, return value is false.

Definition at line 17 of file ssmp.cpp.

References TVec< TVal, TSizeTy >::Add(), TChA::Clr(), TVec< TVal, TSizeTy >::Clr(), TChA::CStr(), TVec< TVal, TSizeTy >::DelLast(), TChA::Empty(), TVec< TVal, TSizeTy >::Empty(), FInPt, FldV, TMIn::GetNextLnBf(), TCh::IsWs(), TVec< TVal, TSizeTy >::Last(), LineCnt, LineStr, SkipCmt, SkipEmptyFld, SkipLeadBlanks, SplitCh, SsFmt, and ssfWhiteSep.

Referenced by TTable::LoadSSPar().

17  { // split on SplitCh
18  FldV.Clr(false);
19  LineStr.Clr();
20  FldV.Clr();
21  LineCnt++;
22  if (! FInPt->GetNextLnBf(LineStr)) { return false; }
23  if (SkipCmt && !LineStr.Empty() && LineStr[0]=='#') { return Next(); }
24 
25  char* cur = LineStr.CStr();
26  if (SkipLeadBlanks) { // skip leading blanks
27  while (*cur && TCh::IsWs(*cur)) { cur++; }
28  }
29  char *last = cur;
30  while (*cur) {
31  if (SsFmt == ssfWhiteSep) { while (*cur && ! TCh::IsWs(*cur)) { cur++; } }
32  else { while (*cur && *cur!=SplitCh) { cur++; } }
33  if (*cur == 0) { break; }
34  *cur = 0; cur++;
35  FldV.Add(last); last = cur;
36  if (SkipEmptyFld && strlen(FldV.Last())==0) { FldV.DelLast(); } // skip empty fields
37  }
38  FldV.Add(last); // add last field
39  if (SkipEmptyFld && FldV.Empty()) { return Next(); } // skip empty lines
40  return true;
41 }
bool Next()
Loads next line from the input file.
Definition: ssmp.cpp:17
bool Empty() const
Definition: dt.h:260
void Clr()
Definition: dt.h:258
TChA LineStr
Current line.
Definition: ssmp.h:15
uint64 LineCnt
Number of processed lines so far.
Definition: ssmp.h:13
bool SkipLeadBlanks
Ignore leading whitespace characters in a line.
Definition: ssmp.h:10
bool SkipEmptyFld
Skip empty fields (i.e., multiple consecutive separators are considered as one).
Definition: ssmp.h:12
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:763
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
static bool IsWs(const char &Ch)
Definition: dt.h:1063
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
char * CStr()
Definition: dt.h:255
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
Whitespace (space or tab) separated.
Definition: ss.h:11
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:579
bool SkipCmt
Skip comments (lines starting with #).
Definition: ssmp.h:11
char SplitCh
Separator character (if one of the non-started separators is used)
Definition: ssmp.h:14
TSsFmt SsFmt
Separator type.
Definition: ssmp.h:9
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
void DelLast()
Removes the last element of the vector.
Definition: ds.h:665

Here is the call graph for this function:

Here is the caller graph for this function:

void TSsParserMP::NextFromIndex ( uint64  Index,
TVec< char * > &  FieldsV 
)

Loads next line starting from a given position.

Definition at line 128 of file ssmp.cpp.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), TVec< TVal, TSizeTy >::DelLast(), FInPt, TMIn::GetLine(), TCh::IsWs(), TVec< TVal, TSizeTy >::Last(), SkipEmptyFld, SkipLeadBlanks, SplitCh, SsFmt, and ssfWhiteSep.

Referenced by TTable::LoadSSPar().

129 {
130  // split on SplitCh
131  FieldsV.Clr();
132 
133  char* cur = FInPt->GetLine(Index);
134 
135  if (SkipLeadBlanks) { // skip leading blanks
136  while (*cur && TCh::IsWs(*cur)) { cur++; }
137  }
138  char *last = cur;
139  while (*cur != 0 && *cur != '\n') {
140  if (SsFmt == ssfWhiteSep) { while (*cur && (*cur != '\n') && ! TCh::IsWs(*cur)) { cur++; } }
141  else { while (*cur && *cur!=SplitCh && (*cur != '\n')) { cur++; } }
142  if (*cur == 0) { break; }
143  if (*cur == '\n') { break; }
144  //*cur = 0;
145  cur++;
146  FieldsV.Add(last); last = cur;
147  if (SkipEmptyFld && strlen(FieldsV.Last())==0) { FieldsV.DelLast(); } // skip empty fields
148  }
149  FieldsV.Add(last); // add last field
150 }
bool SkipLeadBlanks
Ignore leading whitespace characters in a line.
Definition: ssmp.h:10
bool SkipEmptyFld
Skip empty fields (i.e., multiple consecutive separators are considered as one).
Definition: ssmp.h:12
static bool IsWs(const char &Ch)
Definition: dt.h:1063
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
Whitespace (space or tab) separated.
Definition: ss.h:11
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:579
char * GetLine(uint64 Ind)
Definition: fl.cpp:810
char SplitCh
Separator character (if one of the non-started separators is used)
Definition: ssmp.h:14
TSsFmt SsFmt
Separator type.
Definition: ssmp.h:9
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
void DelLast()
Removes the last element of the vector.
Definition: ds.h:665

Here is the call graph for this function:

Here is the caller graph for this function:

bool TSsParserMP::NextSlow ( )

Loads next line from the input file (older, slow implementation - deprecated).

If end of file is reached, return value is false. This function is deprecated, use Next instead.

const char* TSsParserMP::operator[] ( const int &  FldN) const
inline

Returns the contents of the field at index FldN.

Definition at line 70 of file ssmp.h.

70 { return FldV[FldN]; }
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
char* TSsParserMP::operator[] ( const int &  FldN)
inline

Returns the contents of the field at index FldN.

Definition at line 72 of file ssmp.h.

72 { return FldV[FldN]; }
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16
void TSsParserMP::SetStreamPos ( uint64  Pos)
inline

Sets position of stream pointer.

Definition at line 97 of file ssmp.h.

Referenced by TTable::LoadSSPar().

97  {
98  return FInPt->SetBfC(Pos); }
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17
void SetBfC(uint64 Pos)
Definition: fl.cpp:777

Here is the caller graph for this function:

void TSsParserMP::SkipCommentLines ( )

Skips lines that begin with a comment character.

Definition at line 12 of file ssmp.cpp.

References FInPt, and TMIn::SkipCommentLines().

Referenced by TTable::LoadSSPar().

12  {
14 }
void SkipCommentLines()
Move stream pointer along until a non commented line is found.
Definition: fl.cpp:814
TPt< TMIn > FInPt
Pointer to the input file stream.
Definition: ssmp.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

void TSsParserMP::ToLc ( )

Transforms the current line to lower case.

Definition at line 43 of file ssmp.cpp.

References FldV, and TVec< TVal, TSizeTy >::Len().

43  {
44  for (int f = 0; f < FldV.Len(); f++) {
45  for (char *c = FldV[f]; *c; c++) {
46  *c = tolower(*c); }
47  }
48 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TVec< char * > FldV
Pointers to fields of the current line.
Definition: ssmp.h:16

Here is the call graph for this function:

TSsParserMP::UndefDefaultCopyAssign ( TSsParserMP  )
private

Friends And Related Function Documentation

friend class TPt< TSsParserMP >
friend

Definition at line 7 of file ssmp.h.

Member Data Documentation

TCRef TSsParserMP::CRef
private

Definition at line 7 of file ssmp.h.

TPt<TMIn> TSsParserMP::FInPt
private

Pointer to the input file stream.

Definition at line 17 of file ssmp.h.

Referenced by CountNewLinesInRange(), GetStartPosV(), Next(), NextFromIndex(), SkipCommentLines(), and TSsParserMP().

TVec<char*> TSsParserMP::FldV
private

Pointers to fields of the current line.

Definition at line 16 of file ssmp.h.

Referenced by DumpStr(), Next(), and ToLc().

uint64 TSsParserMP::LineCnt
private

Number of processed lines so far.

Definition at line 13 of file ssmp.h.

Referenced by Next().

TChA TSsParserMP::LineStr
private

Current line.

Definition at line 15 of file ssmp.h.

Referenced by Next().

bool TSsParserMP::SkipCmt
private

Skip comments (lines starting with #).

Definition at line 11 of file ssmp.h.

Referenced by Next().

bool TSsParserMP::SkipEmptyFld
private

Skip empty fields (i.e., multiple consecutive separators are considered as one).

Definition at line 12 of file ssmp.h.

Referenced by Next(), and NextFromIndex().

bool TSsParserMP::SkipLeadBlanks
private

Ignore leading whitespace characters in a line.

Definition at line 10 of file ssmp.h.

Referenced by Next(), and NextFromIndex().

char TSsParserMP::SplitCh
private

Separator character (if one of the non-started separators is used)

Definition at line 14 of file ssmp.h.

Referenced by Next(), NextFromIndex(), and TSsParserMP().

TSsFmt TSsParserMP::SsFmt
private

Separator type.

Definition at line 9 of file ssmp.h.

Referenced by Next(), and NextFromIndex().


The documentation for this class was generated from the following files: