SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSs Class Reference

#include <ss.h>

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.

22 : CellStrVV(){}
TVec< PStrV > CellStrVV
Definition: ss.h:20
TSs::~TSs ( )
inline

Definition at line 24 of file ss.h.

24 {}
TSs::TSs ( TSIn SIn)
inline

Definition at line 25 of file ss.h.

25 : CellStrVV(SIn){}
TVec< PStrV > CellStrVV
Definition: ss.h:20

Member Function Documentation

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

Definition at line 3 of file ss.cpp.

3  {
4 // Fail;
5  if (Y>=CellStrVV.Len()){CellStrVV.Reserve(Y+1, Y+1);}
6  if (X>=CellStrVV[Y]->Len()){CellStrVV[Y]->V.Reserve(X+1, X+1);}
7  return CellStrVV[Y]->V[X];
8 }
TVec< PStrV > CellStrVV
Definition: ss.h:20
void TSs::DelX ( const int &  X)

Definition at line 62 of file ss.cpp.

62  {
63  int YLen=GetYLen();
64  for (int Y=0; Y<YLen; Y++){
65  CellStrVV[Y]->V.Del(X);
66  }
67 }
int GetYLen() const
Definition: ss.cpp:47
TVec< PStrV > CellStrVV
Definition: ss.h:20
void TSs::DelY ( const int &  Y)

Definition at line 69 of file ss.cpp.

69  {
70  CellStrVV.Del(Y);
71 }
TVec< PStrV > CellStrVV
Definition: ss.h:20
TStr TSs::GetFldNm ( const int &  FldX) const
inline

Definition at line 50 of file ss.h.

50 {return GetVal(FldX, 0);}
TStr GetVal(const int &X, const int &Y) const
Definition: ss.cpp:16
int TSs::GetFlds ( ) const
inline

Definition at line 47 of file ss.h.

47 {return GetXLen(0);}
int GetXLen() const
Definition: ss.cpp:28
int TSs::GetFldX ( const TStr FldNm,
const TStr NewFldNm = "",
const int &  Y = 0 
) const

Definition at line 73 of file ss.cpp.

73  {
74  if (GetYLen()>Y){
75  int XLen=GetXLen(Y);
76  for (int X=0; X<XLen; X++){
77  if (GetVal(X, Y).GetTrunc()==FldNm){
78  if (!NewFldNm.Empty()){GetVal(X, Y)=NewFldNm;}
79  return X;
80  }
81  }
82  return -1;
83  } else {
84  return -1;
85  }
86 }
int GetYLen() const
Definition: ss.cpp:47
int GetXLen() const
Definition: ss.cpp:28
TStr GetVal(const int &X, const int &Y) const
Definition: ss.cpp:16
bool Empty() const
Definition: dt.h:488
int TSs::GetFldY ( const TStr FldNm,
const TStr NewFldNm = "",
const int &  X = 0 
) const

Definition at line 88 of file ss.cpp.

88  {
89  for (int Y=0; Y<GetYLen(); Y++){
90  if (GetXLen(Y)>X){
91  if (GetVal(X, Y).GetTrunc()==FldNm){
92  if (!NewFldNm.Empty()){GetVal(X, Y)=NewFldNm;}
93  return Y;
94  }
95  }
96  }
97  return -1;
98 }
int GetYLen() const
Definition: ss.cpp:47
int GetXLen() const
Definition: ss.cpp:28
TStr GetVal(const int &X, const int &Y) const
Definition: ss.cpp:16
TStr GetTrunc() const
Definition: dt.h:506
bool Empty() const
Definition: dt.h:488
TSsFmt TSs::GetSsFmtFromStr ( const TStr SsFmtNm)
static

Definition at line 315 of file ss.cpp.

315  {
316  TStr LcSsFmtNm=SsFmtNm.GetLc();
317  if (LcSsFmtNm=="tab"){return ssfTabSep;}
318  else if (LcSsFmtNm=="comma"){return ssfCommaSep;}
319  else if (LcSsFmtNm=="semicolon"){return ssfSemicolonSep;}
320  else if (LcSsFmtNm=="vbar"){return ssfVBar;}
321  else if (LcSsFmtNm=="space"){return ssfSpaceSep;}
322  else if (LcSsFmtNm=="white"){return ssfWhiteSep;}
323  else {return ssfUndef;}
324 }
Semicolon separated.
Definition: ss.h:8
Vertical bar separated.
Definition: ss.h:9
Whitespace (space or tab) separated.
Definition: ss.h:11
Tab separated.
Definition: ss.h:6
TStr GetLc() const
Definition: dt.h:499
Space separated.
Definition: ss.h:10
Definition: dt.h:412
Definition: ss.h:5
Comma separated.
Definition: ss.h:7
TStr TSs::GetSsFmtNmVStr ( )
static

Definition at line 338 of file ss.cpp.

338  {
339  TChA ChA;
340  ChA+='(';
341  ChA+="tab"; ChA+=", ";
342  ChA+="comma"; ChA+=", ";
343  ChA+="semicolon"; ChA+=", ";
344  ChA+="space"; ChA+=", ";
345  ChA+="white"; ChA+=")";
346  return ChA;
347 }
Definition: dt.h:201
TStr TSs::GetStrFromSsFmt ( const TSsFmt SsFmt)
static

Definition at line 326 of file ss.cpp.

326  {
327  switch (SsFmt){
328  case ssfTabSep: return "tab";
329  case ssfCommaSep: return "comma";
330  case ssfSemicolonSep: return "semicolon";
331  case ssfVBar: return "vbar";
332  case ssfSpaceSep: return "space";
333  case ssfWhiteSep: return "white";
334  default: return "undef";
335  }
336 }
Semicolon separated.
Definition: ss.h:8
Vertical bar separated.
Definition: ss.h:9
Whitespace (space or tab) separated.
Definition: ss.h:11
Tab separated.
Definition: ss.h:6
Space separated.
Definition: ss.h:10
Comma separated.
Definition: ss.h:7
TStr TSs::GetVal ( const int &  X,
const int &  Y 
) const

Definition at line 16 of file ss.cpp.

16  {
17  if ((0<=Y)&&(Y<CellStrVV.Len())){
18  if ((0<=X)&&(X<CellStrVV[Y]->Len())){
19  return CellStrVV[Y]->V[X];
20  } else {
21  return TStr::GetNullStr();
22  }
23  } else {
24  return TStr::GetNullStr();
25  }
26 }
static TStr GetNullStr()
Definition: dt.cpp:1626
TVec< PStrV > CellStrVV
Definition: ss.h:20
int TSs::GetXLen ( ) const

Definition at line 28 of file ss.cpp.

28  {
29  if (CellStrVV.Len()==0){
30  return 0;
31  } else {
32  int MxXLen=CellStrVV[0]->Len();
33  for (int Y=1; Y<CellStrVV.Len(); Y++){
34  MxXLen=TInt::GetMx(MxXLen, CellStrVV[Y]->Len());}
35  return MxXLen;
36  }
37 }
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1092
TVec< PStrV > CellStrVV
Definition: ss.h:20
int TSs::GetXLen ( const int &  Y) const

Definition at line 39 of file ss.cpp.

39  {
40  if ((0<=Y)&&(Y<CellStrVV.Len())){
41  return CellStrVV[Y]->Len();
42  } else {
43  return 0;
44  }
45 }
TVec< PStrV > CellStrVV
Definition: ss.h:20
int TSs::GetYLen ( ) const

Definition at line 47 of file ss.cpp.

47  {
48  return CellStrVV.Len();
49 }
TVec< PStrV > CellStrVV
Definition: ss.h:20
static PSs TSs::Load ( TSIn SIn)
inlinestatic

Definition at line 26 of file ss.h.

26 {return new TSs(SIn);}
TSs()
Definition: ss.h:22
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.

103  {
104  TNotify::OnNotify(Notify, ntInfo, TStr("Loading File ")+FNm+" ...");
105  PSIn SIn=TFIn::New(FNm);
106  PSs Ss=TSs::New();
107  if (!SIn->Eof()){
108  int X=0; int Y=0; int PrevX=-1; int PrevY=-1;
109  char Ch=SIn->GetCh(); TChA ChA;
110  while (!SIn->Eof()){
111  // compose value
112  ChA.Clr();
113  if (IsQStr&&(Ch=='"')){
114  // quoted string ('""' sequence means '"')
115  Ch=SIn->GetCh();
116  forever {
117  while ((!SIn->Eof())&&(Ch!='"')){
118  ChA+=Ch; Ch=SIn->GetCh();}
119  if (Ch=='"'){
120  Ch=SIn->GetCh();
121  if (Ch=='"'){ChA+=Ch; Ch=SIn->GetCh();}
122  else {break;}
123  }
124  }
125  } else {
126  if (SsFmt==ssfTabSep){
127  while ((!SIn->Eof())&&(Ch!='\t')&&(Ch!='\r')&&((Ch!='\n')||IsExcelEoln)){
128  ChA+=Ch; Ch=SIn->GetCh();
129  }
130  } else
131  if (SsFmt==ssfCommaSep){
132  while ((!SIn->Eof())&&(Ch!=',')&&(Ch!='\r')&&((Ch!='\n')||IsExcelEoln)){
133  ChA+=Ch; Ch=SIn->GetCh();
134  }
135  } else
136  if (SsFmt==ssfSemicolonSep){
137  while ((!SIn->Eof())&&(Ch!=';')&&(Ch!='\r')&&((Ch!='\n')||IsExcelEoln)){
138  ChA+=Ch; Ch=SIn->GetCh();
139  }
140  } else
141  if (SsFmt==ssfVBar){
142  while ((!SIn->Eof())&&(Ch!='|')&&(Ch!='\r')&&((Ch!='\n')||IsExcelEoln)){
143  ChA+=Ch; Ch=SIn->GetCh();
144  }
145  } else
146  if (SsFmt==ssfSpaceSep){
147  while ((!SIn->Eof())&&(Ch!=' ')&&(Ch!='\r')&&((Ch!='\n')||IsExcelEoln)){
148  ChA+=Ch; Ch=SIn->GetCh();
149  }
150  } else {
151  Fail;
152  }
153  }
154  // add new line if neccessary
155  if (PrevY!=Y){
156  if ((MxY!=-1)&&(Ss->CellStrVV.Len()==MxY)){break;}
157  Ss->CellStrVV.Add(TStrVP::New()); PrevY=Y;
158  int Recs=Ss->CellStrVV.Len();
159  if (Recs%1000==0){
160  TNotify::OnStatus(Notify, TStr::Fmt(" %d\r", Recs));}
161  }
162  // add value to spreadsheet
163  if (AllowedColNV.Empty()||AllowedColNV.IsIn(X)){
164  Ss->CellStrVV[Y]->V.Add(ChA);
165  }
166  // process delimiters
167  if (SIn->Eof()){
168  break;
169  } else
170  if ((SsFmt==ssfTabSep)&&(Ch=='\t')){
171  X++; Ch=SIn->GetCh();
172  } else
173  if ((SsFmt==ssfCommaSep)&&(Ch==',')){
174  X++; Ch=SIn->GetCh();
175  } else
176  if ((SsFmt==ssfSemicolonSep)&&(Ch==';')){
177  X++; Ch=SIn->GetCh();
178  } else
179  if ((SsFmt==ssfVBar)&&(Ch=='|')){
180  X++; Ch=SIn->GetCh();
181  } else
182  if ((SsFmt==ssfSpaceSep)&&(Ch==' ')){
183  X++; Ch=SIn->GetCh();
184  } else
185  if (Ch=='\r'){
186  if ((PrevX!=-1)&&(X!=PrevX)){
187  TNotify::OnNotify(Notify, ntWarn, "Number of fields is not the same!");}
188  PrevX=X; X=0; Y++; Ch=SIn->GetCh();
189  if ((Ch=='\n')&&(!SIn->Eof())){Ch=SIn->GetCh();}
190  //if (Ss->CellStrVV.Len()%1000==0){Y--; break;}
191  } else
192  if (Ch=='\n'){
193  if ((PrevX!=-1)&&(X!=PrevX)){
194  TNotify::OnNotify(Notify, ntWarn, "Number of fields is not the same!");}
195  PrevX=X; X=0; Y++; Ch=SIn->GetCh();
196  if ((Ch=='\r')&&(!SIn->Eof())){Ch=SIn->GetCh();}
197  //if (Ss->CellStrVV.Len()%1000==0){Y--; break;}
198  } else {
199  Fail;
200  }
201  }
202  }
203  int Recs=Ss->CellStrVV.Len();
204  TNotify::OnNotify(Notify, ntInfo, TStr::Fmt(" %d records read.", Recs));
205  TNotify::OnNotify(Notify, ntInfo, "... Done.");
206  return Ss;
207 }
bool IsIn(const TVal &Val) const
Checks whether element Val is a member of the vector.
Definition: ds.h:797
#define forever
Definition: bd.h:6
#define Fail
Definition: bd.h:238
void Clr()
Definition: dt.h:258
Semicolon separated.
Definition: ss.h:8
Vertical bar separated.
Definition: ss.h:9
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
static PSs New()
Definition: ss.h:23
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
virtual bool Eof()=0
Definition: ut.h:28
Tab separated.
Definition: ss.h:6
virtual void OnNotify(const TNotifyType &, const TStr &)
Definition: ut.h:38
Space separated.
Definition: ss.h:10
Definition: dt.h:201
Definition: dt.h:412
virtual void OnStatus(const TStr &)
Definition: ut.h:39
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
Definition: ut.h:28
virtual char GetCh()=0
static TPt< PVec< TVal > > New()
Definition: ds.h:2118
Comma separated.
Definition: ss.h:7
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.

230  {
231  if (!SIn->Eof()){
232  FldValV.Clr(false); int X=0;
233  if (Ch==TCh::NullCh){Ch=SIn->GetCh();}
234  TChA ChA;
235  while (!SIn->Eof()){
236  // compose value
237  ChA.Clr();
238  if (IsQStr&&(Ch=='"')){
239  // quoted string ('""' sequence means '"')
240  Ch=SIn->GetCh();
241  forever {
242  while ((!SIn->Eof())&&(Ch!='"')){
243  ChA+=Ch; Ch=SIn->GetCh();}
244  if (Ch=='"'){
245  Ch=SIn->GetCh();
246  if (Ch=='"'){ChA+=Ch; Ch=SIn->GetCh();}
247  else {break;}
248  }
249  }
250  } else {
251  if (SsFmt==ssfTabSep){
252  while ((!SIn->Eof())&&(Ch!='\t')&&(Ch!='\r')&&
253  ((Ch!='\n')||IsExcelEoln)){
254  ChA+=Ch; Ch=SIn->GetCh();
255  }
256  if ((!ChA.Empty())&&(ChA.LastCh()=='\"')){
257  ChA.Pop();}
258  } else
259  if (SsFmt==ssfCommaSep){
260  while ((!SIn->Eof())&&(Ch!=',')&&(Ch!='\r')&&
261  ((Ch!='\n')||IsExcelEoln)){
262  ChA+=Ch; Ch=SIn->GetCh();
263  }
264  } else
265  if (SsFmt==ssfSemicolonSep){
266  while ((!SIn->Eof())&&(Ch!=';')&&(Ch!='\r')&&
267  ((Ch!='\n')||IsExcelEoln)){
268  ChA+=Ch; Ch=SIn->GetCh();
269  }
270  } else
271  if (SsFmt==ssfVBar){
272  while ((!SIn->Eof())&&(Ch!='|')&&(Ch!='\r')&&
273  ((Ch!='\n')||IsExcelEoln)){
274  ChA+=Ch; Ch=SIn->GetCh();
275  }
276  } else {
277  Fail;
278  }
279  }
280  // add value to spreadsheet
281  ChA.Trunc();
282  FldValV.Add(ChA);
283  // process delimiters
284  if (SIn->Eof()){
285  break;
286  } else
287  if ((SsFmt==ssfTabSep)&&(Ch=='\t')){
288  X++; Ch=SIn->GetCh();
289  } else
290  if ((SsFmt==ssfCommaSep)&&(Ch==',')){
291  X++; Ch=SIn->GetCh();
292  } else
293  if ((SsFmt==ssfSemicolonSep)&&(Ch==';')){
294  X++; Ch=SIn->GetCh();
295  } else
296  if ((SsFmt==ssfVBar)&&(Ch=='|')){
297  X++; Ch=SIn->GetCh();
298  } else
299  if (Ch=='\r'){
300  Ch=SIn->GetCh();
301  if ((Ch=='\n')&&(!SIn->Eof())){Ch=SIn->GetCh();}
302  break;
303  } else
304  if (Ch=='\n'){
305  X=0; Ch=SIn->GetCh();
306  if ((Ch=='\r')&&(!SIn->Eof())){Ch=SIn->GetCh();}
307  break;
308  } else {
309  Fail;
310  }
311  }
312  }
313 }
#define forever
Definition: bd.h:6
bool Empty() const
Definition: dt.h:260
#define Fail
Definition: bd.h:238
static const char NullCh
Definition: dt.h:943
void Clr()
Definition: dt.h:258
Semicolon separated.
Definition: ss.h:8
Vertical bar separated.
Definition: ss.h:9
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
virtual bool Eof()=0
char LastCh() const
Definition: dt.h:281
Tab separated.
Definition: ss.h:6
void Trunc()
Definition: dt.cpp:420
Definition: dt.h:201
virtual char GetCh()=0
char Pop()
Definition: dt.h:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
Comma separated.
Definition: ss.h:7
static PSs TSs::New ( )
inlinestatic

Definition at line 23 of file ss.h.

23 {return PSs(new TSs());}
TSs()
Definition: ss.h:22
TPt< TSs > PSs
Definition: ss.h:18
TSs& TSs::operator= ( const TSs Ss)
inline

Definition at line 29 of file ss.h.

29  {
30  if (this!=&Ss){CellStrVV=Ss.CellStrVV;} return *this;}
TVec< PStrV > CellStrVV
Definition: ss.h:20
void TSs::PutVal ( const int &  X,
const int &  Y,
const TStr Str 
)

Definition at line 10 of file ss.cpp.

10  {
11  if (Y>=CellStrVV.Len()){CellStrVV.Reserve(Y+1, Y+1);}
12  if (X>=CellStrVV[Y]->Len()){CellStrVV[Y]->V.Reserve(X+1, X+1);}
13  CellStrVV[Y]->V[X]=Str;
14 }
TVec< PStrV > CellStrVV
Definition: ss.h:20
void TSs::Save ( TSOut SOut)
inline

Definition at line 27 of file ss.h.

27 {CellStrVV.Save(SOut);}
TVec< PStrV > CellStrVV
Definition: ss.h:20
void TSs::SaveTxt ( const TStr FNm,
const PNotify Notify = NULL 
) const

Definition at line 209 of file ss.cpp.

209  {
210  PSOut SOut=TFOut::New(FNm);
211  for (int Y=0; Y<CellStrVV.Len(); Y++){
212  for (int X=0; X<CellStrVV[Y]->Len(); X++){
213  if (X>0){SOut->PutCh('\t');}
214  TStr Str=CellStrVV[Y]->V[X];
215  TChA ChA(Str);
216  for (int ChN=0; ChN<ChA.Len(); ChN++){
217  char Ch=ChA[ChN];
218  if ((Ch=='\t')||(Ch=='\r')||(Ch=='\n')){
219  ChA.PutCh(ChN, ' ');
220  }
221  }
222  SOut->PutStr(ChA);
223  }
224  SOut->PutCh('\r'); SOut->PutCh('\n');
225  }
226 }
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
Definition: dt.h:201
TVec< PStrV > CellStrVV
Definition: ss.h:20
Definition: dt.h:412
Definition: bd.h:196
int TSs::SearchX ( const int &  Y,
const TStr Str 
) const

Definition at line 51 of file ss.cpp.

51  {
52  return CellStrVV[Y]->V.SearchForw(Str);
53 }
TVec< PStrV > CellStrVV
Definition: ss.h:20
int TSs::SearchY ( const int &  X,
const TStr Str 
) const

Definition at line 55 of file ss.cpp.

55  {
56  int YLen=GetYLen();
57  for (int Y=0; Y<YLen; Y++){
58  if (Str==GetVal(X, Y)){return Y;}}
59  return -1;
60 }
int GetYLen() const
Definition: ss.cpp:47
TStr GetVal(const int &X, const int &Y) const
Definition: ss.cpp:16

Friends And Related Function Documentation

friend class TPt< TSs >
friend

Definition at line 18 of file ss.h.

Member Data Documentation

TVec<PStrV> TSs::CellStrVV
private

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: