|
SNAP Library , Developer Reference
2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <ss.h>

Public Member Functions | |
| TSs () | |
| ~TSs () | |
| TSs (TSIn &SIn) | |
| void | Save (TSOut &SOut) |
| TSs & | operator= (const TSs &Ss) |
| TStr & | At (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< PStrV > | CellStrVV |
Friends | |
| class | TPt< TSs > |
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];
}

| void TSs::DelX | ( | const int & | X | ) |
| void TSs::DelY | ( | const int & | Y | ) |
| TStr TSs::GetFldNm | ( | const int & | FldX | ) | const [inline] |
| int TSs::GetFlds | ( | ) | const [inline] |
| 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;
}
}

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

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

| TStr TSs::GetSsFmtNmVStr | ( | ) | [static] |
| 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();
}
}


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


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


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

| void TSs::PutVal | ( | const int & | X, |
| const int & | Y, | ||
| const TStr & | Str | ||
| ) |
| 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');
}
}

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

| int TSs::SearchY | ( | const int & | X, |
| const TStr & | Str | ||
| ) | const |
TVec<PStrV> TSs::CellStrVV [private] |