SNAP Library , Developer Reference
2013-01-07 14:03:36
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) | |
TSsParser (const TStr &FNm, const char &Separator, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false) | |
~TSsParser () | |
bool | Next () |
int | Len () const |
int | GetFlds () const |
uint64 | GetLineNo () const |
bool | IsCmt () const |
bool | Eof () const |
const TChA & | GetLnStr () const |
void | ToLc () |
const char * | GetFld (const int &FldN) const |
char * | GetFld (const int &FldN) |
const char * | operator[] (const int &FldN) const |
char * | operator[] (const int &FldN) |
bool | GetInt (const int &FldN, int &Val) const |
int | GetInt (const int &FldN) const |
bool | IsInt (const int &FldN) const |
bool | GetFlt (const int &FldN, double &Val) const |
bool | IsFlt (const int &FldN) const |
double | GetFlt (const int &FldN) const |
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 |
bool | SkipLeadBlanks |
bool | SkipCmt |
bool | SkipEmptyFld |
uint64 | LineCnt |
char | SplitCh |
TChA | LineStr |
TVec< char * > | FldV |
PSIn | FInPt |
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 |
||
) |
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'), 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 |
||
) |
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'), 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 452 of file ss.cpp.
References TChA::Clr(), TChA::CStr(), FldV, TStr::Fmt(), and TVec< TVal >::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] |
Definition at line 81 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] |
Definition at line 78 of file ss.h.
Referenced by TNcpGraphsBase::TNcpGraphsBase().
{ return Len(); }
bool TSsParser::GetFlt | ( | const int & | FldN, |
double & | Val | ||
) | const |
Definition at line 430 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 |
Definition at line 411 of file ss.cpp.
References GetFld(), TCh::GetNum(), TCh::IsNum(), and TCh::IsWs().
Referenced by 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] |
uint64 TSsParser::GetLineNo | ( | ) | const [inline] |
Definition at line 79 of file ss.h.
Referenced by TTimeNENet::LoadFlickr().
{ return LineCnt; }
const TChA& TSsParser::GetLnStr | ( | ) | const [inline] |
bool TSsParser::IsCmt | ( | ) | const [inline] |
Definition at line 80 of file ss.h.
Referenced by TTimeNENet::LoadEdgeTm().
bool TSsParser::IsFlt | ( | const int & | FldN | ) | const [inline] |
Definition at line 94 of file ss.h.
Referenced by TNcpGraphsBase::TNcpGraphsBase().
{ double v; return GetFlt(FldN, v); }
bool TSsParser::IsInt | ( | const int & | FldN | ) | const [inline] |
Definition at line 92 of file ss.h.
Referenced by TSnap::LoadConnList(), and TSnap::LoadPajek().
{ int v; return GetInt(FldN, v); }
int TSsParser::Len | ( | ) | const [inline] |
Definition at line 77 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 74 of file ss.h.
Referenced by TSsParser().
bool TSsParser::Next | ( | ) |
Definition at line 378 of file ss.cpp.
References TVec< TVal >::Add(), TChA::Clr(), TVec< TVal >::Clr(), TChA::CStr(), TVec< TVal >::DelLast(), TVec< TVal >::Empty(), FInPt, FldV, TSIn::GetNextLn(), TCh::IsWs(), TVec< TVal >::Last(), TChA::Len(), LineCnt, LineStr, SkipCmt, SkipEmptyFld, SkipLeadBlanks, SplitCh, SsFmt, and ssfWhiteSep.
Referenced by TSnap::LoadConnList(), TSnap::LoadConnListStr(), TSnap::LoadEdgeList(), TSnap::LoadEdgeListStr(), TTimeNENet::LoadEdgeTm(), TTimeNENet::LoadFlickr(), TSnap::LoadPajek(), and TNcpGraphsBase::TNcpGraphsBase().
{ // split on SplitCh FldV.Clr(false); LineStr.Clr(); FldV.Clr(); LineCnt++; if (! FInPt->GetNextLn(LineStr)) { return false; } if (SkipCmt && LineStr.Len()>0 && LineStr[0]=='#') { return Next(); } char* cur = LineStr.CStr(); if (SkipLeadBlanks) { // skip leadning 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; }
const char* TSsParser::operator[] | ( | const int & | FldN | ) | const [inline] |
char* TSsParser::operator[] | ( | const int & | FldN | ) | [inline] |
void TSsParser::ToLc | ( | ) |
Definition at line 404 of file ss.cpp.
References FldV, and TVec< TVal >::Len().
Referenced by TSnap::LoadPajek().
TSsParser::UndefDefaultCopyAssign | ( | TSsParser | ) | [private] |
TCRef TSsParser::CRef [private] |
PSIn TSsParser::FInPt [private] |
Definition at line 68 of file ss.h.
Referenced by Next(), and TSsParser().
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] |
Definition at line 65 of file ss.h.
Referenced by Next(), and TSsParser().
TSsFmt TSsParser::SsFmt [private] |
Definition at line 62 of file ss.h.
Referenced by Next(), and TSsParser().