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
TSs Class Reference

#include <ss.h>

Collaboration diagram for TSs:

List of all members.

Public Member Functions

 TSs ()
 ~TSs ()
 TSs (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
void SaveTxt (const TStr &FNm, const PNotify &Notify=NULL) const

Static Public Member Functions

static PSs New ()
static PSs Load (TSIn &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 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 ()

Private Attributes

TCRef CRef
TVec< PStrVCellStrVV

Friends

class TPt< TSs >

Detailed Description

Definition at line 8 of file ss.h.


Constructor & Destructor Documentation

TSs::TSs ( ) [inline]

Definition at line 12 of file ss.h.

: CellStrVV(){}
TSs::~TSs ( ) [inline]

Definition at line 14 of file ss.h.

{}
TSs::TSs ( TSIn SIn) [inline]

Definition at line 15 of file ss.h.

: CellStrVV(SIn){}

Member Function Documentation

TStr & TSs::At ( const int &  X,
const int &  Y 
)

Definition at line 3 of file ss.cpp.

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

                                       {
//  Fail;
  if (Y>=CellStrVV.Len()){CellStrVV.Reserve(Y+1, Y+1);}
  if (X>=CellStrVV[Y]->Len()){CellStrVV[Y]->V.Reserve(X+1, X+1);}
  return CellStrVV[Y]->V[X];
}

Here is the call graph for this function:

void TSs::DelX ( const int &  X)

Definition at line 62 of file ss.cpp.

References CellStrVV, TVec< TVal >::Del(), and GetYLen().

                          {
  int YLen=GetYLen();
  for (int Y=0; Y<YLen; Y++){
    CellStrVV[Y]->V.Del(X);
  }
}

Here is the call graph for this function:

void TSs::DelY ( const int &  Y)

Definition at line 69 of file ss.cpp.

References CellStrVV, and TVec< TVal >::Del().

                          {
  CellStrVV.Del(Y);
}

Here is the call graph for this function:

TStr TSs::GetFldNm ( const int &  FldX) const [inline]

Definition at line 40 of file ss.h.

{return GetVal(FldX, 0);}
int TSs::GetFlds ( ) const [inline]

Definition at line 37 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.

References TStr::Empty(), GetVal(), GetXLen(), and GetYLen().

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

Here is the call graph for this function:

int TSs::GetFldY ( const TStr FldNm,
const TStr NewFldNm = "",
const int &  X = 0 
) const

Definition at line 88 of file ss.cpp.

References TStr::Empty(), TStr::GetTrunc(), GetVal(), GetXLen(), and GetYLen().

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

Here is the call graph for this function:

TSsFmt TSs::GetSsFmtFromStr ( const TStr SsFmtNm) [static]

Definition at line 315 of file ss.cpp.

References TStr::GetLc(), ssfCommaSep, ssfSemicolonSep, ssfSpaceSep, ssfTabSep, ssfUndef, ssfVBar, and ssfWhiteSep.

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

Here is the call graph for this function:

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.

References ssfCommaSep, ssfSemicolonSep, ssfSpaceSep, ssfTabSep, ssfVBar, and ssfWhiteSep.

                                            {
  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 TSs::GetVal ( const int &  X,
const int &  Y 
) const

Definition at line 16 of file ss.cpp.

References CellStrVV, TStr::GetNullStr(), and TVec< TVal >::Len().

Referenced by GetFldX(), GetFldY(), and SearchY().

                                                 {
  if ((0<=Y)&&(Y<CellStrVV.Len())){
    if ((0<=X)&&(X<CellStrVV[Y]->Len())){
      return CellStrVV[Y]->V[X];
    } else {
      return TStr::GetNullStr();
    }
  } else {
    return TStr::GetNullStr();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TSs::GetXLen ( ) const

Definition at line 28 of file ss.cpp.

References CellStrVV, TInt::GetMx(), and TVec< TVal >::Len().

Referenced by GetFldX(), and GetFldY().

                       {
  if (CellStrVV.Len()==0){
    return 0;
  } else {
    int MxXLen=CellStrVV[0]->Len();
    for (int Y=1; Y<CellStrVV.Len(); Y++){
      MxXLen=TInt::GetMx(MxXLen, CellStrVV[Y]->Len());}
    return MxXLen;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TSs::GetXLen ( const int &  Y) const

Definition at line 39 of file ss.cpp.

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

                                   {
  if ((0<=Y)&&(Y<CellStrVV.Len())){
    return CellStrVV[Y]->Len();
  } else {
    return 0;
  }
}

Here is the call graph for this function:

int TSs::GetYLen ( ) const

Definition at line 47 of file ss.cpp.

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

Referenced by DelX(), GetFldX(), GetFldY(), and SearchY().

                       {
  return CellStrVV.Len();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PSs TSs::Load ( TSIn SIn) [inline, static]

Definition at line 16 of file ss.h.

{return new TSs(SIn);}
PSs TSs::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]

Definition at line 100 of file ss.cpp.

References TChA::Clr(), TVec< TVal >::Empty(), TSIn::Eof(), Fail, TStr::Fmt(), forever, TSIn::GetCh(), TVec< TVal >::IsIn(), New(), PVec< TVal >::New(), ntInfo, ntWarn, TNotify::OnNotify(), TNotify::OnStatus(), ssfCommaSep, ssfSemicolonSep, ssfSpaceSep, ssfTabSep, and ssfVBar.

Referenced by TTimeNet::LoadBipartite(), and TGnuPlot::LoadTs().

                                                               {
  TNotify::OnNotify(Notify, ntInfo, TStr("Loading File ")+FNm+" ...");
  PSIn SIn=TFIn::New(FNm);
  PSs Ss=TSs::New();
  if (!SIn->Eof()){
    int X=0; int Y=0; int PrevX=-1; int PrevY=-1;
    char 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();
          }
        } 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
        if (SsFmt==ssfSpaceSep){
          while ((!SIn->Eof())&&(Ch!=' ')&&(Ch!='\r')&&((Ch!='\n')||IsExcelEoln)){
            ChA+=Ch; Ch=SIn->GetCh();
          }
        } else {
          Fail;
        }
      }
      // add new line if neccessary
      if (PrevY!=Y){
        if ((MxY!=-1)&&(Ss->CellStrVV.Len()==MxY)){break;}
        Ss->CellStrVV.Add(TStrVP::New()); PrevY=Y;
        int Recs=Ss->CellStrVV.Len();
        if (Recs%1000==0){
          TNotify::OnStatus(Notify, TStr::Fmt("  %d\r", Recs));}
      }
      // add value to spreadsheet
      if (AllowedColNV.Empty()||AllowedColNV.IsIn(X)){
        Ss->CellStrVV[Y]->V.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 ((SsFmt==ssfSpaceSep)&&(Ch==' ')){
        X++; Ch=SIn->GetCh();
      } else
      if (Ch=='\r'){
        if ((PrevX!=-1)&&(X!=PrevX)){
          TNotify::OnNotify(Notify, ntWarn, "Number of fields is not the same!");}
        PrevX=X; X=0; Y++; Ch=SIn->GetCh();
        if ((Ch=='\n')&&(!SIn->Eof())){Ch=SIn->GetCh();}
        //if (Ss->CellStrVV.Len()%1000==0){Y--; break;}
      } else
      if (Ch=='\n'){
        if ((PrevX!=-1)&&(X!=PrevX)){
          TNotify::OnNotify(Notify, ntWarn, "Number of fields is not the same!");}
        PrevX=X; X=0; Y++; Ch=SIn->GetCh();
        if ((Ch=='\r')&&(!SIn->Eof())){Ch=SIn->GetCh();}
        //if (Ss->CellStrVV.Len()%1000==0){Y--; break;}
      } else {
        Fail;
      }
    }
  }
  int Recs=Ss->CellStrVV.Len();
  TNotify::OnNotify(Notify, ntInfo, TStr::Fmt("  %d records read.", Recs));
  TNotify::OnNotify(Notify, ntInfo, "... Done.");
  return Ss;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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.

References TVec< TVal >::Add(), TChA::Clr(), TVec< TVal >::Clr(), TChA::Empty(), TSIn::Eof(), Fail, forever, TSIn::GetCh(), TChA::LastCh(), TCh::NullCh, TChA::Pop(), ssfCommaSep, ssfSemicolonSep, ssfTabSep, ssfVBar, and TChA::Trunc().

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

Here is the call graph for this function:

static PSs TSs::New ( ) [inline, static]

Definition at line 13 of file ss.h.

Referenced by LoadTxt(), and SaveTxt().

{return PSs(new TSs());}

Here is the caller graph for this function:

TSs& TSs::operator= ( const TSs Ss) [inline]

Definition at line 19 of file ss.h.

References CellStrVV.

                               {
    if (this!=&Ss){CellStrVV=Ss.CellStrVV;} return *this;}
void TSs::PutVal ( const int &  X,
const int &  Y,
const TStr Str 
)

Definition at line 10 of file ss.cpp.

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

                                                           {
  if (Y>=CellStrVV.Len()){CellStrVV.Reserve(Y+1, Y+1);}
  if (X>=CellStrVV[Y]->Len()){CellStrVV[Y]->V.Reserve(X+1, X+1);}
  CellStrVV[Y]->V[X]=Str;
}

Here is the call graph for this function:

void TSs::Save ( TSOut SOut) [inline]

Definition at line 17 of file ss.h.

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

Definition at line 209 of file ss.cpp.

References CellStrVV, TChA::Len(), TVec< TVal >::Len(), New(), TSOut::PutCh(), TChA::PutCh(), and TSOut::PutStr().

                                                       {
  PSOut SOut=TFOut::New(FNm);
  for (int Y=0; Y<CellStrVV.Len(); Y++){
    for (int X=0; X<CellStrVV[Y]->Len(); X++){
      if (X>0){SOut->PutCh('\t');}
      TStr Str=CellStrVV[Y]->V[X];
      TChA ChA(Str);
      for (int ChN=0; ChN<ChA.Len(); ChN++){
        char Ch=ChA[ChN];
        if ((Ch=='\t')||(Ch=='\r')||(Ch=='\n')){
          ChA.PutCh(ChN, ' ');
        }
      }
      SOut->PutStr(ChA);
    }
    SOut->PutCh('\r'); SOut->PutCh('\n');
  }
}

Here is the call graph for this function:

int TSs::SearchX ( const int &  Y,
const TStr Str 
) const

Definition at line 51 of file ss.cpp.

References CellStrVV, and TVec< TVal >::SearchForw().

                                                    {
  return CellStrVV[Y]->V.SearchForw(Str);
}

Here is the call graph for this function:

int TSs::SearchY ( const int &  X,
const TStr Str 
) const

Definition at line 55 of file ss.cpp.

References GetVal(), and GetYLen().

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

Here is the call graph for this function:


Friends And Related Function Documentation

friend class TPt< TSs > [friend]

Definition at line 8 of file ss.h.


Member Data Documentation

Definition at line 10 of file ss.h.

Referenced by At(), DelX(), DelY(), GetVal(), GetXLen(), GetYLen(), operator=(), PutVal(), SaveTxt(), and SearchX().

TCRef TSs::CRef [private]

Definition at line 8 of file ss.h.


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