|
SNAP Library 2.0, User Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <ss.h>
Public Member Functions | |
| TSsParser (const TStr &FNm, const TSsFmt _SsFmt=ssfTabSep, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false) | |
| Constructor. | |
| TSsParser (const TStr &FNm, const char &Separator, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false) | |
| Constructor. | |
| ~TSsParser () | |
| bool | Next () |
| Loads next line from the input file. | |
| bool | NextSlow () |
| Loads next line from the input file (older, slow implementation - deprecated). | |
| int | Len () const |
| Returns the number of fields in the current line. | |
| int | GetFlds () const |
| Returns the number of fields in the current line. | |
| uint64 | GetLineNo () const |
| Returns the line number of the current line. | |
| bool | IsCmt () const |
| Checks whether the current line is a comment (starts with '#'). | |
| bool | Eof () const |
| Checks for end of file. | |
| const TChA & | GetLnStr () const |
| Returns the current line. | |
| void | ToLc () |
| Transforms the current line to lower case. | |
| const char * | GetFld (const int &FldN) const |
Returns the contents of the field at index FldN. | |
| char * | GetFld (const int &FldN) |
Returns the contents of the field at index FldN. | |
| const char * | operator[] (const int &FldN) const |
Returns the contents of the field at index FldN. | |
| char * | operator[] (const int &FldN) |
Returns the contents of the field at index FldN. | |
| 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. | |
| 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. | |
| bool | IsInt (const int &FldN) const |
Checks whether fields FldN is an integer. | |
| 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. | |
| bool | IsFlt (const int &FldN) const |
Checks whether fields FldN is a float. | |
| 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. | |
| const char * | DumpStr () const |
Static Public Member Functions | |
| static PSsParser | New (const TStr &FNm, const TSsFmt SsFmt) |
Private Member Functions | |
| UndefDefaultCopyAssign (TSsParser) | |
Private Attributes | |
| TCRef | CRef |
| TSsFmt | SsFmt |
| Separator type. | |
| bool | SkipLeadBlanks |
| Ignore leading whitespace characters in a line. | |
| bool | SkipCmt |
| Skip comments (lines starting with #). | |
| bool | SkipEmptyFld |
| Skip empty fields (i.e., multiple consecutive separators are considered as one). | |
| uint64 | LineCnt |
| Number of processed lines so far. | |
| char | SplitCh |
| Separator character (if one of the non-started separators is used) | |
| TChA | LineStr |
| Current line. | |
| TVec< char * > | FldV |
| Pointers to fields of the current line. | |
| PSIn | FInPt |
| Pointer to the input file stream. | |
Friends | |
| class | TPt< TSsParser > |
| TSsParser::TSsParser | ( | const TStr & | FNm, |
| const TSsFmt | _SsFmt = ssfTabSep, |
||
| const bool & | _SkipLeadBlanks = false, |
||
| const bool & | _SkipCmt = true, |
||
| const bool & | _SkipEmptyFld = false |
||
| ) |
Constructor.
| FNm | Input filename. Can be a text file or a compressed file. |
| _SsFmt | Spread-sheet separator format. Each line will be broken in a set of fields, where the boundary between the fields is defined by the _SsFmt. |
| _SkipLeadBlanks | If true leading/trailing white-spaces of the line will be ignored. |
| _SkipCmt | If true lines starting with '#' will be considered as comments and will be skipped. |
| _SkipEmptyFld | If true then empty fields (consecutive occurrences of the separator) will be ignored. |
Definition at line 351 of file ss.cpp.
: SsFmt(_SsFmt), SkipLeadBlanks(_SkipLeadBlanks), SkipCmt(_SkipCmt), SkipEmptyFld(_SkipEmptyFld), LineCnt(0), /*Bf(NULL),*/ SplitCh('\t'), LineStr(), FldV(), FInPt(NULL) { if (TZipIn::IsZipExt(FNm.GetFExt())) { FInPt = TZipIn::New(FNm); } else { FInPt = TFIn::New(FNm); } //Bf = new char [BfLen]; switch(SsFmt) { case ssfTabSep : SplitCh = '\t'; break; case ssfCommaSep : SplitCh = ','; break; case ssfSemicolonSep : SplitCh = ';'; break; case ssfVBar : SplitCh = '|'; break; case ssfSpaceSep : SplitCh = ' '; break; case ssfWhiteSep: SplitCh = ' '; break; default: FailR("Unknown separator character."); } }
| TSsParser::TSsParser | ( | const TStr & | FNm, |
| const char & | Separator, | ||
| const bool & | _SkipLeadBlanks = false, |
||
| const bool & | _SkipCmt = true, |
||
| const bool & | _SkipEmptyFld = false |
||
| ) |
Constructor.
| FNm | Input filename. Can be a text file or a compressed file. |
| Separator | Spread-sheet separator character. Each line will be broken in a set of fields, where the boundary between the fields is the Separator character. |
| _SkipLeadBlanks | If true leading/trailing white-spaces of the line will be ignored. |
| _SkipCmt | If true lines starting with '#' will be considered as comments and will be skipped. |
| _SkipEmptyFld | If true then empty fields (consecutive occurrences of the separator) will be ignored. |
Definition at line 367 of file ss.cpp.
: SsFmt(ssfSpaceSep), SkipLeadBlanks(_SkipLeadBlanks), SkipCmt(_SkipCmt), SkipEmptyFld(_SkipEmptyFld), LineCnt(0), /*Bf(NULL),*/ SplitCh('\t'), LineStr(), FldV(), FInPt(NULL) { if (TZipIn::IsZipExt(FNm.GetFExt())) { FInPt = TZipIn::New(FNm); } else { FInPt = TFIn::New(FNm); } SplitCh = Separator; }
| const char * TSsParser::DumpStr | ( | ) | const |
| bool TSsParser::Eof | ( | ) | const [inline] |
| const char* TSsParser::GetFld | ( | const int & | FldN | ) | const [inline] |
| char* TSsParser::GetFld | ( | const int & | FldN | ) | [inline] |
| int TSsParser::GetFlds | ( | ) | const [inline] |
| bool TSsParser::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 462 of file ss.cpp.
{
// parsing format {ws} [+/-] +{d} ([.]{d}) ([E|e] [+/-] +{d})
const char *c = GetFld(FldN);
while (TCh::IsWs(*c)) { c++; }
if (*c=='+' || *c=='-') { c++; }
if (! TCh::IsNum(*c) && *c!='.') { return false; }
while (TCh::IsNum(*c)) { c++; }
if (*c == '.') {
c++;
while (TCh::IsNum(*c)) { c++; }
}
if (*c=='e' || *c == 'E') {
c++;
if (*c == '+' || *c == '-' ) { c++; }
if (! TCh::IsNum(*c)) { return false; }
while (TCh::IsNum(*c)) { c++; }
}
if (*c != 0) { return false; }
Val = atof(GetFld(FldN));
return true;
}
| double TSsParser::GetFlt | ( | const int & | FldN | ) | const [inline] |
| bool TSsParser::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 443 of file ss.cpp.
{
// parsing format {ws} [+/-] +{ddd}
int _Val = -1;
bool Minus=false;
const char *c = GetFld(FldN);
while (TCh::IsWs(*c)) { c++; }
if (*c=='-') { Minus=true; c++; }
if (! TCh::IsNum(*c)) { return false; }
_Val = TCh::GetNum(*c); c++;
while (TCh::IsNum(*c)){
_Val = 10 * _Val + TCh::GetNum(*c);
c++;
}
if (Minus) { _Val = -_Val; }
if (*c != 0) { return false; }
Val = _Val;
return true;
}
| int TSsParser::GetInt | ( | const int & | FldN | ) | const [inline] |
| uint64 TSsParser::GetLineNo | ( | ) | const [inline] |
| const TChA& TSsParser::GetLnStr | ( | ) | const [inline] |
| bool TSsParser::IsCmt | ( | ) | const [inline] |
| bool TSsParser::IsFlt | ( | const int & | FldN | ) | const [inline] |
| bool TSsParser::IsInt | ( | const int & | FldN | ) | const [inline] |
| int TSsParser::Len | ( | ) | const [inline] |
| static PSsParser TSsParser::New | ( | const TStr & | FNm, |
| const TSsFmt | SsFmt | ||
| ) | [inline, static] |
| bool TSsParser::Next | ( | ) |
Loads next line from the input file.
If end of file is reached, return value is false.
Definition at line 410 of file ss.cpp.
{ // split on SplitCh
FldV.Clr(false);
LineStr.Clr();
FldV.Clr();
LineCnt++;
if (! FInPt->GetNextLnBf(LineStr)) { return false; }
if (SkipCmt && !LineStr.Empty() && LineStr[0]=='#') { return Next(); }
char* cur = LineStr.CStr();
if (SkipLeadBlanks) { // skip leading blanks
while (*cur && TCh::IsWs(*cur)) { cur++; }
}
char *last = cur;
while (*cur) {
if (SsFmt == ssfWhiteSep) { while (*cur && ! TCh::IsWs(*cur)) { cur++; } }
else { while (*cur && *cur!=SplitCh) { cur++; } }
if (*cur == 0) { break; }
*cur = 0; cur++;
FldV.Add(last); last = cur;
if (SkipEmptyFld && strlen(FldV.Last())==0) { FldV.DelLast(); } // skip empty fields
}
FldV.Add(last); // add last field
if (SkipEmptyFld && FldV.Empty()) { return Next(); } // skip empty lines
return true;
}
| bool TSsParser::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.
Definition at line 382 of file ss.cpp.
{ // split on SplitCh
FldV.Clr(false);
LineStr.Clr();
FldV.Clr();
LineCnt++;
if (! FInPt->GetNextLn(LineStr)) { return false; }
if (SkipCmt && !LineStr.Empty() && LineStr[0]=='#') { return NextSlow(); }
char* cur = LineStr.CStr();
if (SkipLeadBlanks) { // skip leading blanks
while (*cur && TCh::IsWs(*cur)) { cur++; }
}
char *last = cur;
while (*cur) {
if (SsFmt == ssfWhiteSep) { while (*cur && ! TCh::IsWs(*cur)) { cur++; } }
else { while (*cur && *cur!=SplitCh) { cur++; } }
if (*cur == 0) { break; }
*cur = 0; cur++;
FldV.Add(last); last = cur;
if (SkipEmptyFld && strlen(FldV.Last())==0) { FldV.DelLast(); } // skip empty fields
}
FldV.Add(last); // add last field
if (SkipEmptyFld && FldV.Empty()) { return NextSlow(); } // skip empty lines
return true;
}
| const char* TSsParser::operator[] | ( | const int & | FldN | ) | const [inline] |
| char* TSsParser::operator[] | ( | const int & | FldN | ) | [inline] |
| void TSsParser::ToLc | ( | ) |
| TSsParser::UndefDefaultCopyAssign | ( | TSsParser | ) | [private] |
TCRef TSsParser::CRef [private] |
PSIn TSsParser::FInPt [private] |
TVec<char*> TSsParser::FldV [private] |
uint64 TSsParser::LineCnt [private] |
TChA TSsParser::LineStr [private] |
bool TSsParser::SkipCmt [private] |
bool TSsParser::SkipEmptyFld [private] |
bool TSsParser::SkipLeadBlanks [private] |
char TSsParser::SplitCh [private] |
TSsFmt TSsParser::SsFmt [private] |