|
SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
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. | |
| 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.
References FailR, FInPt, TStr::GetFExt(), TZipIn::IsZipExt(), New(), SplitCh, ssfCommaSep, SsFmt, ssfSemicolonSep, ssfSpaceSep, ssfTabSep, ssfVBar, and ssfWhiteSep.
: 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.
References FInPt, TStr::GetFExt(), TZipIn::IsZipExt(), New(), and SplitCh.
: 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 |
Definition at line 484 of file ss.cpp.
References TChA::Clr(), TChA::CStr(), FldV, TStr::Fmt(), and TVec< TVal, TSizeTy >::Len().
{
static TChA ChA(10*1024);
ChA.Clr();
for (int i = 0; i < FldV.Len(); i++) {
ChA += TStr::Fmt(" %d: '%s'\n", i, FldV[i]);
}
return ChA.CStr();
}

| bool TSsParser::Eof | ( | ) | const [inline] |
Checks for end of file.
Definition at line 122 of file ss.h.
Referenced by TSnap::LoadPajek().

| const char* TSsParser::GetFld | ( | const int & | FldN | ) | const [inline] |
| char* TSsParser::GetFld | ( | const int & | FldN | ) | [inline] |
| int TSsParser::GetFlds | ( | ) | const [inline] |
Returns the number of fields in the current line.
Definition at line 116 of file ss.h.
Referenced by TAGMUtil::LoadCmtyVV(), and TNcpGraphsBase::TNcpGraphsBase().
{ return Len(); }

| 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.
References GetFld(), TCh::IsNum(), and TCh::IsWs().
Referenced by TNcpGraphsBase::TNcpGraphsBase().
{
// 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.
References GetFld(), TCh::GetNum(), TCh::IsNum(), and TCh::IsWs().
Referenced by TAGMUtil::LoadCmtyVV(), TSnap::LoadConnList(), TSnap::LoadEdgeList(), TTimeNENet::LoadFlickr(), and TSnap::LoadPajek().
{
// 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] |
Assumes FldN is an integer its value is returned. If FldN is not an integer an exception is thrown.
Definition at line 139 of file ss.h.
References TStr::Fmt(), and IAssertR.
{
int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }

| uint64 TSsParser::GetLineNo | ( | ) | const [inline] |
Returns the line number of the current line.
Definition at line 118 of file ss.h.
Referenced by TTimeNENet::LoadFlickr().
{ return LineCnt; }

| TChA TSsParser::GetLnStr | ( | ) | const [inline] |
| bool TSsParser::IsCmt | ( | ) | const [inline] |
Checks whether the current line is a comment (starts with '#').
Definition at line 120 of file ss.h.
Referenced by TTimeNENet::LoadEdgeTm().

| bool TSsParser::IsFlt | ( | const int & | FldN | ) | const [inline] |
Checks whether fields FldN is a float.
Definition at line 146 of file ss.h.
Referenced by TNcpGraphsBase::TNcpGraphsBase().
{ double v; return GetFlt(FldN, v); }

| bool TSsParser::IsInt | ( | const int & | FldN | ) | const [inline] |
Checks whether fields FldN is an integer.
Definition at line 142 of file ss.h.
Referenced by TAGMUtil::LoadCmtyVV(), TSnap::LoadConnList(), and TSnap::LoadPajek().
{ int v; return GetInt(FldN, v); }

| int TSsParser::Len | ( | ) | const [inline] |
Returns the number of fields in the current line.
Definition at line 114 of file ss.h.
Referenced by TSnap::LoadConnList(), TSnap::LoadConnListStr(), TTimeNENet::LoadEdgeTm(), and TSnap::LoadPajek().

| static PSsParser TSsParser::New | ( | const TStr & | FNm, |
| const TSsFmt | SsFmt | ||
| ) | [inline, static] |
Definition at line 102 of file ss.h.
Referenced by TSsParser().

| 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.
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, TSIn::GetNextLnBf(), TCh::IsWs(), TVec< TVal, TSizeTy >::Last(), LineCnt, LineStr, SkipCmt, SkipEmptyFld, SkipLeadBlanks, SplitCh, SsFmt, and ssfWhiteSep.
Referenced by TAGMUtil::LoadCmtyVV(), TSnap::LoadConnList(), TSnap::LoadConnListStr(), TSnap::LoadEdgeList(), TSnap::LoadEdgeListStr(), TAGMUtil::LoadEdgeListStr(), TTimeNENet::LoadEdgeTm(), TTimeNENet::LoadFlickr(), TSnap::LoadPajek(), and TNcpGraphsBase::TNcpGraphsBase().
{ // 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.
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, TSIn::GetNextLn(), TCh::IsWs(), TVec< TVal, TSizeTy >::Last(), LineCnt, LineStr, SkipCmt, SkipEmptyFld, SkipLeadBlanks, SplitCh, SsFmt, and ssfWhiteSep.
{ // 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 | ( | ) |
Transforms the current line to lower case.
Definition at line 436 of file ss.cpp.
References FldV, and TVec< TVal, TSizeTy >::Len().
Referenced by TSnap::LoadPajek().


| TSsParser::UndefDefaultCopyAssign | ( | TSsParser | ) | [private] |
TCRef TSsParser::CRef [private] |
PSIn TSsParser::FInPt [private] |
Pointer to the input file stream.
Definition at line 82 of file ss.h.
Referenced by Next(), NextSlow(), and TSsParser().
TVec<char*> TSsParser::FldV [private] |
uint64 TSsParser::LineCnt [private] |
Number of processed lines so far.
Definition at line 78 of file ss.h.
Referenced by Next(), and NextSlow().
TChA TSsParser::LineStr [private] |
bool TSsParser::SkipCmt [private] |
Skip comments (lines starting with #).
Definition at line 76 of file ss.h.
Referenced by Next(), and NextSlow().
bool TSsParser::SkipEmptyFld [private] |
Skip empty fields (i.e., multiple consecutive separators are considered as one).
Definition at line 77 of file ss.h.
Referenced by Next(), and NextSlow().
bool TSsParser::SkipLeadBlanks [private] |
Ignore leading whitespace characters in a line.
Definition at line 75 of file ss.h.
Referenced by Next(), and NextSlow().
char TSsParser::SplitCh [private] |
Separator character (if one of the non-started separators is used)
Definition at line 79 of file ss.h.
Referenced by Next(), NextSlow(), and TSsParser().
TSsFmt TSsParser::SsFmt [private] |
Separator type.
Definition at line 74 of file ss.h.
Referenced by Next(), NextSlow(), and TSsParser().