SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TSsParser Class Reference

#include <ss.h>

Collaboration diagram for TSsParser:

List of all members.

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 TChAGetLnStr () 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 >

Detailed Description

Definition at line 60 of file ss.h.


Constructor & Destructor Documentation

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.");
  }
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

Definition at line 374 of file ss.cpp.

                      {
  //if (Bf != NULL) { delete [] Bf; }
}

Member Function Documentation

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();
}

Here is the call graph for this function:

bool TSsParser::Eof ( ) const [inline]

Definition at line 81 of file ss.h.

Referenced by TSnap::LoadPajek().

{ return FInPt->Eof(); }

Here is the caller graph for this function:

const char* TSsParser::GetFld ( const int &  FldN) const [inline]

Definition at line 85 of file ss.h.

Referenced by GetFlt(), GetInt(), and TTimeNENet::LoadEdgeTm().

{ return FldV[FldN]; }

Here is the caller graph for this function:

char* TSsParser::GetFld ( const int &  FldN) [inline]

Definition at line 86 of file ss.h.

{ return FldV[FldN]; }
int TSsParser::GetFlds ( ) const [inline]

Definition at line 78 of file ss.h.

Referenced by TNcpGraphsBase::TNcpGraphsBase().

{ return Len(); }

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double TSsParser::GetFlt ( const int &  FldN) const [inline]

Definition at line 95 of file ss.h.

References IAssert.

                                       {
    double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TSsParser::GetInt ( const int &  FldN) const [inline]

Definition at line 90 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; }

Here is the call graph for this function:

uint64 TSsParser::GetLineNo ( ) const [inline]

Definition at line 79 of file ss.h.

Referenced by TTimeNENet::LoadFlickr().

{ return LineCnt; }

Here is the caller graph for this function:

const TChA& TSsParser::GetLnStr ( ) const [inline]

Definition at line 82 of file ss.h.

{ return LineStr; }
bool TSsParser::IsCmt ( ) const [inline]

Definition at line 80 of file ss.h.

Referenced by TTimeNENet::LoadEdgeTm().

{ return Len()>0 && GetFld(0)[0] == '#'; }

Here is the caller graph for this function:

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); }

Here is the caller graph for this function:

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); }

Here is the caller graph for this function:

int TSsParser::Len ( ) const [inline]

Definition at line 77 of file ss.h.

Referenced by TSnap::LoadConnList(), TSnap::LoadConnListStr(), TTimeNENet::LoadEdgeTm(), and TSnap::LoadPajek().

{ return FldV.Len(); }

Here is the caller graph for this function:

static PSsParser TSsParser::New ( const TStr FNm,
const TSsFmt  SsFmt 
) [inline, static]

Definition at line 74 of file ss.h.

Referenced by TSsParser().

{ return new TSsParser(FNm, SsFmt); }

Here is the caller graph for this function:

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; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 87 of file ss.h.

{ return FldV[FldN]; }
char* TSsParser::operator[] ( const int &  FldN) [inline]

Definition at line 88 of file ss.h.

{ return FldV[FldN]; }
void TSsParser::ToLc ( )

Definition at line 404 of file ss.cpp.

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

Referenced by TSnap::LoadPajek().

                     {
  for (int f = 0; f < FldV.Len(); f++) {
    for (char *c = FldV[f]; *c; c++) {
      *c = tolower(*c); }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class TPt< TSsParser > [friend]

Definition at line 60 of file ss.h.


Member Data Documentation

Definition at line 60 of file ss.h.

Definition at line 68 of file ss.h.

Referenced by Next(), and TSsParser().

TVec<char*> TSsParser::FldV [private]

Definition at line 67 of file ss.h.

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

Definition at line 64 of file ss.h.

Referenced by Next().

Definition at line 66 of file ss.h.

Referenced by Next().

bool TSsParser::SkipCmt [private]

Definition at line 63 of file ss.h.

Referenced by Next().

bool TSsParser::SkipEmptyFld [private]

Definition at line 63 of file ss.h.

Referenced by Next().

bool TSsParser::SkipLeadBlanks [private]

Definition at line 63 of file ss.h.

Referenced by Next().

char TSsParser::SplitCh [private]

Definition at line 65 of file ss.h.

Referenced by Next(), and TSsParser().

Definition at line 62 of file ss.h.

Referenced by Next(), and TSsParser().


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