SNAP Library, User Reference  2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ss.h File Reference

Go to the source code of this file.

Enumerations

enum  TSsFmt {
  ssfUndef, ssfTabSep, ssfCommaSep, ssfSemicolonSep,
  ssfVBar, ssfSpaceSep, ssfWhiteSep, ssfMx
}

Functions

 TSs ()
static PSs New ()
 ~TSs ()
 TSs (TSIn &SIn)
static PSs Load (TSIn &SIn)
void Save (TSOut &SOut)
TSsoperator= (const TSs &Ss)
TStrAt (const int &X, const int &Y)
void PutVal (const int &X, const int &Y, const TStr &Str)
TStr GetVal (const int &X, const int &Y) const
int GetXLen () const
int GetXLen (const int &Y) const
int GetYLen () const
void DelX (const int &X)
void DelY (const int &Y)
int SearchX (const int &Y, const TStr &Str) const
int SearchY (const int &X, const TStr &Str) const
int GetFlds () const
int GetFldX (const TStr &FldNm, const TStr &NewFldNm="", const int &Y=0) const
int GetFldY (const TStr &FldNm, const TStr &NewFldNm="", const int &X=0) const
TStr GetFldNm (const int &FldX) const
static PSs LoadTxt (const TSsFmt &SsFmt, const TStr &FNm, const PNotify &Notify=NULL, const bool &IsExcelEoln=true, const int &MxY=-1, const TIntV &AllowedColNV=TIntV(), const bool &IsQStr=true)
void SaveTxt (const TStr &FNm, const PNotify &Notify=NULL) const
static void LoadTxtFldV (const TSsFmt &SsFmt, const PSIn &SIn, char &Ch, TStrV &FldValV, const bool &IsExcelEoln=true, const bool &IsQStr=true)
static TSsFmt GetSsFmtFromStr (const TStr &SsFmtNm)
static TStr GetStrFromSsFmt (const TSsFmt &SsFmt)
static TStr GetSsFmtNmVStr ()
 UndefDefaultCopyAssign (TSsParser)
 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 ()
static PSsParser New (const TStr &FNm, const TSsFmt SsFmt)
bool Next ()
int Len () const
uint64 GetLineNo () const
bool IsCmt () const
bool Eof () const
const TChAGetLnStr () const
void ToLc ()
const char * GetFld (const int &FldN) const
const char * operator[] (const int &FldN) const
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

Variables

ClassTP(TSsParser, PSsParser)
private bool 
SkipLeadBlanks
ClassTP(TSsParser, PSsParser)
private bool 
SkipCmt
ClassTP(TSsParser, PSsParser)
private bool 
SkipEmptyFld
uint64 LineCnt
char SplitCh
TChA LineStr
TVec< char * > FldV
PSIn FInPt

Enumeration Type Documentation

enum TSsFmt
Enumerator:
ssfUndef 
ssfTabSep 
ssfCommaSep 
ssfSemicolonSep 
ssfVBar 
ssfSpaceSep 
ssfWhiteSep 
ssfMx 

Definition at line 3 of file ss.h.


Function Documentation

TStr& At ( const int &  X,
const int &  Y 
)
void DelX ( const int &  X)
void DelY ( const int &  Y)
const char * TSsParser::DumpStr ( ) const

Definition at line 452 of file ss.cpp.

                                     {
  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 Eof ( ) const

Definition at line 79 of file ss.h.

{ return FInPt->Eof(); }
char * GetFld ( const int &  FldN) const

Definition at line 83 of file ss.h.

{ return FldV[FldN]; }
TStr GetFldNm ( const int &  FldX) const

Definition at line 38 of file ss.h.

{return GetVal(FldX, 0);}
int GetFlds ( ) const

Definition at line 35 of file ss.h.

{return GetXLen(0);}
int TSs::GetFldX ( const TStr FldNm,
const TStr NewFldNm = "",
const int &  Y = 0 
) const

Definition at line 73 of file ss.cpp.

                                                                            {
  if (GetYLen()>Y){
    int XLen=GetXLen(Y);
    for (int X=0; X<XLen; X++){
      if (GetVal(X, Y).GetTrunc()==FldNm){
        if (!NewFldNm.Empty()){GetVal(X, Y)=NewFldNm;}
        return X;
      }
    }
    return -1;
  } else {
    return -1;
  }
}
int TSs::GetFldY ( const TStr FldNm,
const TStr NewFldNm = "",
const int &  X = 0 
) const

Definition at line 88 of file ss.cpp.

                                                                            {
  for (int Y=0; Y<GetYLen(); Y++){
    if (GetXLen(Y)>X){
      if (GetVal(X, Y).GetTrunc()==FldNm){
        if (!NewFldNm.Empty()){GetVal(X, Y)=NewFldNm;}
        return Y;
      }
    }
  }
  return -1;
}
bool GetFlt ( const int &  FldN,
double &  Val 
) const
double GetFlt ( const int &  FldN) const

Definition at line 93 of file ss.h.

                                       {
    double Val=0.0; IAssert(GetFlt(FldN, Val)); return Val; }
bool GetInt ( const int &  FldN,
int &  Val 
) const
int GetInt ( const int &  FldN) const

Definition at line 88 of file ss.h.

                                    {
    int Val=0; IAssertR(GetInt(FldN, Val), TStr::Fmt("Field %d not INT.\n%s", FldN, DumpStr()).CStr()); return Val; }
uint64 GetLineNo ( ) const

Definition at line 77 of file ss.h.

{ return LineCnt; }
const TChA& GetLnStr ( ) const

Definition at line 80 of file ss.h.

{ return LineStr; }
TSsFmt TSs::GetSsFmtFromStr ( const TStr SsFmtNm) [static]

Definition at line 315 of file ss.cpp.

                                              {
  TStr LcSsFmtNm=SsFmtNm.GetLc();
  if (LcSsFmtNm=="tab"){return ssfTabSep;}
  else if (LcSsFmtNm=="comma"){return ssfCommaSep;}
  else if (LcSsFmtNm=="semicolon"){return ssfSemicolonSep;}
  else if (LcSsFmtNm=="vbar"){return ssfVBar;}
  else if (LcSsFmtNm=="space"){return ssfSpaceSep;}
  else if (LcSsFmtNm=="white"){return ssfWhiteSep;}
  else {return ssfUndef;}
}
TStr TSs::GetSsFmtNmVStr ( ) [static]

Definition at line 338 of file ss.cpp.

                        {
  TChA ChA;
  ChA+='(';
  ChA+="tab"; ChA+=", ";
  ChA+="comma"; ChA+=", ";
  ChA+="semicolon"; ChA+=", ";
  ChA+="space"; ChA+=", ";
  ChA+="white"; ChA+=")";
  return ChA;
}
TStr TSs::GetStrFromSsFmt ( const TSsFmt SsFmt) [static]

Definition at line 326 of file ss.cpp.

                                            {
  switch (SsFmt){
    case ssfTabSep: return "tab";
    case ssfCommaSep: return "comma";
    case ssfSemicolonSep: return "semicolon";
    case ssfVBar: return "vbar";
    case ssfSpaceSep: return "space";
    case ssfWhiteSep: return "white";
    default: return "undef";
  }
}
TStr GetVal ( const int &  X,
const int &  Y 
) const

Definition at line 157 of file url.h.

                                                        {
    return KeyNmToValH.GetDat(KeyNmV[KeyN])[ValN];}
int GetXLen ( ) const
int GetXLen ( const int &  Y) const
int GetYLen ( ) const
bool IsCmt ( ) const

Definition at line 78 of file ss.h.

{ return Len()>0 && GetFld(0)[0] == '#'; }
bool IsFlt ( const int &  FldN) const

Definition at line 92 of file ss.h.

{ double v; return GetFlt(FldN, v); }
bool IsInt ( const int &  FldN) const

Definition at line 90 of file ss.h.

{ int v; return GetInt(FldN, v); }
int Len ( ) const

Definition at line 75 of file ss.h.

{ return FldV.Len(); }
static PSs Load ( TSIn SIn) [static]

Definition at line 14 of file ss.h.

{return new TSs(SIn);}
static PSs LoadTxt ( const TSsFmt SsFmt,
const TStr FNm,
const PNotify &  Notify = NULL,
const bool &  IsExcelEoln = true,
const int &  MxY = -1,
const TIntV AllowedColNV = TIntV(),
const bool &  IsQStr = true 
) [static]
void TSs::LoadTxtFldV ( const TSsFmt SsFmt,
const PSIn SIn,
char &  Ch,
TStrV FldValV,
const bool &  IsExcelEoln = true,
const bool &  IsQStr = true 
) [static]

Definition at line 228 of file ss.cpp.

                                                             {
  if (!SIn->Eof()){
    FldValV.Clr(false); int X=0;
    if (Ch==TCh::NullCh){Ch=SIn->GetCh();}
    TChA ChA;
    while (!SIn->Eof()){
      // compose value
      ChA.Clr();
      if (IsQStr&&(Ch=='"')){
        // quoted string ('""' sequence means '"')
        Ch=SIn->GetCh();
        forever {
          while ((!SIn->Eof())&&(Ch!='"')){
            ChA+=Ch; Ch=SIn->GetCh();}
          if (Ch=='"'){
            Ch=SIn->GetCh();
            if (Ch=='"'){ChA+=Ch; Ch=SIn->GetCh();}
            else {break;}
          }
        }
      } else {
        if (SsFmt==ssfTabSep){
          while ((!SIn->Eof())&&(Ch!='\t')&&(Ch!='\r')&&
           ((Ch!='\n')||IsExcelEoln)){
            ChA+=Ch; Ch=SIn->GetCh();
          }
          if ((!ChA.Empty())&&(ChA.LastCh()=='\"')){
            ChA.Pop();}
        } else
        if (SsFmt==ssfCommaSep){
          while ((!SIn->Eof())&&(Ch!=',')&&(Ch!='\r')&&
           ((Ch!='\n')||IsExcelEoln)){
            ChA+=Ch; Ch=SIn->GetCh();
          }
        } else
        if (SsFmt==ssfSemicolonSep){
          while ((!SIn->Eof())&&(Ch!=';')&&(Ch!='\r')&&
           ((Ch!='\n')||IsExcelEoln)){
            ChA+=Ch; Ch=SIn->GetCh();
          }
        } else
        if (SsFmt==ssfVBar){
          while ((!SIn->Eof())&&(Ch!='|')&&(Ch!='\r')&&
           ((Ch!='\n')||IsExcelEoln)){
            ChA+=Ch; Ch=SIn->GetCh();
          }
        } else {
          Fail;
        }
      }
      // add value to spreadsheet
      ChA.Trunc();
      FldValV.Add(ChA);
      // process delimiters
      if (SIn->Eof()){
        break;
      } else
      if ((SsFmt==ssfTabSep)&&(Ch=='\t')){
        X++; Ch=SIn->GetCh();
      } else
      if ((SsFmt==ssfCommaSep)&&(Ch==',')){
        X++; Ch=SIn->GetCh();
      } else
      if ((SsFmt==ssfSemicolonSep)&&(Ch==';')){
        X++; Ch=SIn->GetCh();
      } else
      if ((SsFmt==ssfVBar)&&(Ch=='|')){
        X++; Ch=SIn->GetCh();
      } else
      if (Ch=='\r'){
        Ch=SIn->GetCh();
        if ((Ch=='\n')&&(!SIn->Eof())){Ch=SIn->GetCh();}
        break;
      } else
      if (Ch=='\n'){
        X=0; Ch=SIn->GetCh();
        if ((Ch=='\r')&&(!SIn->Eof())){Ch=SIn->GetCh();}
        break;
      } else {
        Fail;
      }
    }
  }
}
static PSs New ( ) [static]

Definition at line 11 of file ss.h.

{return PSs(new TSs());}
static PSsParser New ( const TStr FNm,
const TSsFmt  SsFmt 
) [static]

Definition at line 72 of file ss.h.

{ return new TSsParser(FNm, SsFmt); }
bool Next ( )

Definition at line 58 of file xfl.h.

{TStr FNm; return Next(FNm);}
TSs& operator= ( const TSs Ss)

Definition at line 17 of file ss.h.

                               {
    if (this!=&Ss){CellStrVV=Ss.CellStrVV;} return *this;}
const char* operator[] ( const int &  FldN) const

Definition at line 85 of file ss.h.

{ return FldV[FldN]; }
void PutVal ( const int &  X,
const int &  Y,
const TStr Str 
)
void Save ( TSOut SOut)

Definition at line 15 of file ss.h.

{CellStrVV.Save(SOut);}
void SaveTxt ( const TStr FNm,
const PNotify &  Notify = NULL 
) const
int TSs::SearchX ( const int &  Y,
const TStr Str 
) const

Definition at line 51 of file ss.cpp.

                                                    {
  return CellStrVV[Y]->V.SearchForw(Str);
}
int TSs::SearchY ( const int &  X,
const TStr Str 
) const

Definition at line 55 of file ss.cpp.

                                                    {
  int YLen=GetYLen();
  for (int Y=0; Y<YLen; Y++){
     if (Str==GetVal(X, Y)){return Y;}}
  return -1;
}
void ToLc ( )
TSs ( )

Definition at line 10 of file ss.h.

: CellStrVV(){}
TSs ( TSIn SIn)

Definition at line 13 of file ss.h.

: CellStrVV(SIn){}
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.

                                                                                                                                       : 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.

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

Definition at line 12 of file ss.h.

{}

Definition at line 374 of file ss.cpp.

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

Variable Documentation

Definition at line 66 of file ss.h.

TVec<char*> FldV

Definition at line 65 of file ss.h.

Definition at line 62 of file ss.h.

Definition at line 64 of file ss.h.

ClassTP (TSsParser, PSsParser) private bool SkipCmt

Definition at line 58 of file ss.h.

ClassTP (TSsParser, PSsParser) private bool SkipEmptyFld

Definition at line 58 of file ss.h.

ClassTP (TSsParser, PSsParser) private bool SkipLeadBlanks

Fast Spread Sheet Parser.

Definition at line 58 of file ss.h.

char SplitCh

Definition at line 63 of file ss.h.