SNAP Library 2.1, User Reference  2013-09-25 10:47:25
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>

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 18 of file ss.h.


Constructor & Destructor Documentation

TSs::TSs ( ) [inline]

Definition at line 22 of file ss.h.

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

Definition at line 24 of file ss.h.

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

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

                                       {
//  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];
}
void TSs::DelX ( const int &  X)

Definition at line 62 of file ss.cpp.

                          {
  int YLen=GetYLen();
  for (int Y=0; Y<YLen; Y++){
    CellStrVV[Y]->V.Del(X);
  }
}
void TSs::DelY ( const int &  Y)

Definition at line 69 of file ss.cpp.

                          {
  CellStrVV.Del(Y);
}
TStr TSs::GetFldNm ( const int &  FldX) const [inline]

Definition at line 50 of file ss.h.

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

Definition at line 47 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;
}
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 TSs::GetVal ( const int &  X,
const int &  Y 
) const

Definition at line 16 of file ss.cpp.

                                                 {
  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();
  }
}
int TSs::GetXLen ( ) const

Definition at line 28 of file ss.cpp.

                       {
  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;
  }
}
int TSs::GetXLen ( const int &  Y) const

Definition at line 39 of file ss.cpp.

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

Definition at line 47 of file ss.cpp.

                       {
  return CellStrVV.Len();
}
static PSs TSs::Load ( TSIn SIn) [inline, static]

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

                                                               {
  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;
}
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 TSs::New ( ) [inline, static]

Definition at line 23 of file ss.h.

{return PSs(new TSs());}
TSs& TSs::operator= ( const TSs Ss) [inline]

Definition at line 29 of file ss.h.

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

                                                           {
  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;
}
void TSs::Save ( TSOut SOut) [inline]

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

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

Friends And Related Function Documentation

friend class TPt< TSs > [friend]

Definition at line 18 of file ss.h.


Member Data Documentation

Definition at line 20 of file ss.h.

TCRef TSs::CRef [private]

Definition at line 18 of file ss.h.


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