SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
dt.cpp
Go to the documentation of this file.
1 // Random
3 const int TRnd::RndSeed=0;
4 const int TRnd::a=16807;
5 const int TRnd::m=2147483647;
6 const int TRnd::q=127773; // m DIV a
7 const int TRnd::r=2836; // m MOD a
8 
9 void TRnd::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
10  XLoadHd(Nm);
11  Seed=TXmlObjSer::GetIntArg(XmlTok, "Seed");
12 }
13 
14 void TRnd::SaveXml(TSOut& SOut, const TStr& Nm) const {
15  XSaveBETagArg(Nm, "Seed", TInt::GetStr(Seed));
16 }
17 
18 void TRnd::PutSeed(const int& _Seed){
19  Assert(_Seed>=0);
20  if (_Seed==0){
21  //Seed=int(time(NULL));
22  Seed=abs(int(TSysTm::GetPerfTimerTicks()));
23  } else {
24  Seed=_Seed;
25  //Seed=abs(_Seed*100000)+1;
26  }
27 }
28 
29 void TRnd::Move(const int& Steps){
30  for (int StepN=0; StepN<Steps; StepN++){GetNextSeed();}
31 }
32 
33 bool TRnd::Check(){
34  int PSeed=Seed; Seed=1;
35  for (int SeedN=0; SeedN<10000; SeedN++){GetNextSeed();}
36  bool Ok=Seed==1043618065; Seed=PSeed; return Ok;
37 }
38 
39 int TRnd::GetUniDevInt(const int& Range){
40  int Seed=GetNextSeed();
41  if (Range==0){return Seed;}
42  else {return Seed%Range;}
43 }
44 
46  uint Seed=uint(GetNextSeed()%0x10000)*0x10000+uint(GetNextSeed()%0x10000);
47  if (Range==0){return Seed;}
48  else {return Seed%Range;}
49 }
50 
52  const int64 RndVal = int64((uint64(GetUniDevInt())<<32) | uint64(GetUniDevInt()));
53  if (Range==0){return RndVal;}
54  else {return RndVal%Range;}
55 }
56 
58  const uint64 RndVal = uint64((uint64(GetUniDevInt())<<32) | uint64(GetUniDevInt()));
59  if (Range==0){return RndVal;}
60  else {return RndVal%Range;}
61 }
62 
63 double TRnd::GetNrmDev(){
64  double v1, v2, rsq;
65  do {
66  v1=2.0*GetUniDev()-1.0; // pick two uniform numbers in the square
67  v2=2.0*GetUniDev()-1.0; // extending from -1 to +1 in each direction
68  rsq=v1*v1+v2*v2; // see if they are in the unit cicrcle
69  } while ((rsq>=1.0)||(rsq==0.0)); // and if they are not, try again
70  double fac=sqrt(-2.0*log(rsq)/rsq); // Box-Muller transformation
71  return v1*fac;
72 // return v2*fac; // second deviate
73 }
74 
76  const double& Mean, const double& SDev, const double& Mn, const double& Mx){
77  double Val=Mean+GetNrmDev()*SDev;
78  if (Val<Mn){Val=Mn;}
79  if (Val>Mx){Val=Mx;}
80  return Val;
81 }
82 
83 double TRnd::GetExpDev(){
84  double UniDev;
85  do {
86  UniDev=GetUniDev();
87  } while (UniDev==0.0);
88  return -log(UniDev);
89 }
90 
91 double TRnd::GetExpDev(const double& Lambda) {
92  return GetExpDev()/Lambda;
93 }
94 
95 double TRnd::GetGammaDev(const int& Order){
96  int j;
97  double am,e,s,v1,v2,x,y;
98  if (Order<1){Fail;}
99  if (Order<6) {
100  x=1.0;
101  for (j=1;j<=Order;j++) x *=GetUniDev();
102  x = -log(x);
103  } else {
104  do {
105  do {
106  do {
107  v1=2.0*GetUniDev()-1.0;
108  v2=2.0*GetUniDev()-1.0;
109  } while (v1*v1+v2*v2 > 1.0);
110  y=v2/v1;
111  am=Order-1;
112  s=sqrt(2.0*am+1.0);
113  x=s*y+am;
114  } while (x <= 0.0);
115  e=(1.0+y*y)*exp(am*log(x/am)-s*y);
116  } while (GetUniDev()>e);
117  }
118  return x;
119 }
120 
121 double TRnd::GetPoissonDev(const double& Mean){
122  static double sq,alxm,g,oldm=(-1.0);
123  double em,t,y;
124  if (Mean < 12.0) {
125  if (Mean != oldm) {
126  oldm=Mean;
127  g=exp(-Mean);
128  }
129  em = -1;
130  t=1.0;
131  do {
132  ++em;
133  t *= GetUniDev();
134  } while (t>g);
135  } else {
136  if (Mean != oldm) {
137  oldm=Mean;
138  sq=sqrt(2.0*Mean);
139  alxm=log(Mean);
140  g=Mean*alxm-TSpecFunc::LnGamma(Mean+1.0);
141  }
142  do {
143  do {
144  y=tan(TMath::Pi*GetUniDev());
145  em=sq*y+Mean;
146  } while (em < 0.0);
147  em=floor(em);
148  t=0.9*(1.0+y*y)*exp(em*alxm-TSpecFunc::LnGamma(em+1.0)-g);
149  } while (GetUniDev()>t);
150  }
151  return em;
152 }
153 
154 double TRnd::GetBinomialDev(const double& Prb, const int& Trials){
155  int j;
156  static int nold=(-1);
157  double am,em,g,angle,p,bnl,sq,t,y;
158  static double pold=(-1.0),pc,plog,pclog,en,oldg;
159 
160  p=(Prb <= 0.5 ? Prb : 1.0-Prb);
161  am=Trials*p;
162  if (Trials < 25) {
163  bnl=0.0;
164  for (j=1;j<=Trials;j++)
165  if (GetUniDev() < p) ++bnl;
166  } else if (am < 1.0) {
167  g=exp(-am);
168  t=1.0;
169  for (j=0;j<=Trials;j++) {
170  t *= GetUniDev();
171  if (t < g) break;
172  }
173  bnl=(j <= Trials ? j : Trials);
174  } else {
175  if (Trials != nold) {
176  en=Trials;
177  oldg=TSpecFunc::LnGamma(en+1.0);
178  nold=Trials;
179  } if (p != pold) {
180  pc=1.0-p;
181  plog=log(p);
182  pclog=log(pc);
183  pold=p;
184  }
185  sq=sqrt(2.0*am*pc);
186  do {
187  do {
188  angle=TMath::Pi*GetUniDev();
189  y=tan(angle);
190  em=sq*y+am;
191  } while (em < 0.0 || em >= (en+1.0));
192  em=floor(em);
193  t=1.2*sq*(1.0+y*y)*exp(oldg-(em+1.0)
194  -TSpecFunc::LnGamma(en-em+1.0)+em*plog+(en-em)*pclog);
195  } while (GetUniDev() > t);
196  bnl=em;
197  }
198  if (p != Prb) bnl=Trials-bnl;
199  return bnl;
200 }
201 
202 // sample points from d-dimensional unit sphere
203 /*void TRnd::GetSphereDev(const int& Dim, TFltV& ValV) {
204  if (ValV.Len() != Dim) { ValV.Gen(Dim); }
205  double Length = 0.0;
206  for (int i = 0; i < Dim; i++) {
207  ValV[i] = GetNrmDev();
208  Length += TMath::Sqr(ValV[i]); }
209  Length = 1.0 / sqrt(Length);
210  for (int i = 0; i < Dim; i++) {
211  ValV[i] *= Length;
212  }
213 }*/
214 
216  return TRnd(Lx.GetInt());
217 }
218 
219 void TRnd::SaveTxt(TOLx& Lx) const {
220  Lx.PutInt(Seed);
221 }
222 
224 // Memory
225 void TMem::Resize(const int& _MxBfL){
226  if (_MxBfL<=MxBfL){return;}
227  else {if (MxBfL*2<_MxBfL){MxBfL=_MxBfL;} else {MxBfL*=2;}}
228  char* NewBf=new char[MxBfL]; IAssert(NewBf!=NULL);
229  if (BfL>0){memcpy(NewBf, Bf, BfL);}
230  if (Bf!=NULL){delete[] Bf;}
231  Bf=NewBf;
232 }
233 
234 TMem::TMem(const TStr& Str):
235  MxBfL(Str.Len()), BfL(MxBfL), Bf(NULL){
236  if (MxBfL>0){
237  Bf=new char[MxBfL];
238  if (BfL>0){memcpy(Bf, Str.CStr(), BfL);}
239  }
240 }
241 
242 void TMem::SaveXml(TSOut& SOut, const TStr& Nm) const {
243  XSaveHdArg(Nm, "BfL", TInt::GetStr(BfL));
245 }
246 
247 bool TMem::DoFitStr(const TStr& Str) const {
248  return DoFitLen(Str.Len()+1);
249 }
250 
251 TMem& TMem::operator+=(const char& Ch){
252  if (BfL==MxBfL){Resize(BfL+1);}
253  Bf[BfL]=Ch; BfL++; return *this;
254 }
255 
257  int LBfL=Mem.Len(); if (BfL+LBfL>MxBfL){Resize(BfL+LBfL);}
258  if (LBfL>0){memcpy(&Bf[BfL], Mem(), LBfL);}
259  BfL+=LBfL; return *this;
260 }
261 
263  int LBfL=Str.Len(); if (BfL+LBfL>MxBfL){Resize(BfL+LBfL);}
264  if (LBfL>0){memcpy(Bf+BfL, Str.CStr(), LBfL);}
265  BfL+=LBfL; return *this;
266 }
267 
269  int LBfL=SIn->Len(); if (BfL+LBfL>MxBfL){Resize(BfL+LBfL);}
270  char* LBf=new char[LBfL];
271  SIn->GetBf(LBf, LBfL);
272  if (LBfL>0){memcpy(Bf+BfL, LBf, LBfL);}
273  delete[] LBf;
274  BfL+=LBfL; return *this;
275 }
276 
277 void TMem::Del(const int& BChN, const int& EChN){
278  if (BChN>EChN){return;}
279  if ((BChN==0)&&(EChN==BfL-1)){Clr(); return;}
280  IAssert((0<=BChN)&&(BChN<=EChN)&&(EChN<BfL));
281  memmove(Bf+BChN, Bf+EChN+1, BfL-EChN-1);
282  BfL-=(EChN-BChN+1);
283 }
284 
285 //int TMem::AddStr(const TStr& Str){
286 // int LBfL=Str.Len()+1; Resize(BfL+LBfL);
287 // if (LBfL>0){memcpy(&Bf[BfL], Str.CStr(), LBfL);}
288 // int FChN=BfL; BfL+=LBfL; return FChN;
289 //}
290 
291 void TMem::AddBf(const void* _Bf, const int& _BfL){
292  IAssert((_BfL>=0) && (_Bf != NULL));
293  Reserve(Len() + _BfL, false);
294  memcpy(Bf + BfL, _Bf, _BfL);
295  BfL+=_BfL;
296  //char* ChBf=(char*)Bf;
297  //for (int BfC=0; BfC<BfL; BfC++){
298  // char Ch=ChBf[BfC];
299  // operator+=(Ch);
300  //}
301 }
302 
303 TStr TMem::GetAsStr(const char& NewNullCh) const {
304  if (NewNullCh!='\0'){
305  TChA ChA(*this);
306  ChA.ChangeCh('\0', NewNullCh);
307  return ChA;
308  } else {
309  return TStr(*this);
310  }
311 }
312 
314 // Input-Memory
315 TMemIn::TMemIn(const TMem& _Mem, const int& _BfC):
316  TSBase("Input-Memory"), TSIn("Input-Memory"), Mem(), Bf(_Mem()), BfC(_BfC), BfL(_Mem.Len()){}
317 
318 int TMemIn::GetBf(const void* LBf, const TSize& LBfL){
319  Assert(TSize(BfC+LBfL)<=TSize(BfL));
320  int LBfS=0;
321  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
322  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
323  return LBfS;
324 }
325 
327  // not implemented
328  FailR(TStr::Fmt("TMemIn::GetNextLnBf: not implemented").CStr());
329  return false;
330 }
331 
333 // Output-Memory
334 TMemOut::TMemOut(const PMem& _Mem): TSBase("Output-Memory"), TSOut("Output-Memory"), Mem(_Mem){}
335 
336 int TMemOut::PutBf(const void* LBf, const TSize& LBfL){
337  int LBfS=0;
338  TMem& _Mem=*Mem;
339  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
340  char Ch=((char*)LBf)[LBfC];
341  LBfS+=Ch; _Mem+=Ch;
342  }
343  return LBfS;
344 }
345 
347 // Char-Array
348 void TChA::Resize(const int& _MxBfL){
349  if (_MxBfL<=MxBfL){return;}
350  else {if (MxBfL*2<_MxBfL){MxBfL=_MxBfL;} else {MxBfL*=2;}}
351  char* NewBf=new char[MxBfL+1]; IAssert(NewBf!=NULL);
352  strcpy(NewBf, Bf);
353  delete[] Bf; Bf=NewBf;
354 }
355 
356 TChA::TChA(const TStr& Str){
357  Bf=new char[(MxBfL=BfL=Str.Len())+1];
358  strcpy(Bf, Str.CStr());
359 }
360 
361 void TChA::SaveXml(TSOut& SOut, const TStr& Nm) const {
362  XSaveHdArg(Nm, "BfL", TInt::GetStr(BfL));
364 }
365 
366 TChA& TChA::operator=(const TChA& ChA){
367  if (this!=&ChA){
368  if (ChA.BfL>MxBfL){delete[] Bf; Bf=new char[(MxBfL=ChA.BfL)+1];}
369  BfL=ChA.BfL; strcpy(Bf, ChA.CStr());
370  }
371  return *this;
372 }
373 
374 TChA& TChA::operator=(const TStr& Str){
375  if (Str.Len()>MxBfL){delete[] Bf; Bf=new char[(MxBfL=Str.Len())+1];}
376  BfL=Str.Len(); strcpy(Bf, Str.CStr());
377  return *this;
378 }
379 
380 TChA& TChA::operator=(const char* CStr){
381  int CStrLen=int(strlen(CStr));
382  if (CStrLen>MxBfL){delete[] Bf; Bf=new char[(MxBfL=CStrLen)+1];}
383  BfL=CStrLen; strcpy(Bf, CStr);
384  return *this;
385 }
386 
387 TChA& TChA::operator+=(const TMem& Mem) {
388  Resize(BfL+Mem.Len());
389  strcpy(Bf+BfL, Mem.GetBf()); BfL+=Mem.Len(); return *this;
390 }
391 
393  Resize(BfL+ChA.Len());
394  strcpy(Bf+BfL, ChA.CStr()); BfL+=ChA.Len(); return *this;
395 }
396 
398  Resize(BfL+Str.Len());
399  strcpy(Bf+BfL, Str.CStr()); BfL+=Str.Len(); return *this;
400 }
401 
402 TChA& TChA::operator+=(const char* CStr){
403  int CStrLen=(int)strlen(CStr); Resize(BfL+CStrLen);
404  strcpy(Bf+BfL, CStr); BfL+=CStrLen; return *this;
405 }
406 
407 void TChA::Ins(const int& BChN, const char* CStr){
408  Assert((0<=BChN)&&(BChN<=BfL)); //** ali je <= v (BChN<=BfL) upravicen?
409  int CStrLen=int(strlen(CStr)); Resize(BfL+CStrLen);
410  memmove(Bf+BChN+CStrLen, Bf+BChN, BfL-BChN+1);
411  memmove(Bf+BChN, CStr, CStrLen); BfL+=CStrLen;
412 }
413 
414 void TChA::Del(const int& ChN){
415  Assert((0<=ChN)&&(ChN<BfL));
416  memmove(Bf+ChN, Bf+ChN+1, BfL-ChN);
417  BfL--;
418 }
419 
420 void TChA::Trunc(){
421  int BChN=0; while ((BChN<BfL)&&(GetCh(BChN)<=' ')){BChN++;}
422  int EChN=BfL-1; while ((0<=EChN)&&(GetCh(EChN)<=' ')){EChN--;}
423  if (BChN<=EChN){
424  for (int ChN=BChN; ChN<=EChN; ChN++){
425  PutCh(ChN-BChN, GetCh(ChN));}
426  Trunc(EChN-BChN+1);
427  } else {
428  Clr();
429  }
430 /* int BChN=0; while ((BChN<BfL)&&(Bf[BChN]<=' ')){BChN++;}
431  int EChN=BfL-1; while ((0<=EChN)&&(Bf[EChN]<=' ')){EChN--;}
432  if (BChN<=EChN){
433  for (int ChN=BChN; ChN<=EChN; ChN++){Bf[ChN-BChN]=Bf[ChN];}
434  Bf[BfL=EChN+1]=0;
435  } else {
436  Clr();
437  }*/
438 }
439 
441  for (int ChN=0; ChN<BfL/2; ChN++){
442  char Ch=Bf[ChN];
443  Bf[ChN]=Bf[BfL-ChN-1];
444  Bf[BfL-ChN-1]=Ch;
445  }
446 }
447 
448 TChA TChA::GetSubStr(const int& _BChN, const int& _EChN) const {
449  int BChN=TInt::GetMx(_BChN, 0);
450  int EChN=TInt::GetMn(_EChN, Len()-1);
451  int Chs=EChN-BChN+1;
452  if (Chs<=0){return TStr::GetNullStr();}
453  else if (Chs==Len()){return *this;}
454  else {
455  //char* Bf=new char[Chs+1]; strncpy(Bf, CStr()+BChN, Chs); Bf[Chs]=0;
456  //TStr Str(Bf); delete[] Bf;
457  //return Str;
458  return TChA(CStr()+BChN, Chs);
459  }
460 }
461 
462 int TChA::CountCh(const char& Ch, const int& BChN) const {
463  int ChN=TInt::GetMx(BChN, 0);
464  const int ThisLen=Len();
465  int Cnt = 0;
466  while (ChN<ThisLen){if (Bf[ChN]==Ch){ Cnt++;} ChN++;}
467  return Cnt;
468 }
469 
470 int TChA::SearchCh(const char& Ch, const int& BChN) const {
471  int ChN=TInt::GetMx(BChN, 0);
472  const int ThisLen=Len();
473  while (ChN<ThisLen){if (Bf[ChN]==Ch){return ChN;} ChN++;}
474  return -1;
475 }
476 
477 int TChA::SearchChBack(const char& Ch, int BChN) const {
478  if (BChN >= Len() || BChN < 0) { BChN = Len()-1; }
479  for (int i = BChN; i >= 0; i--) {
480  if (GetCh(i) == Ch) { return i; }
481  }
482  return -1;
483 }
484 
485 int TChA::SearchStr(const TChA& Str, const int& BChN) const {
486  return SearchStr(Str.CStr(), BChN);
487 }
488 
489 int TChA::SearchStr(const TStr& Str, const int& BChN) const {
490  return SearchStr(Str.CStr(), BChN);
491 }
492 
493 int TChA::SearchStr(const char* CStr, const int& BChN) const {
494  const char* BegPos=strstr(Bf+BChN, CStr);
495  if (BegPos==NULL){return -1;}
496  else {return int(BegPos-Bf);}
497 }
498 
499 bool TChA::IsPrefix(const char* CStr, const int& BChN) const {
500  if (BChN+(int)strlen(CStr)>Len()){return false;}
501  const char* B = Bf+BChN;
502  const char* C = CStr;
503  while (*C!=0 && *B==*C) {
504  B++; C++;
505  }
506  if (*C==0){return true;}
507  else {return false;}
508 }
509 
510 bool TChA::IsPrefix(const TStr& Str) const {
511  return IsPrefix(Str.CStr());
512 }
513 
514 bool TChA::IsPrefix(const TChA& Str) const {
515  return IsPrefix(Str.CStr());
516 }
517 
518 bool TChA::IsSuffix(const char* CStr) const {
519  if ((int)strlen(CStr) > Len()) { return false; }
520  const char* E = Bf+Len()-1;
521  const char* C = CStr+strlen(CStr)-1;
522  while (C >= CStr && *E==*C) {
523  E--; C--;
524  }
525  if (C+1 == CStr) { return true; }
526  else { return false; }
527 }
528 
529 bool TChA::IsSuffix(const TStr& Str) const {
530  return IsSuffix(Str.CStr());
531 }
532 
533 bool TChA::IsSuffix(const TChA& Str) const {
534  return IsSuffix(Str.CStr());
535 }
536 
537 void TChA::ChangeCh(const char& SrcCh, const char& DstCh){
538  int StrLen=Len();
539  for (int ChN=0; ChN<StrLen; ChN++){if (Bf[ChN]==SrcCh){Bf[ChN]=DstCh;}}
540 }
541 
542 /*void TChA::ToUc(){
543  int StrLen=Len();
544  for (int ChN=0; ChN<StrLen; ChN++){Bf[ChN]=(char)toupper(Bf[ChN]);}
545 }
546 
547 void TChA::ToLc(){
548  int StrLen=Len();
549  for (int ChN=0; ChN<StrLen; ChN++){Bf[ChN]=(char)tolower(Bf[ChN]);}
550 }*/
551 
553  char *c = Bf;
554  while (*c) {
555  *c = (char) tolower(*c); c++;
556  }
557  return *this;
558 }
559 
561  char *c = Bf;
562  while (*c) {
563  *c = (char) toupper(*c); c++;
564  }
565  return *this;
566 }
567 
569  int StrLen=Len(); int BChN=0; int EChN=StrLen-1;
570  while ((BChN<StrLen)&&TCh::IsWs(GetCh(BChN))){BChN++;}
571  while ((EChN>=0)&&TCh::IsWs(GetCh(EChN))){EChN--;}
572  if ((BChN!=0)||(EChN!=StrLen-1)){
573  int DstChN=0;
574  for (int SrcChN=BChN; SrcChN<=EChN; SrcChN++){
575  PutCh(DstChN, GetCh(SrcChN)); DstChN++;}
576  Trunc(DstChN);
577  }
578  return *this;
579 }
580 
582  int StrLen=Len(); int SrcChN=0; int DstChN=0;
583  while ((SrcChN<StrLen)&&TCh::IsWs(GetCh(SrcChN))){SrcChN++;}
584  while (SrcChN<StrLen){
585  if ((TCh::IsWs(GetCh(SrcChN)))&&(DstChN>0)&&(TCh::IsWs(GetCh(DstChN-1)))){
586  SrcChN++;
587  } else {
588  PutCh(DstChN, GetCh(SrcChN)); SrcChN++; DstChN++;
589  }
590  }
591  if ((DstChN>0)&&(TCh::IsWs(GetCh(DstChN-1)))){DstChN--;}
592  Trunc(DstChN);
593 }
594 
595 void TChA::Swap(const int& ChN1, const int& ChN2){
596  char Ch=GetCh(ChN1);
597  PutCh(ChN1, GetCh(ChN2));
598  PutCh(ChN2, Ch);
599 }
600 
601 void TChA::Swap(TChA& ChA) {
602  ::Swap(MxBfL, ChA.MxBfL);
603  ::Swap(BfL, ChA.BfL);
604  ::Swap(Bf, ChA.Bf);
605 }
606 
607 int TChA::GetPrimHashCd() const {
609 }
610 
611 int TChA::GetSecHashCd() const {
613 }
614 
615 
616 void TChA::LoadTxt(const PSIn& SIn, TChA& ChA){
617  delete[] ChA.Bf;
618  ChA.Bf=new char[(ChA.MxBfL=ChA.BfL=SIn->Len())+1];
619  SIn->GetBf(ChA.CStr(), SIn->Len()); ChA.Bf[ChA.BfL]=0;
620 }
621 
622 void TChA::SaveTxt(const PSOut& SOut) const {
623  SOut->SaveBf(CStr(), Len());
624 }
625 
626 /*TChA operator+(const TChA& LStr, const TChA& RStr){
627  return LStr+=RStr; }
628 }
629 
630 TChA operator+(const TChA& LStr, const TStr& RStr){
631  return LStr+=RStr.CStr();
632 }
633 
634 TChA operator+(const TStr& LStr, const char* RCStr){
635  return LStr+=RCStr;
636 }*/
637 
638 
640 // Input-Char-Array
641 TChAIn::TChAIn(const TChA& ChA, const int& _BfC):
642  TSBase("Input-Char-Array"), TSIn("Input-Char-Array"), Bf(ChA.CStr()), BfC(_BfC), BfL(ChA.Len()){}
643 
644 int TChAIn::GetBf(const void* LBf, const TSize& LBfL){
645  Assert(TSize(BfC+LBfL)<=TSize(BfL));
646  int LBfS=0;
647  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
648  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
649  return LBfS;
650 }
651 
653  // not implemented
654  FailR(TStr::Fmt("TChAIn::GetNextLnBf: not implemented").CStr());
655  return false;
656 }
657 
659 // Ref-String
660 bool TRStr::IsUc() const {
661  int StrLen=Len();
662  for (int ChN=0; ChN<StrLen; ChN++){
663  if (('a'<=Bf[ChN])&&(Bf[ChN]<='z')){return false;}}
664  return true;
665 }
666 
667 void TRStr::ToUc(){
668  int StrLen=Len();
669  for (int ChN=0; ChN<StrLen; ChN++){
670  Bf[ChN]=(char)toupper(Bf[ChN]);}}
671 
672 bool TRStr::IsLc() const {
673  int StrLen=Len();
674  for (int ChN=0; ChN<StrLen; ChN++){
675  if (('A'<=Bf[ChN])&&(Bf[ChN]<='Z')){return false;}}
676  return true;
677 }
678 
679 void TRStr::ToLc(){
680  int StrLen=Len();
681  for (int ChN=0; ChN<StrLen; ChN++){
682  Bf[ChN]=(char)tolower(Bf[ChN]);}
683 }
684 
686  int StrLen=Len();
687  if (StrLen>0){
688  Bf[0]=(char)toupper(Bf[0]);}
689  for (int ChN=1; ChN<StrLen; ChN++){
690  Bf[ChN]=(char)tolower(Bf[ChN]);}
691 }
692 
694  int StrLen=Len();
695  for (int ChN=0; ChN<StrLen; ChN++){
696  Bf[ChN]=TCh::GetUsFromYuAscii(Bf[ChN]);}
697 }
698 
699 int TRStr::CmpI(const char* p, const char* r){
700  if (!p){return r ? (*r ? -1 : 0) : 0;}
701  if (!r){return (*p ? 1 : 0);}
702  while (*p && *r){
703  int i=int(toupper(*p++))-int(toupper(*r++));
704  if (i!=0){return i;}
705  }
706  return int(toupper(*p++))-int(toupper(*r++));
707 }
708 
709 int TRStr::GetPrimHashCd() const {
711 }
712 
713 int TRStr::GetSecHashCd() const {
715 }
716 
718 // String
719 TRStr* TStr::GetRStr(const char* CStr){
720  int CStrLen;
721  if (CStr==NULL){CStrLen=0;} else {CStrLen=int(strlen(CStr));}
722  if (CStrLen==0){return TRStr::GetNullRStr();}
723  // next lines are not multi-threading safe
724  //else if (CStrLen==1){return GetChStr(CStr[0]).RStr;}
725  //else if (CStrLen==2){return GetDChStr(CStr[0], CStr[1]).RStr;}
726  else {return new TRStr(CStr);}
727 }
728 
730  char* CStr=RStr->CStr(); int CStrLen=int(strlen(CStr));
731  TRStr* NewRStr;
732  if (CStrLen==0){NewRStr=TRStr::GetNullRStr();}
733  // next lines are not multi-threading safe
734  //else if (CStrLen==1){NewRStr=GetChStr(CStr[0]).RStr;}
735  //else if (CStrLen==2){NewRStr=GetDChStr(CStr[0], CStr[1]).RStr;}
736  else {NewRStr=RStr;}
737  NewRStr->MkRef(); RStr->UnRef(); RStr=NewRStr;
738 }
739 
740 void TStr::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
741  XLoadHd(Nm);
742  TStr TokStr=XmlTok->GetTokStr(false);
743  operator=(TokStr);
744 }
745 
746 void TStr::SaveXml(TSOut& SOut, const TStr& Nm) const {
747  TStr XmlStr=TXmlLx::GetXmlStrFromPlainStr(*this);
748  if (XmlStr.Empty()){XSaveBETag(Nm);}
749  else {XSaveHd(Nm); SOut.PutStr(XmlStr);}
750 }
751 
753  TRStr* NewRStr=new TRStr(RStr->CStr()); NewRStr->ToUc();
754  RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
755  Optimize(); return *this;
756 }
757 
759  TRStr* NewRStr=new TRStr(RStr->CStr()); NewRStr->ToLc();
760  RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
761  Optimize(); return *this;
762 }
763 
765  TRStr* NewRStr=new TRStr(RStr->CStr()); NewRStr->ToCap();
766  RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
767  Optimize(); return *this;
768 }
769 
771  int ThisLen=Len(); char* ThisBf=CStr();
772  int BChN=0; int EChN=ThisLen-1;
773  while ((BChN<ThisLen)&&TCh::IsWs(ThisBf[BChN])){BChN++;}
774  while ((EChN>=0)&&TCh::IsWs(ThisBf[EChN])){EChN--;}
775  *this=GetSubStr(BChN, EChN);
776  return *this;
777 }
778 
780  TRStr* NewRStr=new TRStr(RStr->CStr()); NewRStr->ConvUsFromYuAscii();
781  RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
782  Optimize(); return *this;
783 }
784 
786  TChA ChA;
787  int StrLen=Len();
788  for (int ChN=0; ChN<StrLen; ChN++){
789  uchar Ch=uchar(RStr->Bf[ChN]);
790  char MshCh=TCh::GetHexCh((Ch/16)%16);
791  char LshCh=TCh::GetHexCh(Ch%16);
792  ChA+=MshCh; ChA+=LshCh;
793  }
794  *this=ChA;
795  return *this;
796 }
797 
799  int StrLen=Len(); IAssert(StrLen%2==0);
800  TChA ChA; int ChN=0;
801  while (ChN<StrLen){
802  char MshCh=RStr->Bf[ChN]; ChN++;
803  char LshCh=RStr->Bf[ChN]; ChN++;
804  uchar Ch=uchar(TCh::GetHex(MshCh)*16+TCh::GetHex(LshCh));
805  ChA+=Ch;
806  }
807  *this=ChA;
808  return *this;
809 }
810 
811 TStr TStr::GetSubStr(const int& _BChN, const int& _EChN) const {
812  int StrLen=Len();
813  int BChN=TInt::GetMx(_BChN, 0);
814  int EChN=TInt::GetMn(_EChN, StrLen-1);
815  int Chs=EChN-BChN+1;
816  if (Chs<=0){return TStr();}
817  else if (Chs==StrLen){return *this;}
818  else {
819  char* Bf=new char[Chs+1]; strncpy(Bf, CStr()+BChN, Chs); Bf[Chs]=0;
820  TStr Str(Bf); delete[] Bf;
821  return Str;
822  }
823 }
824 
825 void TStr::InsStr(const int& BChN, const TStr& Str){
826  int ThisLen=Len();
827  IAssert((0<=BChN)&&(BChN<=ThisLen));
828  TStr NewStr;
829  if (BChN==0){
830  NewStr=Str+*this;
831  } else
832  if (BChN==ThisLen){
833  NewStr=*this+Str;
834  } else {
835  NewStr=GetSubStr(0, BChN-1)+Str+GetSubStr(BChN, ThisLen-1);
836  }
837  *this=NewStr;
838 }
839 
840 void TStr::DelChAll(const char& Ch){
841  TChA ChA(*this);
842  int ChN=ChA.SearchCh(Ch);
843  while (ChN!=-1){
844  ChA.Del(ChN);
845  ChN=ChA.SearchCh(Ch);
846  }
847  *this=ChA;
848 }
849 
850 void TStr::DelSubStr(const int& _BChN, const int& _EChN){
851  int BChN=TInt::GetMx(_BChN, 0);
852  int EChN=TInt::GetMn(_EChN, Len()-1);
853  int Chs=Len()-(EChN-BChN+1);
854  if (Chs==0){Clr();}
855  else if (Chs<Len()){
856  char* Bf=new char[Chs+1]; strncpy(Bf, CStr(), BChN);
857  strncpy(Bf+BChN, CStr()+EChN+1, Len()-EChN-1); Bf[Chs]=0;
858  TStr Str(Bf); delete[] Bf;
859  *this=Str;
860  }
861 }
862 
863 bool TStr::DelStr(const TStr& Str){
864  int ChN=SearchStr(Str);
865  if (ChN==-1){
866  return false;
867  } else {
868  DelSubStr(ChN, ChN+Str.Len()-1);
869  return true;
870  }
871 }
872 
873 TStr TStr::LeftOf(const char& SplitCh) const {
874  int ThisLen=Len(); const char* ThisBf=CStr();
875  int ChN=0;
876  while ((ChN<ThisLen)&&(ThisBf[ChN]!=SplitCh)){ChN++;}
877  return (ChN==ThisLen) ? "" : GetSubStr(0, ChN-1);
878 }
879 
880 TStr TStr::LeftOfLast(const char& SplitCh) const {
881  const char* ThisBf=CStr();
882  int ChN=Len()-1;
883  while ((ChN>=0)&&(ThisBf[ChN]!=SplitCh)){ChN--;}
884  return (ChN==-1) ? "" : GetSubStr(0, ChN-1);
885 }
886 
887 TStr TStr::RightOf(const char& SplitCh) const {
888  int ThisLen=Len(); const char* ThisBf=CStr();
889  int ChN=0;
890  while ((ChN<ThisLen)&&(ThisBf[ChN]!=SplitCh)){ChN++;}
891  return (ChN==ThisLen) ? "" : GetSubStr(ChN+1, ThisLen-1);
892 }
893 
894 TStr TStr::RightOfLast(const char& SplitCh) const {
895  int ThisLen=Len(); const char* ThisBf=CStr();
896  int ChN=Len()-1;
897  while ((ChN>=0)&&(ThisBf[ChN]!=SplitCh)){ChN--;}
898  return (ChN==-1) ? "" : GetSubStr(ChN+1, ThisLen-1);
899 }
900 
901 void TStr::SplitOnCh(TStr& LStr, const char& SplitCh, TStr& RStr) const {
902  int ThisLen=Len(); const char* ThisBf=CStr();
903  int ChN=0;
904  while ((ChN<ThisLen)&&(ThisBf[ChN]!=SplitCh)){ChN++;}
905  if (ChN==ThisLen){
906  LStr=GetSubStr(0, ThisLen-1); RStr="";
907  } else {
908  LStr=GetSubStr(0, ChN-1); RStr=GetSubStr(ChN+1, ThisLen-1);
909  }
910 }
911 
912 void TStr::SplitOnLastCh(TStr& LStr, const char& SplitCh, TStr& RStr) const {
913  int ThisLen=Len(); const char* ThisBf=CStr();
914  int ChN=Len()-1;
915  while ((ChN>=0)&&(ThisBf[ChN]!=SplitCh)){ChN--;}
916  if (ChN==-1){
917  LStr=""; RStr=*this;
918  } else
919  if (ChN==0){
920  LStr=""; RStr=GetSubStr(1, ThisLen-1);
921  } else {
922  LStr=GetSubStr(0, ChN-1); RStr=GetSubStr(ChN+1, ThisLen-1);
923  }
924 }
925 
927  const char& SplitCh, TStrV& StrV, const bool& SkipEmpty) const {
928  StrV.Clr();
929  char* Bf=new char[Len()+1];
930  strcpy(Bf, CStr());
931  char* CurStrBf=Bf;
932  forever{
933  char* BfC=CurStrBf;
934  while ((*BfC!=0)&&(*BfC!=SplitCh)){BfC++;}
935  bool IsEnd=(*BfC=='\0');
936  *BfC=0;
937  if ((BfC>CurStrBf)||(!SkipEmpty)){StrV.Add(TStr(CurStrBf));}
938  if (IsEnd){break;}
939  CurStrBf=BfC+1;
940  }
941  delete[] Bf;
942 }
943 
945  const TStr& SplitChStr, TStrV& StrV, const bool& SkipEmpty) const {
946  // reset string output-vector
947  StrV.Clr();
948  // prepare working-copy of string
949  char* Bf=new char[Len()+1];
950  strcpy(Bf, CStr());
951  char* CurStrBf=Bf; // pointer to current string
952  // prepare pointer to split-char-string
953  const char* SplitChBf=SplitChStr.CStr();
954  forever{
955  char* BfC=CurStrBf; // set the counter for working-string
956  while (*BfC!=0){
957  const char* SplitChBfC=SplitChBf; // set counter for split-char-string
958  while ((*SplitChBfC!=0)&&(*SplitChBfC!=*BfC)){SplitChBfC++;}
959  if (*SplitChBfC!=0){break;} // if split-char found
960  BfC++;
961  }
962  bool IsEnd=(*BfC==0);
963  *BfC=0;
964  if ((BfC>CurStrBf)||(!SkipEmpty)){StrV.Add(TStr(CurStrBf));}
965  if (IsEnd){break;}
966  CurStrBf=BfC+1;
967  }
968  // delete working-copy
969  delete[] Bf;
970 }
971 
972 void TStr::SplitOnWs(TStrV& StrV) const {
973  StrV.Clr();
974  char* Bf=new char[Len()+1];
975  strcpy(Bf, CStr());
976  char* StrBf=Bf;
977  forever{
978  while ((*StrBf!=0)&&(TCh::IsWs(*StrBf))){StrBf++;}
979  char* BfC=StrBf;
980  while ((*BfC!=0)&&(!TCh::IsWs(*BfC))){BfC++;}
981  bool IsEnd=(*BfC=='\0');
982  *BfC=0;
983  if (BfC>StrBf){StrV.Add(TStr(StrBf));}
984  if (IsEnd){break;}
985  StrBf=BfC+1;
986  }
987  delete[] Bf;
988 }
989 
990 void TStr::SplitOnNonAlNum(TStrV& StrV) const {
991  StrV.Clr();
992  char* Bf=new char[Len()+1];
993  strcpy(Bf, CStr());
994  char* StrBf=Bf;
995  forever{
996  while ((*StrBf!=0)&&(!TCh::IsAlNum(*StrBf))){StrBf++;}
997  char* BfC=StrBf;
998  while ((*BfC!=0)&&(TCh::IsAlNum(*BfC))){BfC++;}
999  bool IsEnd=(*BfC=='\0');
1000  *BfC=0;
1001  if (BfC>StrBf){StrV.Add(TStr(StrBf));}
1002  if (IsEnd){break;}
1003  StrBf=BfC+1;
1004  }
1005  delete[] Bf;
1006 }
1007 
1008 void TStr::SplitOnStr(const TStr& SplitStr, TStrV& StrV) const {
1009  StrV.Clr();
1010  int SplitStrLen=SplitStr.Len();
1011  int PrevChN=0; int ChN=0;
1012  while ((ChN=SearchStr(SplitStr, ChN))!=-1){
1013  // extract & add string
1014  TStr SubStr=GetSubStr(PrevChN, ChN-1);
1015  StrV.Add(SubStr);
1016  PrevChN=ChN=ChN+SplitStrLen;
1017  }
1018  // add last string
1019  TStr LastSubStr=GetSubStr(PrevChN, Len()-1);
1020  StrV.Add(LastSubStr);
1021 }
1022 
1023 void TStr::SplitOnStr(TStr& LeftStr, const TStr& MidStr, TStr& RightStr) const {
1024  const int ChN=SearchStr(MidStr);
1025  if (ChN==-1){
1026  LeftStr=*this; RightStr=GetNullStr();
1027  } else {
1028  LeftStr=GetSubStr(0, ChN-1);
1029  RightStr=GetSubStr(ChN+MidStr.Len(), Len()-1);
1030  }
1031 }
1032 
1033 int TStr::CountCh(const char& Ch, const int& BChN) const {
1034  const int ThisLen=Len();
1035  const char* ThisBf=CStr();
1036  int Chs=0;
1037  for (int ChN=TInt::GetMx(BChN, 0); ChN<ThisLen; ChN++){
1038  if (ThisBf[ChN]==Ch){Chs++;}
1039  }
1040  return Chs;
1041 }
1042 
1043 int TStr::SearchCh(const char& Ch, const int& BChN) const {
1044  int ThisLen=Len(); const char* ThisBf=CStr();
1045  int ChN=TInt::GetMx(BChN, 0);
1046  while (ChN<ThisLen){
1047  if (ThisBf[ChN]==Ch){return ChN;}
1048  ChN++;
1049  }
1050  return -1;
1051 }
1052 
1053 int TStr::SearchChBack(const char& Ch, int BChN) const {
1054  const int StrLen=Len();
1055  if (BChN==-1||BChN>=StrLen){BChN=StrLen-1;}
1056  const char* ThisBf=CStr();
1057  const char* Pt=ThisBf + BChN;
1058  while (Pt>=ThisBf) {
1059  if (*Pt==Ch){return (int)(Pt-ThisBf);}
1060  Pt--;
1061  }
1062  return -1;
1063 }
1064 
1065 int TStr::SearchStr(const TStr& Str, const int& BChN) const {
1066  int NrBChN=TInt::GetMx(BChN, 0);
1067  const char* StrPt=strstr((const char*)CStr()+NrBChN, Str.CStr());
1068  if (StrPt==NULL){return -1;}
1069  else {return int(StrPt-CStr());}
1070 /* // slow implementation
1071  int ThisLen=Len(); int StrLen=Str.Len();
1072  int ChN=TInt::GetMx(BChN, 0);
1073  while (ChN<ThisLen-StrLen+1){
1074  if (strncmp(CStr()+ChN, Str.CStr(), StrLen)==0){
1075  return ChN;}
1076  ChN++;
1077  }
1078  return -1;*/
1079 }
1080 
1081 bool TStr::IsPrefix(const char *Str) const {
1082  size_t len = strlen(Str);
1083  size_t thisLen = Len();
1084  if (len > thisLen) {
1085  return false;
1086  } else {
1087  size_t minLen = MIN(len, thisLen);
1088  int cmp = strncmp(Str, RStr->Bf, minLen);
1089  return cmp == 0;
1090  }
1091 }
1092 
1093 bool TStr::IsSuffix(const char *Str) const {
1094  size_t len = strlen(Str);
1095  size_t thisLen = Len();
1096  if (len > thisLen) {
1097  // too long to be a suffix anyway
1098  return false;
1099  } else {
1100  // move to the point in the buffer where we would expect the suffix to be
1101  const char *ending = RStr->Bf + thisLen - len;
1102  int cmp = strncmp(Str, ending, len);
1103  return cmp == 0;
1104  }
1105 }
1106 
1107 int TStr::ChangeCh(const char& SrcCh, const char& DstCh, const int& BChN){
1108  int ChN=SearchCh(SrcCh, BChN);
1109  if (ChN!=-1){PutCh(ChN, DstCh);}
1110  return ChN;
1111 }
1112 
1113 int TStr::ChangeChAll(const char& SrcCh, const char& DstCh){
1114  int FirstChN=SearchCh(SrcCh);
1115  if (FirstChN==-1){
1116  return 0;
1117  } else {
1118  TRStr* NewRStr=new TRStr(RStr->CStr());
1119  RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
1120  char* ThisBf=CStr(); int StrLen=Len(); int Changes=0;
1121  for (int ChN=FirstChN; ChN<StrLen; ChN++){
1122  // slow: if (GetCh(ChN)==SrcCh){RStr->PutCh(ChN, DstCh); Changes++;}
1123  if (ThisBf[ChN]==SrcCh){ThisBf[ChN]=DstCh; Changes++;}
1124  }
1125  Optimize();
1126  return Changes;
1127  }
1128 }
1129 
1130 int TStr::ChangeStr(const TStr& SrcStr, const TStr& DstStr, const int& BChN){
1131  int ChN=SearchStr(SrcStr, BChN);
1132  if (ChN==-1){
1133  return -1;
1134  } else {
1135  DelSubStr(ChN, ChN+SrcStr.Len()-1);
1136  InsStr(ChN, DstStr);
1137  return ChN;
1138  }
1139 }
1140 
1141 int TStr::ChangeStrAll(const TStr& SrcStr, const TStr& DstStr, const bool& FromStartP){
1142  const int DstStrLen=DstStr.Len();
1143  int Changes=0-1; int BChN=0-DstStrLen;
1144  do {
1145  Changes++;
1146  if (FromStartP){BChN=0-DstStrLen;}
1147  BChN+=DstStrLen;
1148  BChN=ChangeStr(SrcStr, DstStr, BChN);
1149  } while (BChN!=-1);
1150  return Changes;
1151 }
1152 
1153 bool TStr::IsBool(bool& Val) const {
1154  if (operator==("T")){Val=true; return true;}
1155  else if (operator==("F")){Val=false; return true;}
1156  else {return false;}
1157 }
1158 
1160  const bool& Check, const int& MnVal, const int& MxVal, int& Val) const {
1161  // parsing format {ws} [+/-] +{ddd}
1162  int _Val=0;
1163  bool Minus=false;
1164  TChRet Ch(TStrIn::New(*this));
1165  while (TCh::IsWs(Ch.GetCh())){}
1166  if (Ch()=='+'){Minus=false; Ch.GetCh();}
1167  if (Ch()=='-'){Minus=true; Ch.GetCh();}
1168  if (!TCh::IsNum(Ch())){return false;}
1169  _Val=TCh::GetNum(Ch());
1170  while (TCh::IsNum(Ch.GetCh())){_Val=10*_Val+TCh::GetNum(Ch());}
1171  if (Minus){_Val=-_Val;}
1172  if (Check&&((_Val<MnVal)||(_Val>MxVal))){return false;}
1173  if (Ch.Eof()){Val=_Val; return true;} else {return false;}
1174 }
1175 
1177  const bool& Check, const uint& MnVal, const uint& MxVal, uint& Val) const {
1178  // parsing format {ws} [+]{ddd}
1179  uint _Val=0;
1180  TChRet Ch(TStrIn::New(*this));
1181  while (TCh::IsWs(Ch.GetCh())){}
1182  if (Ch()=='+'){Ch.GetCh();}
1183  if (!TCh::IsNum(Ch())){return false;}
1184  _Val=TCh::GetNum(Ch());
1185  while (TCh::IsNum(Ch.GetCh())){_Val=10*_Val+TCh::GetNum(Ch());}
1186  if (Check&&((_Val<MnVal)||(_Val>MxVal))){return false;}
1187  if (Ch.Eof()){Val=_Val; return true;} else {return false;}
1188 }
1189 
1190 bool TStr::IsHexInt( const bool& Check, const int& MnVal, const int& MxVal, int& Val) const {
1191  // parsing format {ws} [+/-][0x] +{XXX}
1192  int _Val=0;
1193  bool Minus=false;
1194  TChRet Ch(TStrIn::New(*this));
1195  while (TCh::IsWs(Ch.GetCh())){}
1196  if (Ch()=='+'){Minus=false; Ch.GetCh();}
1197  if (Ch()=='-'){Minus=true; Ch.GetCh();}
1198  if (Ch()=='0'){
1199  Ch.GetCh();
1200  if (tolower(Ch())=='x' ){
1201  Ch.GetCh(); if (Ch.Eof()){return false;}
1202  }
1203  }
1204  if (!Ch.Eof() && !TCh::IsHex(Ch())){return false;}
1205  if (!Ch.Eof()) _Val = TCh::GetHex(Ch());
1206  while (TCh::IsHex(Ch.GetCh())){_Val=16*_Val+TCh::GetHex(Ch());}
1207  if (Minus){_Val=-_Val;}
1208  if (Check&&((_Val<MnVal)||(_Val>MxVal))){return false;}
1209  if (Ch.Eof()){Val=_Val; return true;} else {return false;}
1210 }
1211 
1213  const bool& Check, const int64& MnVal, const int64& MxVal, int64& Val) const {
1214  // parsing format {ws} [+/-] +{ddd}
1215  int64 _Val=0;
1216  bool Minus=false;
1217  TChRet Ch(TStrIn::New(*this));
1218  while (TCh::IsWs(Ch.GetCh())){}
1219  if (Ch()=='+'){Minus=false; Ch.GetCh();}
1220  if (Ch()=='-'){Minus=true; Ch.GetCh();}
1221  if (!TCh::IsNum(Ch())){return false;}
1222  _Val=TCh::GetNum(Ch());
1223  while (TCh::IsNum(Ch.GetCh())){_Val=10*_Val+TCh::GetNum(Ch());}
1224  if (Minus){_Val=-_Val;}
1225  if (Check&&((_Val<MnVal)||(_Val>MxVal))){return false;}
1226  if (Ch.Eof()){Val=_Val; return true;} else {return false;}
1227 }
1228 
1230  const bool& Check, const uint64& MnVal, const uint64& MxVal, uint64& Val) const {
1231  // parsing format {ws} [+]{ddd}
1232  uint64 _Val=0;
1233  TChRet Ch(TStrIn::New(*this));
1234  while (TCh::IsWs(Ch.GetCh())){}
1235  if (Ch()=='+'){Ch.GetCh();}
1236  if (!TCh::IsNum(Ch())){return false;}
1237  _Val=TCh::GetNum(Ch());
1238  while (TCh::IsNum(Ch.GetCh())){_Val=10*_Val+TCh::GetNum(Ch());}
1239  if (Check&&((_Val<MnVal)||(_Val>MxVal))){return false;}
1240  if (Ch.Eof()){Val=_Val; return true;} else {return false;}
1241 }
1242 
1244  const bool& Check, const int64& MnVal, const int64& MxVal, int64& Val) const {
1245  // parsing format {ws} [+/-][0x] +{XXX}
1246  int64 _Val=0;
1247  bool Minus=false;
1248  TChRet Ch(TStrIn::New(*this));
1249  while (TCh::IsWs(Ch.GetCh())){}
1250  if (Ch()=='+'){Minus=false; Ch.GetCh();}
1251  if (Ch()=='-'){Minus=true; Ch.GetCh();}
1252  if (Ch()=='0'){
1253  Ch.GetCh();
1254  if (tolower(Ch())=='x' ){
1255  Ch.GetCh(); if (Ch.Eof()){return false;}
1256  }
1257  }
1258  if (!Ch.Eof()) _Val=TCh::GetHex(Ch());
1259  while (TCh::IsHex(Ch.GetCh())){_Val=16*_Val+TCh::GetHex(Ch());}
1260  if (Minus){_Val=-_Val;}
1261  if (Check&&((_Val<MnVal)||(_Val>MxVal))){return false;}
1262  if (Ch.Eof()){Val=_Val; return true;} else {return false;}
1263 }
1264 
1265 bool TStr::IsFlt(const bool& Check, const double& MnVal, const double& MxVal,
1266  double& Val, const char& DecDelimCh) const {
1267  // parsing format {ws} [+/-] +{d} ([.]{d}) ([E|e] [+/-] +{d})
1268  TChRet Ch(TStrIn::New(*this));
1269  while (TCh::IsWs(Ch.GetCh())){}
1270  if ((Ch()=='+')||(Ch()=='-')){Ch.GetCh();}
1271  if (!TCh::IsNum(Ch())&&Ch()!=DecDelimCh){return false;}
1272  while (TCh::IsNum(Ch.GetCh())){}
1273  if (Ch()==DecDelimCh){
1274  Ch.GetCh();
1275  while (TCh::IsNum(Ch.GetCh())){}
1276  }
1277  if ((Ch()=='e')||(Ch()=='E')){
1278  Ch.GetCh();
1279  if ((Ch()=='+')||(Ch()=='-')){Ch.GetCh();}
1280  if (!TCh::IsNum(Ch())){return false;}
1281  while (TCh::IsNum(Ch.GetCh())){}
1282  }
1283  if (!Ch.Eof()){return false;}
1284  double _Val=atof(CStr());
1285  if (Check&&((_Val<MnVal)||(_Val>MxVal))){
1286  return false;
1287  } else {
1288  Val=_Val; return true;
1289  }
1290 }
1291 
1292 bool TStr::IsWord(const bool& WsPrefixP, const bool& FirstUcAllowedP) const {
1293  // parsing format {ws} (A-Z,a-z) *{A-Z,a-z,0-9}
1294  TChRet Ch(TStrIn::New(*this));
1295  if (WsPrefixP){while (TCh::IsWs(Ch.GetCh())){}}
1296  else {Ch.GetCh();}
1297  if (!TCh::IsAlpha(Ch())){return false;}
1298  else if (!FirstUcAllowedP&&(TCh::IsUc(Ch()))){return false;}
1299  while (TCh::IsAlNum(Ch.GetCh())){}
1300  if (!Ch.Eof()){return false;}
1301  return true;
1302 }
1303 
1304 bool TStr::IsWs() const {
1305  // if string is just a bunch of whitespace chars
1306  TChRet Ch(TStrIn::New(*this));
1307  while (TCh::IsWs(Ch.GetCh())){}
1308  return Ch.Eof();
1309 }
1310 
1312  const int& StrBChN, const TStr& WcStr, const int& WcStrBChN, TStrV& StarStrV,
1313  const char& StarCh, const char& QuestCh) const {
1314  int StrLen=Len(); int WcStrLen=WcStr.Len();
1315  int StrChN=StrBChN; int WcStrChN=WcStrBChN;
1316  while ((StrChN<StrLen)&&(WcStrChN<WcStrLen)){
1317  if ((WcStr[WcStrChN]==QuestCh)||(GetCh(StrChN)==WcStr[WcStrChN])){
1318  StrChN++; WcStrChN++;
1319  } else
1320  if (WcStr[WcStrChN]==StarCh){
1321  TChA StarChA; // string substituted by star character
1322  for (int AfterStrChN=StrChN; AfterStrChN<=StrLen; AfterStrChN++){
1323  if (AfterStrChN>StrChN){
1324  StarChA+=GetCh(AfterStrChN-1);}
1325  if (IsWcMatch(AfterStrChN, WcStr, WcStrChN+1, StarStrV, StarCh, QuestCh)){
1326  StarStrV.Add(StarChA); return true;
1327  }
1328  }
1329  return false;
1330  } else {
1331  return false;
1332  }
1333  }
1334  if (StrChN==StrLen){
1335  for (int AfterWcStrChN=WcStrChN; AfterWcStrChN<WcStrLen; AfterWcStrChN++){
1336  if (WcStr[AfterWcStrChN]!=StarCh){return false;}}
1337  return true;
1338  } else {
1339  return false;
1340  }
1341 }
1342 
1344  const TStr& WcStr, TStrV& StarStrV, const char& StarCh, const char& QuestCh) const {
1345  bool WcMatch=IsWcMatch(0, WcStr, 0, StarStrV, StarCh, QuestCh);
1346  if (WcMatch){
1347  StarStrV.Reverse();
1348  return true;
1349  } else {
1350  return false;
1351  }
1352 }
1353 
1355  const TStr& WcStr, const char& StarCh, const char& QuestCh) const {
1356  TStrV StarStrV;
1357  return IsWcMatch(0, WcStr, 0, StarStrV, StarCh, QuestCh);
1358 }
1359 
1360 bool TStr::IsWcMatch(const TStr& WcStr, const int& StarStrN, TStr& StarStr) const {
1361  TStrV StarStrV;
1362  if (IsWcMatch(WcStr, StarStrV)){
1363  if (StarStrV.Len()>StarStrN){
1364  StarStr=StarStrV[StarStrV.Len()-StarStrN-1];
1365  } else {
1366  StarStr="";
1367  }
1368  return true;
1369  } else {
1370  return false;
1371  }
1372 }
1373 
1374 bool TStr::IsWcMatch(const TStr& WcStr) const {
1375  TStrV StarStrV;
1376  return IsWcMatch(0, WcStr, 0, StarStrV);
1377 }
1378 
1379 TStr TStr::GetWcMatch(const TStr& WcStr, const int& StarStrN) const {
1380  TStrV StarStrV;
1381  if (IsWcMatch(WcStr, StarStrV)&&(StarStrV.Len()>=StarStrN)){
1382  IAssert(StarStrN>=0);
1383  return StarStrV[StarStrV.Len()-StarStrN-1];
1384  } else {
1385  return "";
1386  }
1387 }
1388 
1390  int ThisLen=Len(); const char* ThisBf=CStr();
1391  int ChN=ThisLen-1;
1392  while ((ChN>=0)&&(ThisBf[ChN]!='/')&&(ThisBf[ChN]!='\\')){ChN--;}
1393  return GetSubStr(0, ChN);
1394 }
1395 
1397  int ThisLen=Len(); const char* ThisBf=CStr();
1398  int ChN=ThisLen-1;
1399  while ((ChN>=0)&&(ThisBf[ChN]!='/')&&(ThisBf[ChN]!='\\')){ChN--;}
1400  return GetSubStr(ChN+1, ThisLen);
1401 }
1402 
1404  int ThisLen=Len(); const char* ThisBf=CStr();
1405  int ChN=ThisLen-1;
1406  while ((ChN>=0)&&(ThisBf[ChN]!='/')&&(ThisBf[ChN]!='\\')&&(ThisBf[ChN]!='.')){
1407  ChN--;}
1408  if (ChN<0){
1409  return *this;
1410  } else {
1411  if (ThisBf[ChN]=='.'){
1412  int EChN= --ChN;
1413  while ((ChN>=0)&&(ThisBf[ChN]!='/')&&(ThisBf[ChN]!='\\')){ChN--;}
1414  return GetSubStr(ChN+1, EChN);
1415  } else {
1416  return GetSubStr(ChN+1, ThisLen);
1417  }
1418  }
1419 }
1420 
1422  int ThisLen=Len(); const char* ThisBf=CStr();
1423  int ChN=ThisLen-1;
1424  while ((ChN>=0)&&(ThisBf[ChN]!='/')&&(ThisBf[ChN]!='\\')&&
1425  (ThisBf[ChN]!='.')){ChN--;}
1426  if ((ChN>=0)&&(ThisBf[ChN]=='.')){return GetSubStr(ChN, Len());}
1427  else {return TStr();}
1428 }
1429 
1431  TChA NrFPath(FPath.Len()+4); NrFPath+=FPath;
1432  NrFPath.ChangeCh('\\', '/');
1433  if (NrFPath.Empty()){NrFPath="./";}
1434  if ((NrFPath.Len()>=2)&&isalpha(NrFPath[0])&&(NrFPath[1]==':')){
1435  if (NrFPath.Len()==2){NrFPath+="./";}
1436  if ((NrFPath[2]!='.')&&(NrFPath[2]!='/')){NrFPath.Ins(2, "./");}
1437  if (NrFPath[NrFPath.Len()-1]!='/'){NrFPath+="/";}
1438  } else {
1439  if ((NrFPath[0]!='.')&&(NrFPath[0]!='/')){NrFPath.Ins(0, "./");}
1440  if (NrFPath[NrFPath.Len()-1]!='/'){NrFPath+="/";}
1441  }
1442  return NrFPath;
1443 }
1444 
1446  TChA NrFMid;
1447  int FMidLen=FMid.Len();
1448  for (int ChN=0; ChN<FMidLen; ChN++){
1449  char Ch=FMid[ChN];
1450  if (TCh::IsAlNum(Ch)){NrFMid+=Ch;} else {NrFMid+='_';}
1451  }
1452  return NrFMid;
1453 }
1454 
1456  if (FExt.Empty()||(FExt[0]=='.')){return FExt;}
1457  else {return TStr(".")+FExt;}
1458 }
1459 
1460 TStr TStr::GetNrNumFExt(const int& FExtN){
1461  TStr FExtNStr=TInt::GetStr(FExtN);
1462  while (FExtNStr.Len()<3){
1463  FExtNStr=TStr("0")+FExtNStr;}
1464  return FExtNStr;
1465 }
1466 
1468  return GetNrFPath(FNm.GetFPath())+FNm.GetFMid()+GetNrFExt(FNm.GetFExt());
1469 }
1470 
1471 TStr TStr::GetNrAbsFPath(const TStr& FPath, const TStr& BaseFPath){
1472  TStr NrBaseFPath;
1473  if (BaseFPath.Empty()){
1474  NrBaseFPath=GetNrFPath(TDir::GetCurDir());
1475  } else {
1476  NrBaseFPath=GetNrFPath(BaseFPath);
1477  }
1478  IAssert(IsAbsFPath(NrBaseFPath));
1479  TStr NrFPath=GetNrFPath(FPath);
1480  TStr NrAbsFPath;
1481  if (IsAbsFPath(NrFPath)){
1482  NrAbsFPath=NrFPath;
1483  } else {
1484  NrAbsFPath=GetNrFPath(NrBaseFPath+NrFPath);
1485  }
1486  NrAbsFPath.ChangeStrAll("/./", "/");
1487  NrAbsFPath.ChangeStrAll("\\.\\", "\\");
1488  return NrAbsFPath;
1489 }
1490 
1491 bool TStr::IsAbsFPath(const TStr& FPath){
1492  if ((FPath.Len()>=3)&&isalpha(FPath[0])&&(FPath[1]==':')&&
1493  ((FPath[2]=='/')||(FPath[2]=='\\'))){
1494  return true;
1495  }
1496  return false;
1497 }
1498 
1499 TStr TStr::PutFExt(const TStr& FNm, const TStr& FExt){
1500  return FNm.GetFPath()+FNm.GetFMid()+FExt;
1501 }
1502 
1503 TStr TStr::PutFExtIfEmpty(const TStr& FNm, const TStr& FExt){
1504  if (FNm.GetFExt().Empty()){
1505  return FNm.GetFPath()+FNm.GetFMid()+FExt;
1506  } else {
1507  return FNm;
1508  }
1509 }
1510 
1511 TStr TStr::PutFBase(const TStr& FNm, const TStr& FBase){
1512  return FNm.GetFPath()+FBase;
1513 }
1514 
1515 TStr TStr::PutFBaseIfEmpty(const TStr& FNm, const TStr& FBase){
1516  if (FNm.GetFBase().Empty()){
1517  return FNm.GetFPath()+FBase;
1518  } else {
1519  return FNm;
1520  }
1521 }
1522 
1523 TStr TStr::AddToFMid(const TStr& FNm, const TStr& ExtFMid){
1524  return FNm.GetFPath()+FNm.GetFMid()+ExtFMid+FNm.GetFExt();
1525 }
1526 
1527 TStr TStr::GetNumFNm(const TStr& FNm, const int& Num){
1528  return FNm.GetFPath()+FNm.GetFMid()+TInt::GetStr(Num, "%03d")+FNm.GetFExt();
1529 }
1530 
1531 TStr TStr::GetFNmStr(const TStr& Str, const bool& AlNumOnlyP){
1532  TChA FNm=Str;
1533  for (int ChN=0; ChN<FNm.Len(); ChN++){
1534  uchar Ch=FNm[ChN];
1535  if (AlNumOnlyP){
1536  if (
1537  (('0'<=Ch)&&(Ch<='9'))||
1538  (('A'<=Ch)&&(Ch<='Z'))||
1539  (('a'<=Ch)&&(Ch<='z'))||
1540  (Ch=='-')||(Ch=='_')){}
1541  else {Ch='_';}
1542  } else {
1543  if ((Ch<=' ')||(Ch=='/')||(Ch=='\\')||(Ch==':')||(Ch=='.')){
1544  Ch='_';}
1545  }
1546  FNm.PutCh(ChN, Ch);
1547  }
1548  return FNm;
1549 }
1550 
1551 TStr& TStr::GetChStr(const char& Ch){
1552  static char MnCh=char(CHAR_MIN);
1553  static char MxCh=char(CHAR_MAX);
1554  static int Chs=int(MxCh)-int(MnCh)+1;
1555  static TStrV ChStrV;
1556  if (ChStrV.Empty()){
1557  ChStrV.Gen(Chs);
1558  for (int ChN=0; ChN<Chs; ChN++){
1559  ChStrV[ChN]=TStr(char(MnCh+ChN), true);}
1560  }
1561  return ChStrV[int(Ch-MnCh)];
1562 }
1563 
1564 TStr& TStr::GetDChStr(const char& Ch1, const char& Ch2){
1565  Fail; // temporary
1566  static TStrVV DChStrVV;
1567  if (DChStrVV.Empty()){
1568  DChStrVV.Gen(TCh::Vals, TCh::Vals);
1569  for (int Ch1N=0; Ch1N<TCh::Vals; Ch1N++){
1570  for (int Ch2N=0; Ch2N<TCh::Vals; Ch2N++){
1571  DChStrVV.At(Ch1N, Ch2N)=
1572  TStr(char(TCh::Mn+Ch1N), char(TCh::Mn+Ch2N), true);
1573  }
1574  }
1575  }
1576  return DChStrVV.At(int(Ch1-TCh::Mn), int(Ch2-TCh::Mn));
1577 }
1578 
1579 TStr TStr::GetStr(const TStr& Str, const char* FmtStr){
1580  if (FmtStr==NULL){
1581  return Str;
1582  } else {
1583  char Bf[1000];
1584  sprintf(Bf, FmtStr, Str.CStr());
1585  return TStr(Bf);
1586  }
1587 }
1588 
1589 TStr TStr::GetStr(const TStrV& StrV, const TStr& DelimiterStr){
1590  if (StrV.Empty()){return TStr();}
1591  TChA ResStr=StrV[0];
1592  for (int StrN=1; StrN<StrV.Len(); StrN++){
1593  ResStr+=DelimiterStr;
1594  ResStr+=StrV[StrN];
1595  }
1596  return ResStr;
1597 }
1598 
1599 TStr TStr::Fmt(const char *FmtStr, ...){
1600  char Bf[10*1024];
1601  va_list valist;
1602  va_start(valist, FmtStr);
1603  const int RetVal=vsnprintf(Bf, 10*1024-2, FmtStr, valist);
1604  va_end(valist);
1605  return RetVal!=-1 ? TStr(Bf) : TStr::GetNullStr();
1606 }
1607 
1608 TStr TStr::GetSpaceStr(const int& Spaces){
1609  static TStrV SpaceStrV;
1610  if (SpaceStrV.Len()==0){
1611  for (int SpaceStrN=0; SpaceStrN<10; SpaceStrN++){
1612  TChA SpaceChA;
1613  for (int ChN=0; ChN<SpaceStrN; ChN++){SpaceChA+=' ';}
1614  SpaceStrV.Add(SpaceChA);
1615  }
1616  }
1617  if ((0<=Spaces)&&(Spaces<SpaceStrV.Len())){
1618  return SpaceStrV[Spaces];
1619  } else {
1620  TChA SpaceChA;
1621  for (int ChN=0; ChN<Spaces; ChN++){SpaceChA+=' ';}
1622  return SpaceChA;
1623  }
1624 }
1625 
1627  static TStr NullStr="";
1628  return NullStr;
1629 }
1630 
1631 TStr operator+(const TStr& LStr, const TStr& RStr){
1632  if (LStr.Empty()){return RStr;}
1633  else if (RStr.Empty()){return LStr;}
1634  else {return TStr(LStr)+=RStr;}
1635 }
1636 
1637 TStr operator+(const TStr& LStr, const char* RCStr){
1638  return TStr(LStr)+=RCStr;
1639 }
1640 
1642 // Input-String
1643 TStrIn::TStrIn(const TStr& _Str):
1644  TSBase("Input-String"), TSIn("Input-String"), Str(_Str), Bf(Str.CStr()), BfC(0), BfL(Str.Len()){}
1645 
1646 int TStrIn::GetBf(const void* LBf, const TSize& LBfL){
1647  Assert(TSize(BfC+LBfL)<=TSize(BfL));
1648  int LBfS=0;
1649  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
1650  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
1651  return LBfS;
1652 }
1653 
1655  // not implemented
1656  FailR(TStr::Fmt("TStrIn::GetNextLnBf: not implemented").CStr());
1657  return false;
1658 }
1659 
1661 // String-Pool
1662 void TStrPool::Resize(const uint& _MxBfL) {
1663  uint newSize = MxBfL;
1664  while (newSize < _MxBfL) {
1665  if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
1666  else if (newSize > 0) newSize *= 2;
1667  else newSize = TInt::GetMn(GrowBy, 1024);
1668  // check for overflow at 4GB
1669  IAssertR(newSize >= MxBfL, TStr::Fmt("TStrPool::Resize: %u, %u [Size larger than 4Gb, which is not supported by TStrPool]", newSize, MxBfL).CStr());
1670  }
1671  if (newSize > MxBfL) {
1672  Bf = (char *) realloc(Bf, newSize);
1673  IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
1674  MxBfL = newSize;
1675  }
1676  IAssertR(MxBfL >= _MxBfL, TStr::Fmt("new size: %u, requested size: %u", MxBfL, _MxBfL).CStr());
1677 }
1678 
1679 TStrPool::TStrPool(const uint& MxBfLen, const uint& _GrowBy) : MxBfL(MxBfLen), BfL(0), GrowBy(_GrowBy), Bf(0) {
1680  //IAssert(MxBfL >= 0); IAssert(GrowBy >= 0);
1681  if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssertR(Bf, TStr::Fmt("Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]", MxBfL).CStr()); }
1682  AddStr(""); // add an empty string at the beginning for fast future access
1683 }
1684 
1685 TStrPool::TStrPool(TSIn& SIn, bool LoadCompact) : MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
1686  SIn.Load(MxBfL); SIn.Load(BfL); SIn.Load(GrowBy);
1687  //IAssert(MxBfL >= BfL); IAssert(BfL >= 0); IAssert(GrowBy >= 0);
1688  if (LoadCompact) MxBfL = BfL;
1689  if (MxBfL > 0) { Bf = (char *) malloc(MxBfL); IAssertR(Bf, TStr::Fmt("Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]", MxBfL).CStr()); }
1690  if (BfL > 0) SIn.LoadBf(Bf, BfL);
1691  SIn.LoadCs();
1692 }
1693 
1694 void TStrPool::Save(TSOut& SOut) const {
1695  SOut.Save(MxBfL); SOut.Save(BfL); SOut.Save(GrowBy);
1696  SOut.SaveBf(Bf, BfL);
1697  SOut.SaveCs();
1698 }
1699 
1701  if (this != &Pool) {
1702  GrowBy = Pool.GrowBy; MxBfL = Pool.MxBfL; BfL = Pool.BfL;
1703  if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr());
1704  Bf = (char *) malloc(MxBfL); IAssertR(Bf, TStr::Fmt("Can not resize buffer to %u bytes. [Program failed to allocate more memory. Solution: Get a bigger machine.]", MxBfL).CStr()); memcpy(Bf, Pool.Bf, BfL);
1705  }
1706  return *this;
1707 }
1708 
1709 // Adds Len characters to pool. To append a null
1710 // terminated string Len must be equal to strlen(s) + 1
1711 uint TStrPool::AddStr(const char *Str, const uint& Len) {
1712  IAssertR(Len > 0, "String too short (length includes the null character)"); //J: if (! Len) return -1;
1713  if (Len == 1 && BfL > 0) { return 0; } // empty string
1714  Assert(Str); Assert(Len > 0);
1715  if (BfL + Len > MxBfL) Resize(BfL + Len);
1716  memcpy(Bf + BfL, Str, Len);
1717  uint Pos = BfL; BfL += Len; return Pos;
1718 }
1719 
1720 int TStrPool::GetPrimHashCd(const char *CStr) {
1721  return TStrHashF_DJB::GetPrimHashCd(CStr);
1722 }
1723 
1724 int TStrPool::GetSecHashCd(const char *CStr) {
1725  return TStrHashF_DJB::GetSecHashCd(CStr);
1726 }
1727 
1729 // String-Pool-64bit
1731  ::TSize newSize = MxBfL;
1732  while (newSize < _MxBfL) {
1733  if (newSize >= GrowBy && GrowBy > 0) newSize += GrowBy;
1734  else if (newSize > 0) newSize *= 2;
1735  else newSize = (GrowBy > ::TSize(1024)) ? ::TSize(1024) : GrowBy;
1736  IAssert(newSize >= MxBfL); // assert we are growing
1737  }
1738  if (newSize > MxBfL) {
1739  Bf = (char *) realloc(Bf, newSize);
1740  IAssertR(Bf, TStr::Fmt("old Bf size: %u, new size: %u", MxBfL, newSize).CStr());
1741  MxBfL = newSize;
1742  }
1743  IAssert(MxBfL >= _MxBfL);
1744 }
1745 
1746 TStrPool64::TStrPool64(::TSize _MxBfL, ::TSize _GrowBy):
1747  MxBfL(_MxBfL), BfL(0), GrowBy(_GrowBy), Bf(NULL) {
1748 
1749  if (MxBfL > 0) { Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); }
1750  AddStr("");
1751 }
1752 
1754  MxBfL(StrPool.MxBfL), BfL(StrPool.BfL), GrowBy(StrPool.GrowBy) {
1755  if (Bf != NULL) { free(Bf); } else { IAssert(MxBfL == 0); }
1756  Bf = (char*)malloc(StrPool.MxBfL); IAssert(Bf != NULL);
1757  memcpy(Bf, StrPool.Bf, BfL);
1758 }
1759 
1760 TStrPool64::TStrPool64(TSIn& SIn, bool LoadCompact):
1761  MxBfL(0), BfL(0), GrowBy(0), Bf(0) {
1762  uint64 _GrowBy, _MxBfL, _BfL;
1763  SIn.Load(_GrowBy); SIn.Load(_MxBfL); SIn.Load(_BfL);
1764  GrowBy = (::TSize)_GrowBy; MxBfL = (::TSize)_MxBfL; BfL = (::TSize)_BfL;
1765  if (LoadCompact) { MxBfL = BfL; }
1766  if (MxBfL > 0) { Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL); }
1767  for (::TSize BfN = 0; BfN < _BfL; BfN++) { Bf[BfN] = SIn.GetCh(); }
1768  SIn.LoadCs();
1769 }
1770 
1771 void TStrPool64::Save(TSOut& SOut) const {
1772  uint64 _GrowBy = GrowBy, _MxBfL = MxBfL, _BfL = BfL;
1773  SOut.Save(_GrowBy); SOut.Save(_MxBfL); SOut.Save(_BfL);
1774  for (::TSize BfN = 0; BfN < _BfL; BfN++) { SOut.PutCh(Bf[BfN]); }
1775  SOut.SaveCs();
1776 }
1777 
1779  if (this != &StrPool) {
1780  GrowBy = StrPool.GrowBy; MxBfL = StrPool.MxBfL; BfL = StrPool.BfL;
1781  if (Bf != NULL) { free(Bf); } else { IAssert(MxBfL == 0); }
1782  Bf = (char*)malloc(MxBfL); IAssert(Bf != NULL);
1783  memcpy(Bf, StrPool.Bf, BfL);
1784  }
1785  return *this;
1786 }
1787 
1788 void TStrPool64::Clr(bool DoDel) {
1789  BfL = 0;
1790  if (DoDel && (Bf!=NULL)) {
1791  free(Bf);
1792  Bf = NULL; MxBfL = 0;
1793  }
1794 }
1795 
1797  const int Len = Str.Len() + 1;
1798  if (BfL + Len > MxBfL) { Resize(BfL + Len); }
1799  memcpy(Bf + BfL, Str.CStr(), Len);
1800  ::TSize Offset = BfL; BfL += Len;
1801  return uint64(Offset);
1802 }
1803 
1804 TStr TStrPool64::GetStr(const uint64& StrId) const {
1805  ::TSize Offset = (::TSize)StrId;
1806  return TStr(Bf + Offset);
1807 }
1808 
1810 // Void
1811 void TVoid::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
1812  XLoadHd(Nm);
1813 }
1814 
1815 void TVoid::SaveXml(TSOut& SOut, const TStr& Nm) const {
1816  XSaveBETag(Nm);
1817 }
1818 
1820 // Boolean
1821 const bool TBool::Mn=0;
1822 const bool TBool::Mx=1;
1823 const int TBool::Vals=TBool::Mx-TBool::Mn+1;
1825 
1826 const TStr TBool::FalseStr="F";
1827 const TStr TBool::TrueStr="T";
1828 const TStr TBool::NStr="N";
1829 const TStr TBool::YStr="Y";
1830 const TStr TBool::NoStr="No";
1831 const TStr TBool::YesStr="Yes";
1832 
1833 void TBool::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
1834  XLoadHd(Nm);
1835  Val=TXmlObjSer::GetBoolArg(XmlTok, "Val");
1836 }
1837 
1838 void TBool::SaveXml(TSOut& SOut, const TStr& Nm) const {
1839  XSaveBETagArg(Nm, "Val", TBool::GetStr(Val));
1840 }
1841 
1842 bool TBool::IsValStr(const TStr& Str){
1843  TStr UcStr=Str.GetUc();
1844  return
1845  (UcStr==FalseStr)||(UcStr==TrueStr)||
1846  (UcStr==YStr)||(UcStr==NStr)||
1847  (UcStr==YesStr)||(UcStr==NoStr);
1848 }
1849 
1850 bool TBool::GetValFromStr(const TStr& Str){
1851  return (Str==TrueStr)||(Str==YStr)||(Str==YesStr);
1852 }
1853 
1854 bool TBool::GetValFromStr(const TStr& Str, const bool& DfVal){
1855  TStr UcStr=Str.GetUc();
1856  if (IsValStr(UcStr)){
1857  return (UcStr==TrueStr)||(UcStr==YStr)||(UcStr==YesStr);
1858  } else {
1859  return DfVal;
1860  }
1861 }
1862 
1864 // Char
1865 const char TCh::Mn=CHAR_MIN;
1866 const char TCh::Mx=CHAR_MAX;
1867 const int TCh::Vals=int(TCh::Mx)-int(TCh::Mn)+1;
1868 
1869 const char TCh::NullCh=char(0);
1870 const char TCh::TabCh=char(9);
1871 const char TCh::LfCh=char(10);
1872 const char TCh::CrCh=char(13);
1873 const char TCh::EofCh=char(26);
1874 const char TCh::HashCh='#';
1875 
1876 void TCh::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
1877  XLoadHd(Nm);
1878  Val=char(TXmlObjSer::GetIntArg(XmlTok, "Val"));
1879 }
1880 
1881 void TCh::SaveXml(TSOut& SOut, const TStr& Nm) const {
1882  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
1883 }
1884 
1885 char TCh::GetUsFromYuAscii(const char& Ch){
1886  switch (Ch){
1887  case '~': return 'c';
1888  case '^': return 'C';
1889  case '{': return 's';
1890  case '[': return 'S';
1891  case '`': return 'z';
1892  case '@': return 'Z';
1893  case '|': return 'd';
1894  case '\\': return 'D';
1895  default: return Ch;
1896  }
1897 }
1898 
1900 // Unsigned-Char
1901 const uchar TUCh::Mn=0;
1902 const uchar TUCh::Mx=UCHAR_MAX;
1903 const int TUCh::Vals=int(TUCh::Mx)-int(TUCh::Mn)+1;
1904 
1905 void TUCh::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
1906  XLoadHd(Nm);
1907  Val=uchar(TXmlObjSer::GetIntArg(XmlTok, "Val"));
1908 }
1909 
1910 void TUCh::SaveXml(TSOut& SOut, const TStr& Nm) const {
1911  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
1912 }
1913 
1915 // Integer
1916 const int TInt::Mn=INT_MIN;
1917 const int TInt::Mx=INT_MAX;
1918 const int TInt::Kilo=1024;
1919 const int TInt::Mega=1024*1024;
1920 const int TInt::Giga=1024*1024*1024;
1921 TRnd TInt::Rnd;
1922 
1923 void TInt::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
1924  XLoadHd(Nm);
1925  Val=TXmlObjSer::GetIntArg(XmlTok, "Val");
1926 }
1927 
1928 void TInt::SaveXml(TSOut& SOut, const TStr& Nm) const {
1929  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
1930 }
1931 
1932 TStr TInt::GetStr(const int& Val, const char* FmtStr){
1933  if (FmtStr==NULL){
1934  return GetStr(Val);
1935  } else {
1936  char Bf[255];
1937  sprintf(Bf, FmtStr, Val);
1938  return TStr(Bf);
1939  }
1940 }
1941 
1942 //-----------------------------------------------------------------------------
1943 // Frugal integer serialization
1944 //-----------------------------------------------------------------------------
1945 // These routines serialize integers to sequences of 1..4 bytes, with smaller
1946 // integers receiving shorter codes. They do not work directly with streams
1947 // but rather with a user-provided buffer. It is expected that one will want
1948 // to store several such integers at once, and it would be inefficient to
1949 // call the virtual TSOut::PutCh method once for every byte; this is why
1950 // SaveFrugalInt and LoadFrugalInt work with a user-provided char* buffer
1951 // rather than with TSIn/TSOut. To store a vector of such integers, use the
1952 // SaveFrugalIntV/LoadFrugalIntV pair.
1953 
1954 char* TInt::SaveFrugalInt(char *pDest, int i){
1955  // <0xxx xxxx> has 128 combinations and is used to store -1..126.
1956  // <1xxx xxxx> <00xx xxxx> has 2^13 = 8192 combinations and is used to store 127..8318.
1957  // <1xxx xxxx> <01xx xxxx> has 2^13 = 8192 combinations and is used to store -2..-8193.
1958  // <1xxx xxxx> <1xxx xxxx> <xxxx xxxx> <0xxx xxxx> has 2^29 = 536870912 combinations and is used to store 8319..536879230.
1959  // <1xxx xxxx> <1xxx xxxx> <xxxx xxxx> <1xxx xxxx> has 2^29 = 536870912 combinations and is used to store -8194..-536879105.
1960  i++;
1961  if (i >= 0 && i <= 127) { *pDest++ = char(i); return pDest; }
1962  if (i >= 128 && i < 128 + 8192) { i -= 128; *pDest++ = char(0x80 | (i & 0x7f));
1963  *pDest++ = char((i >> 7) & 0x3f); return pDest; }
1964  if (i <= -1 && i > -1 - 8192) { i = -1 - i; *pDest++ = char(0x80 | (i & 0x7f));
1965  *pDest++ = char(0x40 | ((i >> 7) & 0x3f)); return pDest; }
1966  if (i >= 128 + 8192 && i < 128 + 8192 + 536870912) { i -= 128 + 8192;
1967  *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
1968  *pDest++ = char((i >> 14) & 0xff); *pDest++ = char((i >> 22) & 0x7f); return pDest; }
1969  if (i <= -1 - 8192 && i > -1 - 8192 - 536870912) { i = (-1 - 8192) - i;
1970  *pDest++ = char(0x80 | (i & 0x7f)); *pDest++ = char(0x80 | ((i >> 7) & 0x7f));
1971  *pDest++ = char((i >> 14) & 0xff); *pDest++ = char(0x80 | ((i >> 22) & 0x7f)); return pDest; }
1972  IAssertR(false, TInt::GetStr(i)); return 0;
1973 }
1974 
1975 char* TInt::LoadFrugalInt(char *pSrc, int& i){
1976  i = 0;
1977  int ch = (int) ((unsigned char) (*pSrc++));
1978  if ((ch & 0x80) == 0) { i = ch; i--; return pSrc; }
1979  i = (ch & 0x7f);
1980  ch = (int) ((unsigned char) (*pSrc++));
1981  if ((ch & 0x80) == 0)
1982  {
1983  i |= (ch & 0x3f) << 7;
1984  if ((ch & 0x40) == 0) i += 128; else i = -1 - i;
1985  i--; return pSrc;
1986  }
1987  i |= (ch & 0x7f) << 7;
1988  ch = (int) ((unsigned char) (*pSrc++));
1989  i |= ch << 14;
1990  ch = (int) ((unsigned char) (*pSrc++));
1991  i |= (ch & 0x7f) << 22;
1992  if ((ch & 0x80) == 0) i += 128 + 8192; else i = (-1 - 8192) - i;
1993  i--; return pSrc;
1994 }
1995 
1996 // Tests the SaveFrugalInt/LoadFrugalInt combination on all the
1997 // integers they can work with (about 10^9 integers).
1999  char buf[10], *p = &buf[0], *r, *s;
2000  int i, j;
2001 #define __TEST(from, to, len) \
2002  for (i = (from); i <= (to); i++) \
2003  { if ((i & 0xffff) == 0) printf("%d\r", i); \
2004  r = SaveFrugalInt(p, i); s = LoadFrugalInt(p, j); \
2005  IAssert(r == s); IAssert(i == j); IAssert(r - p == len); }
2006 
2007  __TEST(-1, 126, 1);
2008  __TEST(127, 127 + 8191, 2);
2009  __TEST(-2 - 8191, -2, 2);
2010  __TEST(127 + 8192, 127 + 8191 + (1 << 29), 4);
2011  __TEST(-2 - 8191 - (1 << 29), -2 - 8192, 4);
2012 #undef __TEST
2013 }
2014 
2015 // Suppose that the contents of 'v', encoded using SaveFrugalInt,
2016 // occupy 'n' bytes. SaveFrugalIntV first stores 'n' (using
2017 // SaveFrugalInt), then the contents.
2018 void TInt::SaveFrugalIntV(TSOut& SOut, const TIntV& v){
2019  // Prepare a large enough buffer.
2020  int count = v.Len();
2021  char *buf = new char[4 * (count + 1)], *pStart, *pEnd;
2022  // Encode the contents of 'v'.
2023  pStart = buf + 4; pEnd = pStart;
2024  for (int i = 0; i < count; i++)
2025  pEnd = SaveFrugalInt(pEnd, v[i].Val);
2026  // Encode the size of the encoded contents of 'v'.
2027  // This is stored at the beginning of 'buf' and is then
2028  // moved so that there is no gap between it and the
2029  // beginning of the stored contents (at pStart).
2030  int size = int(pEnd - pStart);
2031  char *pSizeStart = buf;
2032  char *pSizeEnd = SaveFrugalInt(pSizeStart, size);
2033  while (pSizeEnd > pSizeStart) *(--pStart) = *(--pSizeEnd);
2034  // Write the buffer and free the memory.
2035  SOut.PutBf(pStart, TSize(pEnd - pStart));
2036  delete[] buf;
2037 }
2038 
2039 // Loads an integer 'n' (using LoadFrugalInt), then loads
2040 // 'n' bytes, decoding them using LoadFrugalInt and adding
2041 // them to the vector 'v'. If clearVec is true, 'v' is
2042 // cleared before anything is added to it.
2043 void TInt::LoadFrugalIntV(TSIn& SIn, TIntV& v, bool clearVec){
2044  if (clearVec) v.Clr();
2045  char sizeBuf[4], *p, *pEnd;
2046  // Load the first frugally-stored integer into the sizeBuf
2047  // buffer. 'count' bytes will be read.
2048  sizeBuf[0] = SIn.GetCh(); int count = 1;
2049  if (sizeBuf[0] & 0x80)
2050  {
2051  sizeBuf[1] = SIn.GetCh(); count++;
2052  if (sizeBuf[1] & 0x80) { sizeBuf[2] = SIn.GetCh();
2053  sizeBuf[3] = SIn.GetCh(); count += 2;}
2054  }
2055  // Decode the stored size.
2056  int size;
2057  pEnd = LoadFrugalInt(&sizeBuf[0], size);
2058  IAssert(pEnd - &sizeBuf[0] == count);
2059  if (size <= 0) return;
2060  // Allocate a buffer and read the compressed data.
2061  char *buf = new char[size];
2062  SIn.GetBf(buf, size);
2063  // Decode the compressed integers and add them into 'v'.
2064  p = buf; pEnd = buf + size;
2065  while (p < pEnd)
2066  { int i; p = LoadFrugalInt(p, i); v.Add(i); }
2067  IAssert(p == pEnd);
2068  delete[] buf;
2069 }
2070 
2072 // Unsigned-Integer
2073 const uint TUInt::Mn=0;
2074 const uint TUInt::Mx=UINT_MAX;
2076 
2077 void TUInt::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2078  XLoadHd(Nm);
2079  Val=TXmlObjSer::GetIntArg(XmlTok, "Val");
2080 }
2081 
2082 void TUInt::SaveXml(TSOut& SOut, const TStr& Nm) const {
2083  XSaveBETagArg(Nm, "Val", TInt::GetStr(Val));
2084 }
2085 
2086 TStr TUInt::GetStr(const uint& Val, const char* FmtStr){
2087  if (FmtStr==NULL){
2088  return GetStr(Val);
2089  } else {
2090  char Bf[255];
2091  sprintf(Bf, FmtStr, Val);
2092  return TStr(Bf);
2093  }
2094 }
2095 
2096 bool TUInt::IsIpStr(const TStr& IpStr, uint& Ip, const char& SplitCh) {
2097  TStrV IpStrV; IpStr.SplitOnAllCh(SplitCh, IpStrV);
2098  Ip = 0; int Byte = 0;
2099  if (IpStrV.Len() != 4) { return false; }
2100  if (!IpStrV[0].IsInt(true, 0, 255, Byte)) { return false; }; Ip = (uint)Byte;
2101  if (!IpStrV[1].IsInt(true, 0, 255, Byte)) { return false; }; Ip = (Ip << 8) | (uint)Byte;
2102  if (!IpStrV[2].IsInt(true, 0, 255, Byte)) { return false; }; Ip = (Ip << 8) | (uint)Byte;
2103  if (!IpStrV[3].IsInt(true, 0, 255, Byte)) { return false; }; Ip = (Ip << 8) | (uint)Byte;
2104  return true;
2105 }
2106 
2107 uint TUInt::GetUIntFromIpStr(const TStr& IpStr, const char& SplitCh) {
2108  TStrV IpStrV; IpStr.SplitOnAllCh(SplitCh, IpStrV);
2109  uint Ip = 0; int Byte = 0;
2110  EAssertR(IpStrV[0].IsInt(true, 0, 255, Byte), TStr::Fmt("Bad IP: '%s;", IpStr.CStr())); Ip = (uint)Byte;
2111  EAssertR(IpStrV[1].IsInt(true, 0, 255, Byte), TStr::Fmt("Bad IP: '%s;", IpStr.CStr())); Ip = (Ip << 8) | (uint)Byte;
2112  EAssertR(IpStrV[2].IsInt(true, 0, 255, Byte), TStr::Fmt("Bad IP: '%s;", IpStr.CStr())); Ip = (Ip << 8) | (uint)Byte;
2113  EAssertR(IpStrV[3].IsInt(true, 0, 255, Byte), TStr::Fmt("Bad IP: '%s;", IpStr.CStr())); Ip = (Ip << 8) | (uint)Byte;
2114  return Ip;
2115 }
2116 
2118  return TStr::Fmt("%d.%d.%d.%d", ((Ip>>24) & 0xFF),
2119  ((Ip>>16) & 0xFF), ((Ip>>8) & 0xFF), (Ip & 0xFF));
2120 }
2121 
2122 bool TUInt::IsIpv6Str(const TStr& IpStr, const char& SplitCh) {
2123  TStrV IpStrV; IpStr.SplitOnAllCh(SplitCh, IpStrV, false);
2124  // check we have 8 groups
2125  if (IpStrV.Len() > 8) { return false; }
2126  // each group must be in hexa and in range from 0x0000 to 0xFFFF
2127  int Group = 0;
2128  for (int IpStrN = 0; IpStrN < IpStrV.Len(); IpStrN++) {
2129  if (IpStrV[IpStrN].Empty()) { continue; }
2130  if (IpStrV[IpStrN].IsHexInt(true, 0x0000, 0xFFFF, Group)) { continue; }
2131  return false;
2132  }
2133  // all fine
2134  return true;
2135 }
2136 
2138 // Unsigned-Integer-64Bit
2139 
2140 #if defined (GLib_WIN32)
2141 const TUInt64 TUInt64::Mn(uint64(0x0000000000000000i64));
2142 const TUInt64 TUInt64::Mx(uint64(0xFFFFFFFFFFFFFFFFi64));
2143 #elif defined (GLib_BCB)
2144 const TUInt64 TUInt64::Mn(0x0000000000000000i64);
2145 const TUInt64 TUInt64::Mx(0xFFFFFFFFFFFFFFFFi64);
2146 #else
2147 const TUInt64 TUInt64::Mn((uint64)0x0000000000000000LL);
2148 const TUInt64 TUInt64::Mx(0xFFFFFFFFFFFFFFFFLL);
2149 #endif
2150 
2151 void TUInt64::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2152  XLoadHd(Nm);
2153  Val=TXmlObjSer::GetInt64Arg(XmlTok, "Val");
2154 }
2155 
2156 void TUInt64::SaveXml(TSOut& SOut, const TStr& Nm) const {
2157  XSaveBETagArg(Nm, "Val", TUInt64::GetStr(Val));
2158 }
2159 
2160 /*/////////////////////////////////////////////////
2161 // Unsigned-Integer-64Bit
2162 const TUInt64 TUInt64::Mn(0, 0);
2163 const TUInt64 TUInt64::Mx(UINT_MAX, UINT_MAX);
2164 
2165 void TUInt64::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2166  XLoadHd(Nm); XLoad(TInt(MsVal)); XLoad(TInt(LsVal));
2167 }
2168 
2169 void TUInt64::SaveXml(TSOut& SOut, const TStr& Nm) const {
2170  XSaveHd(Nm); XSave(TInt(MsVal)); XSave(TInt(LsVal));
2171 }
2172 
2173 TUInt64& TUInt64::operator+=(const TUInt64& Int){
2174  uint CarryVal=(LsVal>TUInt::Mx-Int.LsVal) ? 1 : 0;
2175  LsVal+=Int.LsVal;
2176  MsVal+=Int.MsVal+CarryVal;
2177  return *this;
2178 }
2179 
2180 TUInt64& TUInt64::operator-=(const TUInt64& Int){
2181  IAssert(*this>=Int);
2182  uint CarryVal;
2183  if (LsVal>=Int.LsVal){
2184  LsVal-=Int.LsVal; CarryVal=0;
2185  } else {
2186  LsVal+=(TUInt::Mx-Int.LsVal)+1; CarryVal=1;
2187  }
2188  MsVal-=(Int.MsVal+CarryVal);
2189  return *this;
2190 }
2191 
2192 TUInt64 TUInt64::operator++(int){
2193  if (LsVal==TUInt::Mx){
2194  Assert(MsVal<TUInt::Mx); MsVal++; LsVal=0;}
2195  else {LsVal++;}
2196  return *this;
2197 }
2198 
2199 TUInt64 TUInt64::operator--(int){
2200  if (LsVal==0){
2201  Assert(MsVal>0); MsVal--; LsVal=TUInt::Mx;}
2202  else {LsVal--;}
2203  return *this;
2204 }
2205 
2206 TStr TUInt64::GetStr(const TUInt64& Int){
2207  char Bf[255]; sprintf(Bf, "%.0Lf", ldouble(Int));
2208  return TStr(Bf);
2209 }
2210 
2211 TStr TUInt64::GetHexStr(const TUInt64& Int){
2212  char Bf[255]; sprintf(Bf, "%08X%08X", Int.MsVal, Int.LsVal);
2213  return TStr(Bf);
2214 }*/
2215 
2217 // Float
2218 const double TFlt::Mn=-DBL_MAX;
2219 const double TFlt::Mx=+DBL_MAX;
2220 const double TFlt::NInf=-DBL_MAX;
2221 const double TFlt::PInf=+DBL_MAX;
2222 const double TFlt::Eps=1e-16;
2223 const double TFlt::EpsHalf =1e-7;
2224 
2225 TRnd TFlt::Rnd;
2226 
2227 void TFlt::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2228  XLoadHd(Nm);
2229  Val=TXmlObjSer::GetFltArg(XmlTok, "Val");
2230 }
2231 
2232 void TFlt::SaveXml(TSOut& SOut, const TStr& Nm) const {
2233  XSaveBETagArg(Nm, "Val", TFlt::GetStr(Val));
2234 }
2235 
2236 TStr TFlt::GetStr(const double& Val, const int& Width, const int& Prec){
2237  char Bf[255];
2238  if ((Width==-1)&&(Prec==-1)){sprintf(Bf, "%g", Val);}
2239  else {sprintf(Bf, "%*.*f", Width, Prec, Val);}
2240  return TStr(Bf);
2241 }
2242 
2243 TStr TFlt::GetStr(const double& Val, const char* FmtStr){
2244  if (FmtStr==NULL){
2245  return GetStr(Val);
2246  } else {
2247  char Bf[255];
2248  sprintf(Bf, FmtStr, Val);
2249  return TStr(Bf);
2250  }
2251 }
2252 
2254 // Short-Float
2255 const sdouble TSFlt::Mn=-FLT_MIN;
2256 const sdouble TSFlt::Mx=+FLT_MAX;
2257 
2258 void TSFlt::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2259  XLoadHd(Nm);
2260  Val=sdouble(TXmlObjSer::GetFltArg(XmlTok, "Val"));
2261 }
2262 
2263 void TSFlt::SaveXml(TSOut& SOut, const TStr& Nm) const {
2264  XSaveBETagArg(Nm, "Val", TFlt::GetStr(Val));
2265 }
2266 
2268 // Long-Float
2269 const ldouble TLFlt::Mn=-LDBL_MAX;
2270 const ldouble TLFlt::Mx=+LDBL_MAX;
2271 /*const ldouble TUInt64::Mn_LFlt=TUInt64::Mn;
2272 const ldouble TUInt64::Mx_LFlt=TUInt64::Mx;
2273 const ldouble TUInt64::MxP1_LFlt=ldouble(TUInt::Mx)+ldouble(1);*/
2274 
2275 void TLFlt::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2276  XLoadHd(Nm);
2277  Val=TXmlObjSer::GetFltArg(XmlTok, "Val");
2278 }
2279 
2280 void TLFlt::SaveXml(TSOut& SOut, const TStr& Nm) const {
2281  XSaveBETagArg(Nm, "Val", TFlt::GetStr(double(Val)));
2282 }
2283 
2284 TStr TLFlt::GetStr(const ldouble& Val, const int& Width, const int& Prec){
2285  char Bf[255];
2286  if ((Width==-1)&&(Prec==-1)){sprintf(Bf, "%Lg", Val);}
2287  else {sprintf(Bf, "%*.*Lf", Width, Prec, Val);}
2288  return TStr(Bf);
2289 }
2290 
2291 TStr TLFlt::GetStr(const ldouble& Val, const char* FmtStr){
2292  if (FmtStr==NULL){
2293  return GetStr(Val);
2294  } else {
2295  char Bf[255];
2296  sprintf(Bf, FmtStr, Val);
2297  return TStr(Bf);
2298  }
2299 }
2300 
2302 // Float-Rectangle
2303 void TFltRect::LoadXml(const PXmlTok& XmlTok, const TStr& Nm){
2304  XLoadHd(Nm);
2305  MnX=TXmlObjSer::GetFltArg(XmlTok, "MnX");
2306  MnY=TXmlObjSer::GetFltArg(XmlTok, "MnY");
2307  MxX=TXmlObjSer::GetFltArg(XmlTok, "MxX");
2308  MxY=TXmlObjSer::GetFltArg(XmlTok, "MxY");
2309 }
2310 
2311 void TFltRect::SaveXml(TSOut& SOut, const TStr& Nm) const {
2312  XSaveBETagArg4(Nm,
2313  "MnX", TFlt::GetStr(double(MnX)), "MnY", TFlt::GetStr(double(MnY)),
2314  "MxX", TFlt::GetStr(double(MxX)), "MxY", TFlt::GetStr(double(MxY)));
2315 }
2316 
2317 bool TFltRect::Intersection(const TFltRect& Rect1, const TFltRect& Rect2){
2318  const double MnXX = TFlt::GetMx(Rect1.GetMnX(), Rect2.GetMnX());
2319  const double MnYY = TFlt::GetMx(Rect1.GetMnY(), Rect2.GetMnY());
2320  const double MxXX = TFlt::GetMn(Rect1.GetMxX(), Rect2.GetMxX());
2321  const double MxYY = TFlt::GetMn(Rect1.GetMxY(), Rect2.GetMxY());
2322  return (MnXX < MxXX) && (MnYY < MxYY);
2323 }
2324 
2326  TChA ChA;
2327  ChA+='(';
2328  ChA+=TFlt::GetStr(MnX, "%0.2f"); ChA+=',';
2329  ChA+=TFlt::GetStr(MnY, "%0.2f"); ChA+=',';
2330  ChA+=TFlt::GetStr(MxX, "%0.2f"); ChA+=',';
2331  ChA+=TFlt::GetStr(MxY, "%0.2f"); ChA+=')';
2332  return ChA;
2333 }
void Save(TSOut &SOut) const
Definition: dt.cpp:1771
#define IAssert(Cond)
Definition: bd.h:262
static int CmpI(const char *CStr1, const char *CStr2)
Definition: dt.cpp:699
static bool IsHex(const char &Ch)
Definition: dt.h:1070
void Resize(const uint &_MxBfL)
Definition: dt.cpp:1662
bool IsUInt() const
Definition: dt.h:588
bool IsLc() const
Definition: dt.cpp:672
static TStr PutFExtIfEmpty(const TStr &FNm, const TStr &FExt)
Definition: dt.cpp:1503
static double LnGamma(const double &xx)
Definition: xmath.cpp:80
int SearchCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:1043
int GetBf(const void *LBf, const TSize &LBfL)
Definition: dt.cpp:1646
TRStr * RStr
Definition: dt.h:414
static const double NInf
Definition: dt.h:1392
TMemOut(const PMem &_Mem)
Definition: dt.cpp:334
virtual int Len() const =0
static TStr GetCurDir()
Definition: xfl.cpp:233
static const uint Mn
Definition: dt.h:1246
TStr GetStr() const
Definition: dt.h:1200
#define IAssertR(Cond, Reason)
Definition: bd.h:265
static const int Kilo
Definition: dt.h:1143
static TStr GetSpaceStr(const int &Spaces)
Definition: dt.cpp:1608
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:1910
static const int r
Definition: dt.h:15
bool IsInt64() const
Definition: dt.h:596
#define XSaveBETagArg(Nm, ArgNm, ArgVal)
Definition: bd.h:327
TStr GetAsStr(const char &NewNullCh='\0') const
Definition: dt.cpp:303
int Len() const
Definition: dt.h:490
void ToLc()
Definition: dt.cpp:679
const char * CStr() const
Definition: dt.h:381
TStr GetFMid() const
Definition: dt.cpp:1403
void Resize(const int &_MxBfL)
Definition: dt.cpp:348
#define XLoadHd(Nm)
Definition: bd.h:312
static void LoadTxt(const PSIn &SIn, TChA &ChA)
Definition: dt.cpp:616
TStr & FromHex()
Definition: dt.cpp:798
int64 GetUniDevInt64(const int64 &Range=0)
Definition: dt.cpp:51
void Ins(const int &BChN, const char *CStr)
Definition: dt.cpp:407
double GetMnY() const
Definition: dt.h:1600
int GetNextSeed()
Definition: dt.h:17
static bool IsNum(const char &Ch)
Definition: dt.h:1067
int BfC
Definition: dt.h:704
bool IsPrefix(const char *Str) const
Definition: dt.cpp:1081
virtual int PutCh(const char &Ch)=0
Definition: dt.h:11
Definition: dt.h:1575
static const sdouble Mn
Definition: dt.h:1502
bool IsFlt() const
Definition: dt.h:630
virtual int PutBf(const void *LBf, const TSize &LBfL)=0
static const TStr NoStr
Definition: dt.h:987
#define XSaveHdArg(Nm, ArgNm, ArgVal)
Definition: bd.h:321
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:2280
static TStr GetStrFromIpUInt(const uint &Ip)
Definition: dt.cpp:2117
TStr GetFPath() const
Definition: dt.cpp:1389
void Del(const int &ChN)
Definition: dt.cpp:414
#define XSaveHd(Nm)
Definition: bd.h:318
int GetPrimHashCd() const
Definition: dt.cpp:709
bool IsHexInt64() const
Definition: dt.h:621
TMem & operator+=(const char &Ch)
Definition: dt.cpp:251
void Save(TSOut &SOut) const
Definition: dt.cpp:1694
int Val
Definition: dt.h:1139
sdouble Val
Definition: dt.h:1500
static const uint Mx
Definition: dt.h:1247
static TRnd Rnd
Definition: dt.h:981
int SearchChBack(const char &Ch, int BChN=-1) const
Definition: dt.cpp:1053
long double ldouble
Definition: bd.h:16
char * Bf
Definition: dt.h:80
static TRnd LoadTxt(TILx &Lx)
Definition: dt.cpp:215
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:1833
static double GetMx(const double &Flt1, const double &Flt2)
Definition: dt.h:1444
#define forever
Definition: bd.h:6
int Len() const
Definition: dt.h:134
unsigned int uint
Definition: bd.h:11
bool IsHexInt() const
Definition: dt.h:613
static int GetMx(const int &Int1, const int &Int2)
Definition: dt.h:1185
static const int RndSeed
Definition: dt.h:13
static const int Mx
Definition: dt.h:1142
#define Fail
Definition: bd.h:238
void ToCap()
Definition: dt.cpp:685
int BfL
Definition: dt.h:325
TStr GetUc() const
Definition: dt.h:496
static const char NullCh
Definition: dt.h:1036
static char * SaveFrugalInt(char *pDest, int i)
Definition: dt.cpp:1954
void PutCh(const int &ChN, const char &Ch)
Definition: dt.h:278
static char GetHexCh(const int &Val)
Definition: dt.h:1077
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:1923
void Clr()
Definition: dt.h:258
double Val
Definition: dt.h:1388
void Clr(bool DoDel=false)
Definition: dt.cpp:1788
static const double EpsHalf
Definition: dt.h:1395
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
static void SaveFrugalIntV(TSOut &SOut, const TVec< TInt, int > &IntV)
Definition: dt.cpp:2018
static int GetPrimHashCd(const char *CStr)
Definition: dt.cpp:1720
uint64 GetUniDevUInt64(const uint64 &Range=0)
Definition: dt.cpp:57
void PutInt(const TInt &Int)
Definition: lx.h:277
static TStr GetXmlStrFromPlainMem(const TMem &PlainMem)
Definition: xml.cpp:945
static const bool Mx
Definition: dt.h:979
void DelChAll(const char &Ch)
Definition: dt.cpp:840
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:14
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static int GetHex(const char &Ch)
Definition: dt.h:1072
double GetMxY() const
Definition: dt.h:1602
const char * Bf
Definition: dt.h:161
static TStr GetNrFMid(const TStr &FMid)
Definition: dt.cpp:1445
int Len() const
Definition: dt.h:259
TStr GetSubStr(const int &BChN, const int &EChN) const
Definition: dt.cpp:811
bool DelStr(const TStr &Str)
Definition: dt.cpp:863
int GetBf(const void *LBf, const TSize &LBfL)
Definition: dt.cpp:318
static TStr GetNrFNm(const TStr &FNm)
Definition: dt.cpp:1467
TStr & ToHex()
Definition: dt.cpp:785
int GetInt()
Definition: lx.h:181
int SearchStr(const TChA &Str, const int &BChN=0) const
Definition: dt.cpp:485
static int64 GetInt64Arg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:89
static bool IsIpv6Str(const TStr &IpStr, const char &SplitCh= ':')
Definition: dt.cpp:2122
TStrPool64(::TSize _MxBfL=0,::TSize _GrowBy=16 *1024 *1024)
Definition: dt.cpp:1746
::TSize MxBfL
Definition: dt.h:836
TStr GetFExt() const
Definition: dt.cpp:1421
static bool IsIpStr(const TStr &IpStr, uint &Ip, const char &SplitCh= '.')
Definition: dt.cpp:2096
char * Bf
Definition: dt.h:204
TChA & ToUc()
Definition: dt.cpp:560
void Clr()
Definition: dt.h:489
TFlt MnX
Definition: dt.h:1577
static const int q
Definition: dt.h:15
void UnRef()
Definition: dt.h:379
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:2077
static TRnd Rnd
Definition: dt.h:1146
static int GetSecHashCd(const char *p)
Definition: hash.h:1256
TStr & ToCap()
Definition: dt.cpp:764
static const double Mx
Definition: dt.h:1391
uint MxBfL
Definition: dt.h:783
int ChangeChAll(const char &SrcCh, const char &DstCh)
Definition: dt.cpp:1113
int MxBfL
Definition: dt.h:203
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:2263
Definition: dt.h:834
Definition: fl.h:40
virtual void LoadCs()
Definition: fl.cpp:28
#define XSaveBETag(Nm)
Definition: bd.h:324
static const TStr YStr
Definition: dt.h:986
static bool GetValFromStr(const TStr &Str)
Definition: dt.cpp:1850
PMem Mem
Definition: dt.h:184
static const ldouble Mn
Definition: dt.h:1541
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:746
Definition: fl.h:58
static const int Giga
Definition: dt.h:1145
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:242
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
TStr GetTokStr(const bool &XmlP=true) const
Definition: xml.h:316
double GetGammaDev(const int &Order)
Definition: dt.cpp:95
Definition: dt.h:77
TStr GetWcMatch(const TStr &WcStr, const int &StarStrN=0) const
Definition: dt.cpp:1379
void SplitOnCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
Definition: dt.cpp:901
TStrPool64 & operator=(const TStrPool64 &StrPool)
Definition: dt.cpp:1778
void Optimize()
Definition: dt.cpp:729
static const TStr FalseStr
Definition: dt.h:983
static const char EofCh
Definition: dt.h:1040
static const int Mega
Definition: dt.h:1144
static const char Mx
Definition: dt.h:1033
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:2232
void Reverse()
Definition: dt.cpp:440
char * Bf
Definition: dt.h:348
#define __TEST(from, to, len)
bool IsWs() const
Definition: dt.cpp:1304
static bool GetBoolArg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:59
Definition: dt.h:781
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:1876
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:1811
static const int Mn
Definition: dt.h:1141
int BfL
Definition: dt.h:79
int SearchChBack(const char &Ch, int BChN=-1) const
Definition: dt.cpp:477
static bool IsWs(const char &Ch)
Definition: dt.h:1063
static TStr AddToFMid(const TStr &FNm, const TStr &ExtFMid)
Definition: dt.cpp:1523
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
int PutBf(const void *LBf, const TSize &LBfL)
Definition: dt.cpp:336
void SaveCs()
Definition: fl.h:171
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
Definition: dt.cpp:1141
static const int a
Definition: dt.h:15
static TStr & GetDChStr(const char &Ch1, const char &Ch2)
Definition: dt.cpp:1564
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1183
double GetExpDev()
Definition: dt.cpp:83
char * CStr()
Definition: dt.h:255
static int GetSecHashCd(const char *CStr)
Definition: dt.cpp:1724
#define XSaveBETagArg4(Nm, ArgNm1, ArgVal1, ArgNm2, ArgVal2, ArgNm3, ArgVal3, ArgNm4, ArgVal4)
Definition: bd.h:330
static TStr GetNrAbsFPath(const TStr &FPath, const TStr &BaseFPath=TStr())
Definition: dt.cpp:1471
Definition: ds.h:2223
bool IsPrefix(const char *CStr, const int &BChN=0) const
Definition: dt.cpp:499
bool IsBool(bool &Val) const
Definition: dt.cpp:1153
TFlt MnY
Definition: dt.h:1577
unsigned long long uint64
Definition: bd.h:38
bool IsInt() const
Definition: dt.h:580
static const char TabCh
Definition: dt.h:1037
static const char Mn
Definition: dt.h:1032
void Load(bool &Bool)
Definition: fl.h:84
bool Eof() const
Definition: fl.h:548
int CountCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:462
void SaveTxt(const PSOut &SOut) const
Definition: dt.cpp:622
int SearchStr(const TStr &Str, const int &BChN=0) const
Definition: dt.cpp:1065
bool IsSuffix(const char *Str) const
Definition: dt.cpp:1093
bool IsWcMatch(const int &StrBChN, const TStr &WcStr, const int &WcStrBChN, TStrV &StarStrV, const char &StarCh='*', const char &QuestCh='?') const
Definition: dt.cpp:1311
bool DoFitStr(const TStr &Str) const
Definition: dt.cpp:247
TChA(const int &_MxBfL=256)
Definition: dt.h:207
static PSIn New(const TStr &Str)
Definition: dt.h:711
void MkRef()
Definition: dt.h:378
const char * Bf
Definition: dt.h:324
Definition: lx.h:129
void Resize(const int &_MxBfL)
Definition: dt.cpp:225
TFlt MxY
Definition: dt.h:1577
TMemIn(const TMem &_Mem, const int &_BfC=0)
Definition: dt.cpp:315
static int GetNum(const char &Ch)
Definition: dt.h:1069
#define MIN(a, b)
Definition: bd.h:346
TStr GetStr() const
Definition: dt.h:1282
uint GetUniDevUInt(const uint &Range=0)
Definition: dt.cpp:45
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:740
size_t TSize
Definition: bd.h:58
static TRStr * GetNullRStr()
Definition: dt.h:402
static void TestFrugalInt()
Definition: dt.cpp:1998
#define Assert(Cond)
Definition: bd.h:251
void AddBf(const void *Bf, const int &BfL)
Definition: dt.cpp:291
Definition: lx.h:251
TStr RightOf(const char &SplitCh) const
Definition: dt.cpp:887
TStr & ConvUsFromYuAscii()
Definition: dt.cpp:779
int GetSecHashCd() const
Definition: dt.cpp:611
static double GetFltArg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:104
::TSize BfL
Definition: dt.h:836
TChA GetSubStr(const int &BChN, const int &EChN) const
Definition: dt.cpp:448
static const char HashCh
Definition: dt.h:1041
static TStr & GetChStr(const char &Ch)
Definition: dt.cpp:1551
static TStr PutFBaseIfEmpty(const TStr &FNm, const TStr &FBase)
Definition: dt.cpp:1515
bool IsWord(const bool &WsPrefixP=true, const bool &FirstUcAllowedP=true) const
Definition: dt.cpp:1292
bool Val
Definition: dt.h:976
static const int Vals
Definition: dt.h:1099
TStr & operator=(const TStr &Str)
Definition: dt.h:445
void Del(const int &BChN, const int &EChN)
Definition: dt.cpp:277
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:1928
static TStr GetNrFPath(const TStr &FPath)
Definition: dt.cpp:1430
static TStr GetNrFExt(const TStr &FExt)
Definition: dt.cpp:1455
static TStr GetNullStr()
Definition: dt.cpp:1626
TStr & ToLc()
Definition: dt.cpp:758
static const sdouble Mx
Definition: dt.h:1503
#define FailR(Reason)
Definition: bd.h:240
int Len() const
Definition: dt.h:384
static TRStr * GetRStr(const char *CStr)
Definition: dt.cpp:719
unsigned char uchar
Definition: bd.h:10
double GetMxX() const
Definition: dt.h:1601
void SaveBf(const void *Bf, const TSize &BfL)
Definition: fl.h:172
char GetCh(const int &ChN) const
Definition: dt.h:486
uint64 Len() const
Definition: dt.h:857
TChA & operator+=(const TMem &Mem)
Definition: dt.cpp:387
char GetCh(const int &ChN) const
Definition: dt.h:280
int BfL
Definition: dt.h:203
void Trunc()
Definition: dt.cpp:420
Definition: fl.h:128
static double Pi
Definition: xmath.h:8
int BfC
Definition: dt.h:162
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:1838
void DelSubStr(const int &BChN, const int &EChN)
Definition: dt.cpp:850
int GetSecHashCd() const
Definition: dt.cpp:713
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:2227
static const char LfCh
Definition: dt.h:1038
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:2275
TStr GetStr() const
Definition: dt.h:681
void Save(const bool &Bool)
Definition: fl.h:173
TRnd(const int &_Seed=1, const int &Steps=0)
Definition: dt.h:20
bool GetNextLnBf(TChA &LnChA)
Definition: dt.cpp:326
static TStr PutFBase(const TStr &FNm, const TStr &FBase)
Definition: dt.cpp:1511
double GetPoissonDev(const double &Mean)
Definition: dt.cpp:121
TChA & ToLc()
Definition: dt.cpp:552
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:2082
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:1881
void Move(const int &Steps)
Definition: dt.cpp:29
void Resize(const ::TSize &_MxBfL)
Definition: dt.cpp:1730
static int GetIntArg(const PXmlTok &XmlTok, const TStr &Nm)
Definition: xml.cpp:74
void SaveTxt(TOLx &Lx) const
Definition: dt.cpp:219
static const TStr YesStr
Definition: dt.h:988
Definition: dt.h:201
static TStr GetNumFNm(const TStr &FNm, const int &Num)
Definition: dt.cpp:1527
uchar Val
Definition: dt.h:1095
static const bool Mn
Definition: dt.h:978
static const TStr NStr
Definition: dt.h:985
double GetNrmDev()
Definition: dt.cpp:63
int Seed
Definition: dt.h:16
uint64 AddStr(const TStr &Str)
Definition: dt.cpp:1796
TStr & ToUc()
Definition: dt.cpp:752
void ConvUsFromYuAscii()
Definition: dt.cpp:693
void PutSeed(const int &_Seed)
Definition: dt.cpp:18
static bool IsAlNum(const char &Ch)
Definition: dt.h:1068
float sdouble
Definition: bd.h:15
TFlt MxX
Definition: dt.h:1577
TStr LeftOf(const char &SplitCh) const
Definition: dt.cpp:873
void SplitOnNonAlNum(TStrV &StrV) const
Definition: dt.cpp:990
int SearchCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:470
static char * LoadFrugalInt(char *pSrc, int &i)
Definition: dt.cpp:1975
static bool IsValStr(const TStr &Str)
Definition: dt.cpp:1842
double GetBinomialDev(const double &Prb, const int &Trials)
Definition: dt.cpp:154
static double GetMn(const double &Flt1, const double &Flt2)
Definition: dt.h:1437
TStr GetStr() const
Definition: dt.h:1363
int ChangeCh(const char &SrcCh, const char &DstCh, const int &BChN=0)
Definition: dt.cpp:1107
static const ldouble Mx
Definition: dt.h:1542
long long int64
Definition: bd.h:27
static bool IsAlpha(const char &Ch)
Definition: dt.h:1065
Definition: dt.h:412
char GetCh()
Definition: fl.h:549
TStr GetStr(const uint64 &StrId) const
Definition: dt.cpp:1804
TChA & operator=(const TChA &ChA)
Definition: dt.cpp:366
bool Empty() const
Definition: dt.h:491
uint64 Val
Definition: dt.h:1320
TStr & ToTrunc()
Definition: dt.cpp:770
TStr LeftOfLast(const char &SplitCh) const
Definition: dt.cpp:880
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * Bf
Definition: dt.h:784
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:2151
void Swap(const int &ChN1, const int &ChN2)
Definition: dt.cpp:595
int PutStr(const char *CStr)
Definition: fl.cpp:117
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:9
void SplitOnAllCh(const char &SplitCh, TStrV &StrV, const bool &SkipEmpty=true) const
Definition: dt.cpp:926
static TRnd Rnd
Definition: dt.h:1248
int BfC
Definition: dt.h:325
TStr GetStr() const
Definition: dt.cpp:2325
void LoadBf(const void *Bf, const TSize &BfL)
Definition: fl.h:81
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:361
void ToUc()
Definition: dt.cpp:667
int MxBfL
Definition: dt.h:79
bool IsSuffix(const char *CStr) const
Definition: dt.cpp:518
static const char CrCh
Definition: dt.h:1039
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
static char GetUsFromYuAscii(const char &Ch)
Definition: dt.cpp:1885
static bool Intersection(const TFltRect &Rect1, const TFltRect &Rect2)
Definition: dt.cpp:2317
static TStr GetNrNumFExt(const int &FExtN)
Definition: dt.cpp:1460
double GetUniDev()
Definition: dt.h:30
static TStr GetStr(const bool &Val)
Definition: dt.h:1011
uint Len() const
Definition: dt.h:801
void Reserve(const int &_MxBfL, const bool &DoClr=true)
Definition: dt.h:128
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:1815
void Reverse()
Reverses the order of the elements in the vector.
Definition: ds.h:1350
static const double PInf
Definition: dt.h:1393
bool DoFitLen(const int &LBfL) const
Definition: dt.h:82
uint Val
Definition: dt.h:1244
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:2311
static void LoadFrugalIntV(TSIn &SIn, TVec< TInt, int > &IntV, bool ClrP=true)
Definition: dt.cpp:2043
TStr GetStr() const
Definition: dt.h:1462
void CompressWs()
Definition: dt.cpp:581
ldouble Val
Definition: dt.h:1539
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TMem(const int &_MxBfL=0)
Definition: dt.h:84
static const uchar Mx
Definition: dt.h:1098
char * GetBf() const
Definition: dt.h:144
static const TUInt64 Mn
Definition: dt.h:1322
virtual char GetCh()=0
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:1905
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
static TStr PutFExt(const TStr &FNm, const TStr &FExt)
Definition: dt.cpp:1499
static const int Vals
Definition: dt.h:1034
void SplitOnStr(const TStr &SplitStr, TStrV &StrV) const
Definition: dt.cpp:1008
bool GetNextLnBf(TChA &LnChA)
Definition: dt.cpp:1654
bool Check()
Definition: dt.cpp:33
void PutCh(const int &ChN, const char &Ch)
Definition: dt.h:482
static TStr GetStr(const ldouble &Val, const int &Width=-1, const int &Prec=-1)
Definition: dt.cpp:2284
uint GrowBy
Definition: dt.h:783
void SplitOnWs(TStrV &StrV) const
Definition: dt.cpp:972
bool IsUc() const
Definition: dt.cpp:660
static char IsUc(const char &Ch)
Definition: dt.h:1081
TChA & ToTrunc()
Definition: dt.cpp:568
TStr operator+(const TStr &LStr, const TStr &RStr)
Definition: dt.cpp:1631
static const int Vals
Definition: dt.h:980
char * Bf
Definition: dt.h:703
static const int m
Definition: dt.h:15
char * CStr()
Definition: dt.h:479
int BfL
Definition: dt.h:162
TStr()
Definition: dt.h:423
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:2303
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int GetBf(const void *LBf, const TSize &LBfL)
Definition: dt.cpp:644
void SplitOnLastCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
Definition: dt.cpp:912
double GetMnX() const
Definition: dt.h:1599
uint AddStr(const char *Str, const uint &Len)
Definition: dt.cpp:1711
TStr GetFBase() const
Definition: dt.cpp:1396
static uint GetUIntFromIpStr(const TStr &IpStr, const char &SplitCh= '.')
Definition: dt.cpp:2107
int GetPrimHashCd() const
Definition: dt.cpp:607
::TSize GrowBy
Definition: dt.h:836
void SplitOnAllAnyCh(const TStr &SplitChStr, TStrV &StrV, const bool &SkipEmpty=true) const
Definition: dt.cpp:944
void InsStr(const int &BChN, const TStr &Str)
Definition: dt.cpp:825
int BfL
Definition: dt.h:704
int CountCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:1033
static const TStr TrueStr
Definition: dt.h:984
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm)
Definition: dt.cpp:2258
bool GetNextLnBf(TChA &LnChA)
Definition: dt.cpp:652
TStr RightOfLast(const char &SplitCh) const
Definition: dt.cpp:894
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
Definition: ds.h:2247
static const TUInt64 Mx
Definition: dt.h:1323
static const uchar Mn
Definition: dt.h:1097
static bool IsAbsFPath(const TStr &FPath)
Definition: dt.cpp:1491
TStrPool(const uint &MxBfLen=0, const uint &_GrowBy=16 *1024 *1024)
Definition: dt.cpp:1679
Definition: fl.h:535
Definition: dt.h:1318
static const double Eps
Definition: dt.h:1394
bool IsUInt64() const
Definition: dt.h:605
int ChangeStr(const TStr &SrcStr, const TStr &DstStr, const int &BChN=0)
Definition: dt.cpp:1130
static TRnd Rnd
Definition: dt.h:1396
static const double Mn
Definition: dt.h:1390
uint BfL
Definition: dt.h:783
char * Bf
Definition: dt.h:837
Definition: dt.h:346
char Val
Definition: dt.h:1030
bool Empty() const
Definition: ds.h:2245
static int GetPrimHashCd(const char *p)
Definition: hash.h:1253
void ChangeCh(const char &SrcCh, const char &DstCh)
Definition: dt.cpp:537
void SaveXml(TSOut &SOut, const TStr &Nm) const
Definition: dt.cpp:2156
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2256
static TStr GetFNmStr(const TStr &Str, const bool &AlNumOnlyP=true)
Definition: dt.cpp:1531
TStrPool & operator=(const TStrPool &Pool)
Definition: dt.cpp:1700
static TStr GetXmlStrFromPlainStr(const TChA &PlainChA)
Definition: xml.cpp:968
void Clr(const bool &DoDel=true)
Definition: dt.h:131