SNAP Library 4.1, Developer Reference
2018-07-26 16:30:42
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. More... | |
TSsParser (const TStr &FNm, const char &Separator, const bool &_SkipLeadBlanks=false, const bool &_SkipCmt=true, const bool &_SkipEmptyFld=false) | |
Constructor. More... | |
~TSsParser () | |
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... | |
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... | |
bool | GetUInt64 (const int &FldN, uint64 &Val) const |
If the field FldN is a 64-bit unsigned integer its value is returned in Val and the function returns true . More... | |
bool | IsUInt64 (const int &FldN) const |
Checks whether fields FldN is unsigned 64-bit integer number. More... | |
uint64 | GetUInt64 (const int &FldN) const |
Assumes FldN is a 64-bit unsigned integer point number its value is returned. If FldN is not a 64-bit unsigned integer an exception is thrown. More... | |
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. 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... | |
PSIn | FInPt |
Pointer to the input file stream. More... | |
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(), TZipIn::New(), TFIn::New(), SplitCh, ssfCommaSep, SsFmt, ssfSemicolonSep, ssfSpaceSep, ssfTabSep, ssfVBar, and ssfWhiteSep.
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(), TZipIn::New(), TFIn::New(), and SplitCh.
TSsParser::~TSsParser | ( | ) |
const char * TSsParser::DumpStr | ( | ) | const |
Definition at line 508 of file ss.cpp.
References TChA::Clr(), TChA::CStr(), FldV, TStr::Fmt(), and TVec< TVal, TSizeTy >::Len().
|
inline |
Checks for end of file.
Definition at line 122 of file ss.h.
Referenced by TSnap::CmtyEvolutionFileBatch(), TTable::GetSchema(), and TSnap::LoadPajek().
|
inline |
Returns the contents of the field at index FldN
.
Definition at line 129 of file ss.h.
Referenced by GetFlt(), GetInt(), GetUInt64(), TAGMUtil::LoadCmtyVV(), TSnap::LoadEdgeListNet(), TTimeNENet::LoadEdgeTm(), TCesnaUtil::LoadNIDAttrHFromNIDKH(), TSnap::ReadEdgeSchemaFromFile(), TSnap::ReadEdgesFromFile(), TSnap::ReadNodeSchemaFromFile(), and TSnap::ReadNodesFromFile().
|
inline |
|
inline |
Returns the number of fields in the current line.
Definition at line 116 of file ss.h.
Referenced by TTable::GetSchema(), TAGMUtil::LoadCmtyVV(), TSnap::LoadEdgeListNet(), TTable::LoadSSSeq(), TSnap::ReadEdgeSchemaFromFile(), TSnap::ReadEdgesFromFile(), TSnap::ReadNodeSchemaFromFile(), TSnap::ReadNodesFromFile(), and TNcpGraphsBase::TNcpGraphsBase().
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 485 of file ss.cpp.
References GetFld(), TCh::IsNum(), TCh::IsWs(), and Len().
Referenced by TTable::LoadSSSeq(), TSnap::ReadEdgesFromFile(), TSnap::ReadNodesFromFile(), and TNcpGraphsBase::TNcpGraphsBase().
|
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 150 of file ss.h.
References GetFlt(), and IAssert.
Referenced by GetFlt().
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 447 of file ss.cpp.
References GetFld(), TCh::GetNum(), TCh::IsNum(), TCh::IsWs(), and Len().
Referenced by TSnap::CmtyEvolutionFileBatch(), TAGMUtil::LoadCmtyVV(), TSnap::LoadConnList(), TSnap::LoadEdgeList(), TTimeNENet::LoadFlickr(), TCesnaUtil::LoadNIDAttrHFromNIDKH(), TSnap::LoadNodeList(), TSnap::LoadPajek(), TTable::LoadSSSeq(), TSnap::ReadEdgesFromFile(), and TSnap::ReadNodesFromFile().
|
inline |
Assumes FldN
is an integer its value is returned. If FldN
is not an integer an exception is thrown.
Definition at line 140 of file ss.h.
References TStr::Fmt(), and IAssertR.
|
inline |
Returns the line number of the current line.
Definition at line 118 of file ss.h.
Referenced by TTimeNENet::LoadFlickr(), and TCesnaUtil::LoadNIDAttrHFromNIDKH().
|
inline |
Returns the current line.
Definition at line 124 of file ss.h.
References TChA::DelLastCh(), and TChA::Len().
Referenced by TSnap::CmtyEvolutionFileBatch().
bool TSsParser::GetUInt64 | ( | const int & | FldN, |
uint64 & | Val | ||
) | const |
If the field FldN
is a 64-bit unsigned integer its value is returned in Val
and the function returns true
.
Definition at line 467 of file ss.cpp.
References GetFld(), TCh::GetNum(), TCh::IsNum(), TCh::IsWs(), and Len().
|
inline |
Assumes FldN
is a 64-bit unsigned integer point number its value is returned. If FldN
is not a 64-bit unsigned integer an exception is thrown.
Definition at line 157 of file ss.h.
References GetUInt64(), and IAssert.
Referenced by GetUInt64().
|
inline |
Checks whether the current line is a comment (starts with '#').
Definition at line 120 of file ss.h.
Referenced by TTable::GetSchema(), and TTimeNENet::LoadEdgeTm().
|
inline |
Checks whether fields FldN
is a float.
Definition at line 148 of file ss.h.
Referenced by TTable::GetSchema(), and TNcpGraphsBase::TNcpGraphsBase().
|
inline |
Checks whether fields FldN
is an integer.
Definition at line 143 of file ss.h.
Referenced by TTable::GetSchema(), TAGMUtil::LoadCmtyVV(), TSnap::LoadConnList(), and TSnap::LoadPajek().
|
inline |
Checks whether fields FldN
is unsigned 64-bit integer number.
Definition at line 155 of file ss.h.
|
inline |
Returns the number of fields in the current line.
Definition at line 114 of file ss.h.
Referenced by GetFlt(), GetInt(), GetUInt64(), TSnap::LoadConnList(), TSnap::LoadConnListStr(), TTimeNENet::LoadEdgeTm(), and TSnap::LoadPajek().
Definition at line 102 of file ss.h.
bool TSsParser::Next | ( | ) |
Loads next line from the input file.
If end of file is reached, return value is false
.
Definition at line 412 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 TSnap::CmtyEvolutionFileBatch(), TTable::GetSchema(), TAGMUtil::LoadCmtyVV(), TSnap::LoadConnList(), TSnap::LoadConnListStr(), TSnap::LoadEdgeList(), TSnap::LoadEdgeListNet(), TSnap::LoadEdgeListStr(), TAGMUtil::LoadEdgeListStr(), TTimeNENet::LoadEdgeTm(), TTimeNENet::LoadFlickr(), TCesnaUtil::LoadNIDAttrHFromNIDKH(), TSnap::LoadNodeList(), TSnap::LoadPajek(), TTable::LoadSSSeq(), TSnap::ReadEdgesFromFile(), TSnap::ReadNodesFromFile(), and TNcpGraphsBase::TNcpGraphsBase().
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.
|
inline |
|
inline |
void TSsParser::ToLc | ( | ) |
Transforms the current line to lower case.
Definition at line 440 of file ss.cpp.
References FldV, and TVec< TVal, TSizeTy >::Len().
Referenced by TSnap::LoadPajek().
|
private |
|
private |
Pointer to the input file stream.
Definition at line 82 of file ss.h.
Referenced by Next(), NextSlow(), and TSsParser().
|
private |
|
private |
Number of processed lines so far.
Definition at line 78 of file ss.h.
Referenced by Next(), and NextSlow().
|
private |
|
private |
Skip comments (lines starting with #).
Definition at line 76 of file ss.h.
Referenced by Next(), and NextSlow().
|
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().
|
private |
Ignore leading whitespace characters in a line.
Definition at line 75 of file ss.h.
Referenced by Next(), and NextSlow().
|
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().
|
private |
Separator type.
Definition at line 74 of file ss.h.
Referenced by Next(), NextSlow(), and TSsParser().