SNAP Library, Developer Reference  2012-10-02 12:56:23
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
dt.h
Go to the documentation of this file.
00001 
00002 // Forward
00003 class TILx;
00004 class TOLx;
00005 ClassHdTP(TXmlTok, PXmlTok);
00006 
00008 // Random
00009 class TRnd{
00010 public:
00011   static const int RndSeed;
00012 private:
00013   static const int a, m, q, r;
00014   int Seed;
00015   int GetNextSeed(){
00016     if ((Seed=a*(Seed%q)-r*(Seed/q))>0){return Seed;} else {return Seed+=m;}}
00017 public:
00018   TRnd(const int& _Seed=1, const int& Steps=0){
00019     PutSeed(_Seed); Move(Steps);}
00020   explicit TRnd(TSIn& SIn){SIn.Load(Seed);}
00021   void Save(TSOut& SOut) const {SOut.Save(Seed);}
00022   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00023   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00024 
00025   TRnd& operator=(const TRnd& Rnd){Seed=Rnd.Seed; return *this;}
00026   bool operator==(const TRnd&) const {Fail; return false;}
00027 
00028   double GetUniDev(){return GetNextSeed()/double(m);}
00029   int GetUniDevInt(const int& Range=0);
00030   int GetUniDevInt(const int& MnVal, const int& MxVal){
00031     IAssert(MnVal<=MxVal); return MnVal+GetUniDevInt(MxVal-MnVal+1);}
00032   uint GetUniDevUInt(const uint& Range=0);
00033   double GetNrmDev();
00034   double GetNrmDev(
00035    const double& Mean, const double& SDev, const double& Mn, const double& Mx);
00036   double GetExpDev();
00037   double GetExpDev(const double& Lambda); // mean=1/lambda
00038   double GetGammaDev(const int& Order);
00039   double GetPoissonDev(const double& Mean);
00040   double GetBinomialDev(const double& Prb, const int& Trials);
00041   int GetGeoDev(const double& Prb){
00042     return 1+(int)floor(log(1.0-GetUniDev())/log(1.0-Prb));}
00043   double GetPowerDev(const double& AlphaSlope){ // power-law degree distribution (AlphaSlope>0)
00044     IAssert(AlphaSlope>1.0);
00045     return pow(1.0-GetUniDev(), -1.0/(AlphaSlope-1.0));}
00046   //void GetSphereDev(const int& Dim, TFltV& ValV);
00047 
00048   void PutSeed(const int& _Seed);
00049   int GetSeed() const {return Seed;}
00050   void Randomize(){PutSeed(RndSeed);}
00051   void Move(const int& Steps);
00052   bool Check();
00053 
00054   static double GetUniDevStep(const int& Seed, const int& Steps){
00055     TRnd Rnd(Seed); Rnd.Move(Steps); return Rnd.GetUniDev();}
00056   static double GetNrmDevStep(const int& Seed, const int& Steps){
00057     TRnd Rnd(Seed); Rnd.Move(Steps); return Rnd.GetNrmDev();}
00058   static double GetExpDevStep(const int& Seed, const int& Steps){
00059     TRnd Rnd(Seed); Rnd.Move(Steps); return Rnd.GetExpDev();}
00060 
00061   static TRnd LoadTxt(TILx& Lx);
00062   void SaveTxt(TOLx& Lx) const;
00063 };
00064 
00066 // Memory
00067 ClassTP(TMem, PMem)//{
00068 private:
00069   int MxBfL, BfL;
00070   char* Bf;
00071   void Resize(const int& _MxBfL);
00072   bool DoFitLen(const int& LBfL) const {return BfL+LBfL<=MxBfL;}
00073 public:
00074   TMem(const int& _MxBfL=0):
00075     MxBfL(_MxBfL), BfL(0), Bf(NULL){ IAssert(BfL>=0);
00076     if (MxBfL>0){Bf=new char[MxBfL]; IAssert(Bf!=NULL);}}
00077   static PMem New(const int& MxBfL=0){return new TMem(MxBfL);}
00078   TMem(const void* _Bf, const int& _BfL):
00079     MxBfL(_BfL), BfL(_BfL), Bf(NULL){ IAssert(BfL>=0);
00080     if (BfL>0){Bf=new char[BfL]; IAssert(Bf!=NULL); memcpy(Bf, _Bf, BfL);}}
00081   static PMem New(const void* Bf, const int& BfL){return new TMem(Bf, BfL);}
00082   TMem(const TMem& Mem):
00083     MxBfL(Mem.MxBfL), BfL(Mem.BfL), Bf(NULL){
00084     if (MxBfL>0){Bf=new char[MxBfL]; memcpy(Bf, Mem.Bf, BfL);}}
00085   static PMem New(const TMem& Mem){return new TMem(Mem);}
00086   static PMem New(const PMem& Mem){return new TMem(*Mem);}
00087   TMem(const TStr& Str);
00088   static PMem New(const TStr& Str){return new TMem(Str);}
00089   ~TMem(){if (Bf!=NULL){delete[] Bf;}}
00090   explicit TMem(TSIn& SIn){
00091     SIn.Load(MxBfL); SIn.Load(BfL);
00092     Bf=new char[MxBfL=BfL]; SIn.LoadBf(Bf, BfL);}
00093   void Save(TSOut& SOut) const {
00094     SOut.Save(MxBfL); SOut.Save(BfL); SOut.SaveBf(Bf, BfL);}
00095   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00096   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00097 
00098   TMem& operator=(const TMem& Mem){
00099     if (this!=&Mem){
00100       if (Bf!=NULL){delete[] Bf;}
00101       MxBfL=Mem.MxBfL; BfL=Mem.BfL; Bf=NULL;
00102       if (MxBfL>0){Bf=new char[MxBfL]; memcpy(Bf, Mem.Bf, BfL);}}
00103     return *this;}
00104   char* operator()() const {return Bf;}
00105   TMem& operator+=(const char& Ch);
00106   TMem& operator+=(const TMem& Mem);
00107   TMem& operator+=(const TStr& Str);
00108   TMem& operator+=(const PSIn& SIn);
00109   char& operator[](const int& ChN) const {
00110     Assert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
00111   int GetMemUsed() const {return 2*sizeof(int)+sizeof(char*)+MxBfL;}
00112 
00113   void Gen(const int& _BfL){
00114     Clr(); Resize(_BfL); BfL=_BfL;}
00115   void GenZeros(const int& _BfL){
00116     Clr(false); Resize(_BfL); BfL=_BfL;
00117     if (BfL > 0) memset(Bf, 0, BfL);}
00118   void Reserve(const int& _MxBfL, const bool& DoClr = true){
00119           if (DoClr){ Clr(); } Resize(_MxBfL);}
00120   void Del(const int& BChN, const int& EChN);
00121   void Clr(const bool& DoDel=true){
00122     if (DoDel){if (Bf!=NULL){delete[] Bf;} MxBfL=0; BfL=0; Bf=NULL;}
00123     else {BfL=0;}}
00124   int Len() const {return BfL;}
00125   bool Empty() const {return BfL==0;}
00126   void Trunc(const int& _BfL){
00127     if ((0<=_BfL)&&(_BfL<=BfL)){BfL=_BfL;}}
00128   void Push(const char& Ch){operator+=(Ch);}
00129   char Pop(){IAssert(BfL>0); BfL--; return Bf[BfL];}
00130 
00131   bool DoFitStr(const TStr& Str) const;
00132   //int AddStr(const TStr& Str);
00133   void AddBf(const void* Bf, const int& BfL);
00134   char* GetBf() const {return Bf;}
00135   TStr GetAsStr(const char& NewNullCh='\0') const;
00136   PSIn GetSIn() const {
00137     TMOut MOut(BfL); MOut.SaveBf(Bf, BfL); return MOut.GetSIn();}
00138 
00139   static void LoadMem(const PSIn& SIn, TMem& Mem){
00140     Mem.Clr(); Mem.Gen(SIn->Len()); SIn->GetBf(Mem.Bf, SIn->Len());}
00141   static void LoadMem(const PSIn& SIn, const PMem& Mem){
00142     Mem->Clr(); Mem->Gen(SIn->Len()); SIn->GetBf(Mem->Bf, SIn->Len());}
00143   void SaveMem(const PSOut& SOut) const {SOut->SaveBf(Bf, Len());}
00144 };
00145 
00147 // Input-Memory
00148 class TMemIn: public TSIn{
00149 private:
00150   PMem Mem;
00151   const char* Bf;
00152   int BfC, BfL;
00153 public:
00154   TMemIn(const TMem& _Mem, const int& _BfC=0);
00155   static PSIn New(const TMem& Mem){
00156     return PSIn(new TMemIn(Mem));}
00157   static PSIn New(const PMem& Mem){
00158     TMemIn* MemIn=new TMemIn(*Mem); MemIn->Mem=Mem; return PSIn(MemIn);}
00159   ~TMemIn(){}
00160 
00161   bool Eof(){return BfC==BfL;}
00162   int Len() const {return BfL-BfC;}
00163   char GetCh(){Assert(BfC<BfL); return Bf[BfC++];}
00164   char PeekCh(){Assert(BfC<BfL); return Bf[BfC];}
00165   int GetBf(const void* LBf, const TSize& LBfL);
00166   void Reset(){Cs=TCs(); BfC=0;}
00167 };
00168 
00170 // Output-Memory
00171 class TMemOut: public TSOut{
00172 private:
00173   PMem Mem;
00174 private:
00175   void FlushBf();
00176 public:
00177   TMemOut(const PMem& _Mem);
00178   static PSOut New(const PMem& Mem){
00179     return new TMemOut(Mem);}
00180   ~TMemOut(){}
00181 
00182   int PutCh(const char& Ch){
00183     Mem->operator+=(Ch); return Ch;}
00184   int PutBf(const void* LBf, const TSize& LBfL);
00185   void Flush(){}
00186 };
00187 
00189 // Char-Array
00190 class TChA{
00191 private:
00192   int MxBfL, BfL;
00193   char* Bf;
00194   void Resize(const int& _MxBfL);
00195 public:
00196   explicit TChA(const int& _MxBfL=256){
00197     Bf=new char[(MxBfL=_MxBfL)+1]; Bf[BfL=0]=0;}
00198   TChA(const char* CStr){
00199     Bf=new char[(MxBfL=BfL=int(strlen(CStr)))+1]; strcpy(Bf, CStr);}
00200   TChA(const char* CStr, const int& StrLen) : MxBfL(StrLen), BfL(StrLen) {
00201     Bf=new char[StrLen+1]; strncpy(Bf, CStr, StrLen); Bf[StrLen]=0;}
00202   TChA(const TChA& ChA){
00203     Bf=new char[(MxBfL=ChA.MxBfL)+1]; BfL=ChA.BfL; strcpy(Bf, ChA.CStr());}
00204   TChA(const TStr& Str);
00205   TChA(const TMem& Mem){
00206     Bf=new char[(MxBfL=BfL=Mem.Len())+1]; Bf[MxBfL]=0;
00207     memcpy(CStr(), Mem(), Mem.Len());}
00208   ~TChA(){delete[] Bf;}
00209   explicit TChA(TSIn& SIn){
00210     SIn.Load(MxBfL); SIn.Load(BfL); SIn.Load(Bf, MxBfL, BfL);}
00211   void Load(TSIn& SIn){ delete[] Bf;
00212     SIn.Load(MxBfL); SIn.Load(BfL); SIn.Load(Bf, MxBfL, BfL);}
00213   void Save(TSOut& SOut, const bool& SaveCompact=true) const { //J:
00214     SOut.Save(SaveCompact?BfL:MxBfL); SOut.Save(BfL); SOut.Save(Bf, BfL);}
00215   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00216   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00217 
00218   TChA& operator=(const TChA& ChA);
00219   TChA& operator=(const TStr& Str);
00220   TChA& operator=(const char* CStr);
00221   bool operator==(const TChA& ChA) const {return strcmp(CStr(), ChA.CStr())==0;}
00222   bool operator==(const char* _CStr) const {return strcmp(CStr(), _CStr)==0;}
00223   bool operator==(const char& Ch) const {return (BfL==1)&&(Bf[0]==Ch);}
00224   bool operator!=(const TChA& ChA) const {return strcmp(CStr(), ChA.CStr())!=0;}
00225   bool operator!=(const char* _CStr) const {return strcmp(CStr(), _CStr)!=0;}
00226   bool operator!=(const char& Ch) const {return !((BfL==1)&&(Bf[0]==Ch));}
00227   bool operator<(const TChA& ChA) const {return strcmp(CStr(), ChA.CStr())<0;}
00228 
00229   TChA& operator+=(const TMem& Mem);
00230   TChA& operator+=(const TChA& ChA);
00231   TChA& operator+=(const TStr& Str);
00232   TChA& operator+=(const char* CStr);
00233   TChA& operator+=(const char& Ch){
00234     if (BfL==MxBfL){Resize(BfL+1);}
00235     Bf[BfL]=Ch; BfL++; Bf[BfL]=0; return *this;}
00236   char operator[](const int& ChN) const {
00237     Assert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
00238   char& operator[](const int& ChN){
00239     Assert((0<=ChN)&&(ChN<BfL)); return Bf[ChN];}
00240   int GetMemUsed() const {return 2*sizeof(int)+sizeof(char*)+sizeof(char)*MxBfL;}
00241 
00242   char* operator ()(){return Bf;}
00243   const char* operator ()() const {return Bf;}
00244   char* CStr() {return Bf;}
00245   const char* CStr() const {return Bf;}
00246 
00247   void Clr(){Bf[BfL=0]=0;}
00248   int Len() const {return BfL;}
00249   bool Empty() const {return BfL==0;}
00250   void Ins(const int& BChN, const char* CStr);
00251   void Del(const int& ChN);
00252   void DelLastCh(){Pop();}
00253   void Push(const char& Ch){operator+=(Ch);}
00254   char Pop(){IAssert(BfL>0); BfL--; char Ch=Bf[BfL]; Bf[BfL]=0; return Ch;}
00255   void Trunc();
00256   void Trunc(const int& _BfL){
00257     if ((0<=_BfL)&&(_BfL<=BfL)){Bf[BfL=_BfL]=0;}}
00258   void Reverse();
00259 
00260   void AddCh(const char& Ch, const int& MxLen=-1){
00261     if ((MxLen==-1)||(BfL<MxLen)){operator+=(Ch);}}
00262   void AddChTo(const char& Ch, const int& ToChN){
00263     while (Len()<ToChN){AddCh(Ch);}}
00264   void PutCh(const int& ChN, const char& Ch){
00265     Assert((0<=ChN)&&(ChN<BfL)); Bf[ChN]=Ch;}
00266   char GetCh(const int& ChN) const {return operator[](ChN);}
00267   char LastCh() const { Assert(1<=BfL); return Bf[BfL-1]; }
00268   char LastLastCh() const { Assert(2<=BfL); return Bf[BfL-2]; }
00269 
00270   TChA GetSubStr(const int& BChN, const int& EChN) const;
00271 
00272   int CountCh(const char& Ch, const int& BChN=0) const;
00273   int SearchCh(const char& Ch, const int& BChN=0) const;
00274   int SearchChBack(const char& Ch, int BChN=-1) const;
00275   int SearchStr(const TChA& Str, const int& BChN=0) const;
00276   int SearchStr(const TStr& Str, const int& BChN=0) const;
00277   int SearchStr(const char* CStr, const int& BChN=0) const;
00278   bool IsStrIn(const TStr& Str) const {return SearchStr(Str)!=-1;}
00279   bool IsPrefix(const char* CStr, const int& BChN=0) const;
00280   bool IsPrefix(const TStr& Str) const;
00281   bool IsPrefix(const TChA& Str) const;
00282   bool IsSuffix(const char* CStr) const;
00283   bool IsSuffix(const TStr& Str) const;
00284   bool IsSuffix(const TChA& Str) const;
00285 
00286   bool IsChIn(const char& Ch) const {return SearchCh(Ch)!=-1;}
00287   void ChangeCh(const char& SrcCh, const char& DstCh);
00288   TChA& ToUc();
00289   TChA& ToLc();
00290   TChA& ToTrunc();
00291   void CompressWs();
00292   void Swap(const int& ChN1, const int& ChN2);
00293   void Swap(TChA& ChA);
00294 
00295   int GetPrimHashCd() const;
00296   int GetSecHashCd() const;
00297 
00298   static void LoadTxt(const PSIn& SIn, TChA& ChA);
00299   void SaveTxt(const PSOut& SOut) const;
00300   
00301   //friend TChA operator+(const TChA& LStr, const TChA& RStr);
00302   //friend TChA operator+(const TChA& LStr, const TStr& RStr);
00303   //friend TChA operator+(const TChA& LStr, const char* RCStr);
00304 };
00305 
00307 // Input-Char-Array
00308 class TChAIn: public TSIn{
00309 private:
00310   const char* Bf;
00311   int BfC, BfL;
00312 private:
00313   TChAIn();
00314   TChAIn(const TChAIn&);
00315   TChAIn& operator=(const TChAIn&);
00316 public:
00317   TChAIn(const TChA& ChA, const int& _BfC=0);
00318   static PSIn New(const TChA& ChA){return PSIn(new TChAIn(ChA));}
00319   ~TChAIn(){}
00320 
00321   bool Eof(){return BfC==BfL;}
00322   int Len() const {return BfL-BfC;}
00323   char GetCh(){Assert(BfC<BfL); return Bf[BfC++];}
00324   char PeekCh(){Assert(BfC<BfL); return Bf[BfC];}
00325   int GetBf(const void* LBf, const TSize& LBfL);
00326   void Reset(){Cs=TCs(); BfC=0;}
00327 };
00328 
00330 // Ref-String
00331 class TRStr{
00332 public:
00333   char* Bf;
00334   int Refs;
00335 public:
00336   TRStr(){Refs=1; Bf=new char[0+1]; Bf[0]=0;}
00337   TRStr(const int& Len){
00338     IAssert(Len>=0); Refs=0; Bf=new char[Len+1]; Bf[Len]=0;}
00339   TRStr(const char* CStr){
00340     Refs=0; Bf=new char[strlen(CStr)+1]; strcpy(Bf, CStr);}
00341   TRStr(const char* CStr, const int& MxLen){
00342     Refs=0; Bf=new char[MxLen+1]; strncpy(Bf, CStr, MxLen); Bf[MxLen]=0;}
00343   TRStr(const char* CStr1, const char* CStr2){
00344     Refs=0; int CStr1Len=int(strlen(CStr1)); Bf=new char[CStr1Len+int(strlen(CStr2))+1];
00345     strcpy(Bf, CStr1); strcpy(Bf+CStr1Len, CStr2);}
00346   TRStr(const char& Ch){
00347     Refs=0; Bf=new char[1+1]; Bf[0]=Ch; Bf[1]=0;}
00348   TRStr(const char& Ch1, const char& Ch2){
00349     Refs=0; Bf=new char[2+1]; Bf[0]=Ch1; Bf[1]=Ch2; Bf[2]=0;}
00350   ~TRStr(){
00351     Assert(((this!=GetNullRStr())&&(Refs==0))||((this==GetNullRStr())&&(Refs==1)));
00352     delete[] Bf;}
00353   explicit TRStr(TSIn& SIn, const bool& IsSmall){
00354     if (IsSmall){Refs=0; SIn.Load(Bf);}
00355     else {Refs=0; int BfL; SIn.Load(BfL); SIn.Load(Bf, BfL, BfL);}}
00356   void Save(TSOut& SOut, const bool& IsSmall) const {
00357     if (IsSmall){SOut.Save(Bf);}
00358     else {int BfL=int(strlen(Bf)); SOut.Save(BfL); SOut.Save(Bf, BfL);}}
00359 
00360   TRStr& operator=(const TRStr&){Fail; return *this;}
00361   int GetMemUsed() const {return int(sizeof(int))+int(strlen(Bf));}
00362 
00363   void MkRef(){Refs++;}
00364   void UnRef(){Assert(Refs>0); if (--Refs==0){delete this;}}
00365 
00366   const char* CStr() const {return Bf;}
00367   char* CStr() {return Bf;}
00368   bool Empty() const {return Bf[0]==0;}
00369   int Len() const {return int(strlen(Bf));}
00370 
00371   void PutCh(const int& ChN, const char& Ch){
00372     Assert((0<=ChN)&&(ChN<Len())); Bf[ChN]=Ch;}
00373   char GetCh(const int& ChN) const {
00374     Assert((0<=ChN)&&(ChN<Len())); return Bf[ChN];}
00375 
00376   bool IsUc() const;
00377   void ToUc();
00378   bool IsLc() const;
00379   void ToLc();
00380   void ToCap();
00381   void ConvUsFromYuAscii();
00382   static int CmpI(const char* CStr1, const char* CStr2);
00383 
00384   int GetPrimHashCd() const;
00385   int GetSecHashCd() const;
00386 
00387   static TRStr* GetNullRStr(){
00388     static TRStr NullRStr; Assert(NullRStr.Bf!=NULL); return &NullRStr;}
00389 };
00390 
00392 // String
00393 class TStr;
00394 template <class TVal> class TVec;
00395 typedef TVec<TStr> TStrV;
00396 
00397 class TStr{
00398 private:
00399   TRStr* RStr;
00400 private:
00401   TStr(const char& Ch, bool){
00402     RStr=new TRStr(Ch); RStr->MkRef();}
00403   TStr(const char& Ch1, const char& Ch2, bool){
00404     RStr=new TRStr(Ch1, Ch2); RStr->MkRef();}
00405   static TRStr* GetRStr(const char* CStr);
00406   void Optimize();
00407 public:
00408   TStr(){RStr=TRStr::GetNullRStr(); RStr->MkRef();}
00409   TStr(const TStr& Str){RStr=Str.RStr; RStr->MkRef();}
00410   TStr(const TChA& ChA){RStr=GetRStr(ChA.CStr()); RStr->MkRef();}
00411   TStr(const TSStr& SStr){RStr=GetRStr(SStr.CStr()); RStr->MkRef();}
00412   TStr(const char* CStr){RStr=GetRStr(CStr); RStr->MkRef();}
00413   explicit TStr(const char& Ch){RStr=GetChStr(Ch).RStr; RStr->MkRef();}
00414   TStr(const TMem& Mem){
00415     RStr=new TRStr(Mem.Len()); RStr->MkRef();
00416     memcpy(CStr(), Mem(), Mem.Len()); Optimize();}
00417   explicit TStr(const PSIn& SIn){
00418     int SInLen=SIn->Len(); RStr=new TRStr(SInLen); RStr->MkRef();
00419     SIn->GetBf(CStr(), SInLen); Optimize();}
00420   ~TStr(){RStr->UnRef();}
00421   explicit TStr(TSIn& SIn, const bool& IsSmall=false):
00422     RStr(new TRStr(SIn, IsSmall)){RStr->MkRef(); Optimize();}
00423   void Load(TSIn& SIn, const bool& IsSmall=false){
00424     *this=TStr(SIn, IsSmall);}
00425   void Save(TSOut& SOut, const bool& IsSmall=false) const {
00426     RStr->Save(SOut, IsSmall);}
00427   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00428   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00429 
00430   TStr& operator=(const TStr& Str){
00431     if (this!=&Str){RStr->UnRef(); RStr=Str.RStr; RStr->MkRef();} return *this;}
00432   TStr& operator=(const TChA& ChA){
00433     RStr->UnRef(); RStr=GetRStr(ChA.CStr()); RStr->MkRef(); return *this;}
00434   TStr& operator=(const char* CStr){
00435     RStr->UnRef(); RStr=GetRStr(CStr); RStr->MkRef(); return *this;}
00436   TStr& operator=(const char& Ch){
00437     RStr->UnRef(); RStr=GetChStr(Ch).RStr; RStr->MkRef(); return *this;}
00438   TStr& operator+=(const TStr& Str){
00439     TRStr* NewRStr=new TRStr(RStr->CStr(), Str.RStr->CStr());
00440     RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
00441     Optimize(); return *this;}
00442   TStr& operator+=(const char* CStr){
00443     TRStr* NewRStr=new TRStr(RStr->CStr(), CStr);
00444     RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
00445     Optimize(); return *this;}
00446   bool operator==(const TStr& Str) const {
00447     return (RStr==Str.RStr)||(strcmp(RStr->CStr(), Str.RStr->CStr())==0);}
00448   bool operator==(const char* CStr) const {
00449     return strcmp(RStr->CStr(), CStr)==0;}
00450 //  bool operator!=(const TStr& Str) const {
00451 //    return strcmp(RStr->CStr(), Str.RStr->CStr())!=0;}
00452   bool operator!=(const char* CStr) const {
00453     return strcmp(RStr->CStr(), CStr)!=0;}
00454   bool operator<(const TStr& Str) const {
00455     return strcmp(RStr->CStr(), Str.RStr->CStr())<0;}
00456   char operator[](const int& ChN) const {return RStr->GetCh(ChN);}
00457   int GetMemUsed() const {return sizeof(TRStr*)+RStr->GetMemUsed();}
00458 
00459   char* operator()(){return RStr->CStr();}
00460   const char* operator()() const {return RStr->CStr();}
00461   char* CStr() {return RStr->CStr();}
00462   const char* CStr() const {return RStr->CStr();}
00463 
00464   void PutCh(const int& ChN, const char& Ch){
00465     TRStr* NewRStr=new TRStr(RStr->CStr());
00466     RStr->UnRef(); RStr=NewRStr; RStr->MkRef();
00467     RStr->PutCh(ChN, Ch); Optimize();}
00468   char GetCh(const int& ChN) const {return RStr->GetCh(ChN);}
00469   char LastCh() const {return GetCh(Len()-1);}
00470 
00471   void Clr(){RStr->UnRef(); RStr=TRStr::GetNullRStr(); RStr->MkRef();}
00472   int Len() const {return RStr->Len();}
00473   bool Empty() const {return RStr->Empty();}
00474 
00475   // upper-case
00476   bool IsUc() const {return RStr->IsUc();}
00477   TStr& ToUc();
00478   TStr GetUc() const {return TStr(*this).ToUc();}
00479   int CmpI(const TStr& Str) const {return TRStr::CmpI(CStr(), Str.CStr());}
00480   bool EqI(const TStr& Str) const {return TRStr::CmpI(CStr(), Str.CStr())==0;}
00481   // lower-case
00482   bool IsLc() const {return RStr->IsLc();}
00483   TStr& ToLc();
00484   TStr GetLc() const {return TStr(*this).ToLc();}
00485   // capitalize
00486   TStr& ToCap();
00487   TStr GetCap() const {return TStr(*this).ToCap();}
00488 
00489   // truncate
00490   TStr& ToTrunc();
00491   TStr GetTrunc() const {return TStr(*this).ToTrunc();}
00492   // Yu-Ascii to Us-Ascii
00493   TStr& ConvUsFromYuAscii();
00494   TStr GetUsFromYuAscii() const {return TStr(*this).ConvUsFromYuAscii();}
00495   // hex
00496   TStr& ToHex();
00497   TStr GetHex() const {return TStr(*this).ToHex();}
00498   TStr& FromHex();
00499   TStr GetFromHex() const {return TStr(*this).FromHex();}
00500 
00501   TStr GetSubStr(const int& BChN, const int& EChN) const;
00502   TStr GetSubStr(const int& BChN) const { return GetSubStr(BChN, Len()-1); }
00503   void InsStr(const int& BChN, const TStr& Str);
00504   void DelChAll(const char& Ch);
00505   void DelSubStr(const int& BChN, const int& EChN);
00506   bool DelStr(const TStr& Str);
00507   TStr LeftOf(const char& SplitCh) const;
00508   TStr LeftOfLast(const char& SplitCh) const;
00509   TStr RightOf(const char& SplitCh) const;
00510   TStr RightOfLast(const char& SplitCh) const;
00511   void SplitOnCh(TStr& LStr, const char& SplitCh, TStr& RStr) const;
00512   void SplitOnLastCh(TStr& LStr, const char& SplitCh, TStr& RStr) const;
00513   void SplitOnAllCh(
00514    const char& SplitCh, TStrV& StrV, const bool& SkipEmpty=true) const;
00515   void SplitOnAllAnyCh(
00516    const TStr& SplitChStr, TStrV& StrV, const bool& SkipEmpty=true) const;
00517   void SplitOnWs(TStrV& StrV) const;
00518   void SplitOnNonAlNum(TStrV& StrV) const;
00519   void SplitOnStr(const TStr& SplitStr, TStrV& StrV) const;
00520   void SplitOnStr(TStr& LeftStr, const TStr& MidStr, TStr& RightStr) const;
00521 
00522   //TStr Left(const int& Chs) const { return Chs>0 ? GetSubStr(0, Chs-1) : GetSubStr(0, Len()-Chs-1);}
00523   //TStr Right(const int& Chs) const {return GetSubStr(Len()-Chs, Len()-1);}
00524   TStr Mid(const int& BChN, const int& Chs) const { return GetSubStr(BChN, BChN+Chs-1); }
00525   TStr Mid(const int& BChN) const {return GetSubStr(BChN, Len()-1); }
00526   //TStr Slice(const int& BChN, const int& EChNP1) const {return GetSubStr(BChN, EChNP1-1);}
00527   //TStr operator()(const int& BChN, const int& EChNP1) const {return Slice(BChN, EChNP1);}
00528   //J: as in python or matlab: 1 is 1st character, -1 is last character
00529   // TODO ROK, ask Jure about this comment
00530   TStr Left(const int& EChN) const { return EChN>0 ? GetSubStr(0, EChN-1) : GetSubStr(0, Len()+EChN-1);}
00531   TStr Right(const int& BChN) const {return BChN>=0 ? GetSubStr(BChN, Len()-1) : GetSubStr(Len()+BChN, Len()-1);}
00532   TStr Slice(int BChN, int EChNP1) const { if(BChN<0){BChN=Len()+BChN;} if(EChNP1<=0){EChNP1=Len()+EChNP1;} return GetSubStr(BChN, EChNP1-1); }
00533   TStr operator()(const int& BChN, const int& EChNP1) const {return Slice(BChN, EChNP1);}
00534 
00535   int CountCh(const char& Ch, const int& BChN=0) const;
00536   int SearchCh(const char& Ch, const int& BChN=0) const;
00537   int SearchChBack(const char& Ch, int BChN=-1) const;
00538   int SearchStr(const TStr& Str, const int& BChN=0) const;
00539   bool IsChIn(const char& Ch) const {return SearchCh(Ch)!=-1;}
00540   bool IsStrIn(const TStr& Str) const {return SearchStr(Str)!=-1;}
00541   bool IsPrefix(const char *Str) const;
00542   bool IsPrefix(const TStr& Str) const {
00543     return IsPrefix(Str.CStr());}
00544   bool IsSuffix(const char *Str) const;
00545   bool IsSuffix(const TStr& Str) const {
00546     return IsSuffix(Str.CStr());}
00547 
00548   int ChangeCh(const char& SrcCh, const char& DstCh, const int& BChN=0);
00549   int ChangeChAll(const char& SrcCh, const char& DstCh);
00550   int ChangeStr(const TStr& SrcStr, const TStr& DstStr, const int& BChN=0);
00551   int ChangeStrAll(const TStr& SrcStr, const TStr& DstStr, const bool& FromStartP=false);
00552   TStr Reverse() const {
00553     TChA ChA(*this); ChA.Reverse(); return ChA;}
00554 
00555   int GetPrimHashCd() const {return RStr->GetPrimHashCd();}
00556   int GetSecHashCd() const {return RStr->GetSecHashCd();}
00557 
00558   bool IsBool(bool& Val) const;
00559 
00560   bool IsInt(
00561    const bool& Check, const int& MnVal, const int& MxVal, int& Val) const;
00562   bool IsInt(int& Val) const {return IsInt(false, 0, 0, Val);}
00563   bool IsInt() const {int Val; return IsInt(false, 0, 0, Val);}
00564   int GetInt() const {int Val; IAssertR(IsInt(false, 0, 0, Val), *this); return Val;}
00565   int GetInt(const int& DfVal) const {
00566     int Val; if (IsInt(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00567 
00568   bool IsUInt(
00569    const bool& Check, const uint& MnVal, const uint& MxVal, uint& Val) const;
00570   bool IsUInt(uint& Val) const {return IsUInt(false, 0, 0, Val);}
00571   bool IsUInt() const {uint Val; return IsUInt(false, 0, 0, Val);}
00572   uint GetUInt() const {uint Val; IAssert(IsUInt(false, 0, 0, Val)); return Val;}
00573   uint GetUInt(const uint& DfVal) const {
00574     uint Val; if (IsUInt(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00575 
00576   bool IsInt64(
00577    const bool& Check, const int64& MnVal, const int64& MxVal, int64& Val) const;
00578   bool IsInt64(int64& Val) const {return IsInt64(false, 0, 0, Val);}
00579   bool IsInt64() const {int64 Val; return IsInt64(false, 0, 0, Val);}
00580   int64 GetInt64() const {
00581     int64 Val; IAssert(IsInt64(false, 0, 0, Val)); return Val;}
00582   int64 GetInt64(const int64& DfVal) const {
00583     int64 Val; if (IsInt64(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00584 
00585   bool IsUInt64(
00586    const bool& Check, const uint64& MnVal, const uint64& MxVal, uint64& Val) const;
00587   bool IsUInt64(uint64& Val) const {return IsUInt64(false, 0, 0, Val);}
00588   bool IsUInt64() const {uint64 Val; return IsUInt64(false, 0, 0, Val);}
00589   uint64 GetUInt64() const {
00590     uint64 Val; IAssert(IsUInt64(false, 0, 0, Val)); return Val;}
00591   uint64 GetUInt64(const uint64& DfVal) const {
00592     uint64 Val; if (IsUInt64(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00593 
00594   bool IsHexInt(const bool& Check, const int& MnVal, const int& MxVal, int& Val) const;
00595   bool IsHexInt(int& Val) const {return IsHexInt(false, 0, 0, Val);}
00596   bool IsHexInt() const {int Val; return IsHexInt(false, 0, 0, Val);}
00597   int GetHexInt() const {
00598     int Val; IAssert(IsHexInt(false, 0, 0, Val)); return Val;}
00599   int GetHexInt(const int& DfVal) const {
00600     int Val; if (IsHexInt(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00601 
00602   bool IsHexInt64(const bool& Check, const int64& MnVal, const int64& MxVal, int64& Val) const;
00603   bool IsHexInt64(int64& Val) const {return IsHexInt64(false, 0, 0, Val);}
00604   bool IsHexInt64() const {int64 Val; return IsHexInt64(false, 0, 0, Val);}
00605   int64 GetHexInt64() const {
00606     int64 Val; IAssert(IsHexInt64(false, 0, 0, Val)); return Val;}
00607   int64 GetHexInt64(const int64& DfVal) const {
00608     int64 Val; if (IsHexInt64(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00609 
00610   bool IsFlt(const bool& Check, const double& MnVal, const double& MxVal,
00611    double& Val, const char& DecDelimCh='.') const;
00612   bool IsFlt(double& Val) const {return IsFlt(false, 0, 0, Val);}
00613   bool IsFlt() const {double Val; return IsFlt(false, 0, 0, Val);}
00614   double GetFlt() const {
00615     double Val; IAssert(IsFlt(false, 0, 0, Val)); return Val;}
00616   double GetFlt(const double& DfVal) const {
00617     double Val; if (IsFlt(false, 0, 0, Val)){return Val;} else {return DfVal;}}
00618 
00619   bool IsWord(const bool& WsPrefixP=true, const bool& FirstUcAllowedP=true) const;
00620   bool IsWs() const;
00621 
00622   bool IsWcMatch(
00623    const int& StrBChN, const TStr& WcStr, const int& WcStrBChN, TStrV& StarStrV,
00624    const char& StarCh='*', const char& QuestCh='?') const;
00625   bool IsWcMatch(
00626    const TStr& WcStr, TStrV& StarStrV,
00627    const char& StarCh='*', const char& QuestCh='?') const;
00628   bool IsWcMatch(const TStr& WcStr, const char& StarCh, const char& QuestCh) const;
00629   bool IsWcMatch(const TStr& WcStr, const int& StarStrN, TStr& StarStr) const;
00630   bool IsWcMatch(const TStr& WcStr) const;
00631   TStr GetWcMatch(const TStr& WcStr, const int& StarStrN=0) const;
00632 
00633   TStr GetFPath() const;
00634   TStr GetFBase() const;
00635   TStr GetFMid() const;
00636   TStr GetFExt() const;
00637   static TStr GetNrFPath(const TStr& FPath);
00638   static TStr GetNrFMid(const TStr& FMid);
00639   static TStr GetNrFExt(const TStr& FExt);
00640   static TStr GetNrNumFExt(const int& FExtN);
00641   static TStr GetNrFNm(const TStr& FNm);
00642   static TStr GetNrAbsFPath(const TStr& FPath, const TStr& BaseFPath=TStr());
00643   static bool IsAbsFPath(const TStr& FPath);
00644   static TStr PutFExt(const TStr& FNm, const TStr& FExt);
00645   static TStr PutFExtIfEmpty(const TStr& FNm, const TStr& FExt);
00646   static TStr PutFBase(const TStr& FNm, const TStr& FBase);
00647   static TStr PutFBaseIfEmpty(const TStr& FNm, const TStr& FBase);
00648   static TStr AddToFMid(const TStr& FNm, const TStr& ExtFMid);
00649   static TStr GetNumFNm(const TStr& FNm, const int& Num);
00650   static TStr GetFNmStr(const TStr& Str, const bool& AlNumOnlyP=true);
00651 
00652   static TStr LoadTxt(const PSIn& SIn){
00653     return TStr(SIn);}
00654   static TStr LoadTxt(const TStr& FNm){
00655     PSIn SIn=TFIn::New(FNm); return LoadTxt(SIn);}
00656   void SaveTxt(const PSOut& SOut) const {
00657     SOut->SaveBf(CStr(), Len());}
00658   void SaveTxt(const TStr& FNm) const {
00659     PSOut SOut=TFOut::New(FNm); SaveTxt(SOut);}
00660 
00661   static TStr& GetChStr(const char& Ch);
00662   static TStr& GetDChStr(const char& Ch1, const char& Ch2);
00663 
00664   TStr GetStr() const {return *this;}
00665   static TStr GetStr(const TStr& Str, const char* FmtStr);
00666   static TStr GetStr(const TStr& Str, const TStr& FmtStr){
00667     return GetStr(Str, FmtStr.CStr());}
00668   static TStr GetStr(const TStrV& StrV, const TStr& DelimiterStr);
00669   static TStr Fmt(const char *FmtStr, ...);
00670   static TStr GetSpaceStr(const int& Spaces);
00671   char* GetCStr() const {
00672     char* Bf=new char[Len()+1]; strcpy(Bf, CStr()); return Bf;}
00673 
00674   static TStr MkClone(const TStr& Str){return TStr(Str.CStr());}
00675   static TStr GetNullStr();
00676 
00677   friend TStr operator+(const TStr& LStr, const TStr& RStr);
00678   friend TStr operator+(const TStr& LStr, const char* RCStr);
00679 };
00680 
00682 // Input-String
00683 class TStrIn: public TSIn{
00684 private:
00685   TStr Str;
00686   char* Bf;
00687   int BfC, BfL;
00688 private:
00689   TStrIn();
00690   TStrIn(const TStrIn&);
00691   TStrIn& operator = (const TStrIn&);
00692 public:
00693   TStrIn(const TStr& _Str);
00694   static PSIn New(const TStr& Str){return PSIn(new TStrIn(Str));}
00695   ~TStrIn(){}
00696 
00697   bool Eof(){return BfC==BfL;}
00698   int Len() const {return BfL-BfC;}
00699   char GetCh(){Assert(BfC<BfL); return Bf[BfC++];}
00700   char PeekCh(){Assert(BfC<BfL); return Bf[BfC];}
00701   int GetBf(const void* LBf, const TSize& LBfL);
00702   void Reset(){Cs=TCs(); BfC=0;}
00703 };
00704 
00706 // Double-String
00707 class TDbStr{
00708 public:
00709   TStr Str1;
00710   TStr Str2;
00711 public:
00712   TDbStr(): Str1(), Str2(){}
00713   TDbStr(const TDbStr& DbStr): Str1(DbStr.Str1), Str2(DbStr.Str2){}
00714   TDbStr(const TStr& _Str1): Str1(_Str1), Str2(){}
00715   TDbStr(const TStr& _Str1, const TStr& _Str2): Str1(_Str1), Str2(_Str2){}
00716   explicit TDbStr(TSIn& SIn): Str1(SIn), Str2(SIn){}
00717   void Save(TSOut& SOut) const {Str1.Save(SOut); Str2.Save(SOut);}
00718 
00719   TDbStr& operator=(const TDbStr& DbStr){
00720     if (this!=&DbStr){Str1=DbStr.Str1; Str2=DbStr.Str2;} return *this;}
00721   bool operator==(const TDbStr& DbStr) const {
00722     return (Str1==DbStr.Str1)&&(Str2==DbStr.Str2);}
00723   bool operator<(const TDbStr& DbStr) const {
00724     return (Str1<DbStr.Str1)||((Str1==DbStr.Str1)&&(Str2<DbStr.Str2));}
00725 
00726   TStr GetStr(const TStr& MidStr=TStr()) const {
00727     if (Filled()){return Str1+MidStr+Str2;} else {return Str1+Str2;}}
00728   int GetPrimHashCd() const {
00729     return Str1.GetPrimHashCd()+Str2.GetPrimHashCd();}
00730   int GetSecHashCd() const {
00731     return Str1.GetSecHashCd()+Str2.GetSecHashCd();}
00732 
00733   bool Empty() const {return (Str1.Empty())&&(Str2.Empty());}
00734   bool Filled() const {return (!Str2.Empty())&&(!Str1.Empty());}
00735 };
00736 
00738 // Simple-String-Pool
00739 //ClassTP(TSStrPool, PSStrPool)//{
00740 //private:
00741 //  TMem Bf;
00742 //public:
00743 //  TSStrPool(const int& MxLen=0): Bf(MxLen){}
00744 //  TSStrPool(TSStrPool& StrPool): Bf(StrPool.Bf){}
00745 //  TSStrPool(TSIn& SIn): Bf(SIn){}
00746 //  void Save(TSOut& SOut) const {Bf.Save(SOut);}
00747 //
00748 //  TSStrPool& operator=(const TSStrPool& StrPool){
00749 //    Bf=StrPool.Bf; return *this;}
00750 //
00751 //  int Len() const {return Bf.Len();}
00752 //  void Clr(){Bf.Clr();}
00753 //  int AddStr(const TStr& Str){
00754 //    if (Str.Empty()){return -1;}
00755 //    else {int StrId=Bf.Len(); Bf+=Str; Bf+=char(0); return StrId;}}
00756 //  TStr GetStr(const int& StrId) const {
00757 //    if (StrId==-1){return "";}
00758 //    else {return TStr(Bf()+StrId);}}
00759 //};
00760 
00762 // String-Pool
00763 ClassTP(TStrPool, PStrPool)//{
00764 private:
00765   uint MxBfL, BfL, GrowBy;
00766   char *Bf;
00767 private:
00768   void Resize(uint _MxBfL);
00769 public:
00770   TStrPool(uint MxBfLen = 0, uint _GrowBy = 16*1024*1024);
00771   TStrPool(TSIn& SIn, bool LoadCompact = true);
00772   TStrPool(const TStrPool& Pool) : MxBfL(Pool.MxBfL), BfL(Pool.BfL), GrowBy(Pool.GrowBy) {
00773     Bf = (char *) malloc(Pool.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, Pool.BfL); }
00774   ~TStrPool() { if (Bf) free(Bf); else IAssertR(MxBfL == 0, TStr::Fmt("size: %u, expected size: 0", MxBfL).CStr());  Bf = 0; MxBfL = 0; BfL = 0; }
00775 
00776   static PStrPool New(uint _MxBfLen = 0, uint _GrowBy = 16*1024*1024) { return PStrPool(new TStrPool(_MxBfLen, _GrowBy)); }
00777   static PStrPool New(TSIn& SIn) { return new TStrPool(SIn); }
00778   static PStrPool New(const TStr& fileName) { PSIn SIn = TFIn::New(fileName); return new TStrPool(*SIn); }
00779   static PStrPool Load(TSIn& SIn, bool LoadCompacted = true) { return PStrPool(new TStrPool(SIn, LoadCompacted)); }
00780   void Save(TSOut& SOut) const;
00781   void Save(const TStr& FNm){PSOut SOut=TFOut::New(FNm); Save(*SOut);}
00782 
00783   uint Len() const { return BfL; }
00784   uint Size() const { return MxBfL; }
00785   bool Empty() const { return ! Len(); }
00786   char* operator () () const { return Bf; }
00787   TStrPool& operator = (const TStrPool& Pool);
00788 
00789   uint AddStr(const char *Str, uint Len);
00790   uint AddStr(const char *Str) { return AddStr(Str, uint(strlen(Str)) + 1); }
00791   uint AddStr(const TStr& Str) { return AddStr(Str.CStr(), Str.Len() + 1); }
00792 
00793   TStr GetStr(uint Offset) const { Assert(Offset < BfL);
00794     if (Offset == 0) return TStr::GetNullStr(); else return TStr(Bf + Offset); }
00795   const char *GetCStr(uint Offset) const { Assert(Offset < BfL);
00796     if (Offset == 0) return TStr::GetNullStr().CStr(); else return Bf + Offset; }
00797 
00798   // Clr() removes the empty string at the start.
00799   // Call AddStr("") after Clr(), if you want to use the pool again.
00800   void Clr(bool DoDel = false) { BfL = 0; if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
00801   int Cmp(uint Offset, const char *Str) const { Assert(Offset < BfL);
00802     if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
00803 
00804   static int GetPrimHashCd(const char *CStr);
00805   static int GetSecHashCd(const char *CStr);
00806   int GetPrimHashCd(uint Offset) { Assert(Offset < BfL);
00807     if (Offset != 0) return GetPrimHashCd(Bf + Offset); else return GetPrimHashCd(""); }
00808   int GetSecHashCd(uint Offset) { Assert(Offset < BfL);
00809     if (Offset != 0) return GetSecHashCd(Bf + Offset); else return GetSecHashCd(""); }
00810 };
00811 
00813 // String-Pool-64bit
00814 ClassTP(TStrPool64, PStrPool64)//{
00815 private:
00816   ::TSize MxBfL, BfL, GrowBy;
00817   char *Bf;
00818 private:
00819   void Resize(const ::TSize& _MxBfL);
00820 public:
00821   TStrPool64(::TSize _MxBfL = 0, ::TSize _GrowBy = 16*1024*1024);
00822   TStrPool64(const TStrPool64& StrPool);
00823   TStrPool64(TSIn& SIn, bool LoadCompact = true);
00824   ~TStrPool64() { Clr(true); }
00825   void Save(TSOut& SOut) const;
00826 
00827   static PStrPool64 New(::TSize MxBfL = 0, ::TSize GrowBy = 16*1024*1024) { 
00828       return PStrPool64(new TStrPool64(MxBfL, GrowBy)); }
00829   static PStrPool64 Load(TSIn& SIn, bool LoadCompact = true) { 
00830       return PStrPool64(new TStrPool64(SIn, LoadCompact)); }
00831 
00832   TStrPool64& operator=(const TStrPool64& StrPool);
00833 
00834   uint64 GetMemUsed() const { return 3*sizeof(::TSize) + uint64(MxBfL); }
00835 
00836   bool Empty() const { return (BfL == 0); }
00837   uint64 Len() const {return BfL;}
00838   uint64 Reserved() const { return MxBfL; }
00839   void Clr(bool DoDel = false);
00840   int Cmp(uint64 Offset, const char *Str) const { Assert(Offset < BfL);
00841     if (Offset != 0) return strcmp(Bf + Offset, Str); else return strcmp("", Str); }
00842 
00843   uint64 AddStr(const TStr& Str);
00844   TStr GetStr(const uint64& StrId) const;
00845 };
00846 
00848 // Void
00849 class TVoid{
00850 public:
00851   TVoid(){}
00852   TVoid(TSIn&){}
00853   void Save(TSOut&) const {}
00854   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00855   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00856 
00857   TVoid& operator=(const TVoid&){return *this;}
00858   bool operator==(const TVoid&) const {return true;}
00859   bool operator<(const TVoid&) const {Fail; return false;}
00860   int GetMemUsed() const {return sizeof(TVoid);}
00861 };
00862 
00864 // Boolean
00865 class TBool{
00866 public:
00867   bool Val;
00868 public:
00869   static const bool Mn;
00870   static const bool Mx;
00871   static const int Vals;
00872   static TRnd Rnd;
00873 
00874   static const TStr FalseStr;
00875   static const TStr TrueStr;
00876   static const TStr NStr;
00877   static const TStr YStr;
00878   static const TStr NoStr;
00879   static const TStr YesStr;
00880 
00881   TBool(): Val(false){}
00882   TBool(const bool& _Val): Val(_Val){}
00883   operator bool() const {return Val;}
00884   explicit TBool(TSIn& SIn){SIn.Load(Val);}
00885   void Load(TSIn& SIn){SIn.Load(Val);}
00886   void Save(TSOut& SOut) const {SOut.Save(Val);}
00887   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00888   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00889 
00890   TBool& operator=(const TBool& Bool){Val=Bool.Val; return *this;}
00891   bool operator==(const TBool& Bool) const {return Val==Bool.Val;}
00892   bool operator<(const TBool& Bool) const {//return Val<Bool.Val;
00893     return (Val==false)&&(Bool.Val==true);}
00894   bool operator()() const {return Val;}
00895   int GetMemUsed() const {return sizeof(TBool);}
00896 
00897   int GetPrimHashCd() const {return Val;}
00898   int GetSecHashCd() const {return Val;}
00899 
00900   static bool GetRnd(){return Rnd.GetUniDevInt(2)==1;}
00901 
00902   static TStr GetStr(const bool& Val){
00903     if (Val){return TrueStr;} else {return FalseStr;}}
00904   static TStr GetStr(const TBool& Bool){
00905     return GetStr(Bool.Val);}
00906   static TStr GetYNStr(const bool& Val){
00907     if (Val){return YStr;} else {return NStr;}}
00908   static TStr GetYesNoStr(const bool& Val){
00909     if (Val){return YesStr;} else {return NoStr;}}
00910   static TStr Get01Str(const bool& Val){
00911     if (Val){return "1";} else {return "0";}}
00912   static bool IsValStr(const TStr& Str);
00913   static bool GetValFromStr(const TStr& Str);
00914   static bool GetValFromStr(const TStr& Str, const bool& DfVal);
00915 };
00916 
00918 // Char
00919 class TCh{
00920 public:
00921   char Val;
00922 public:
00923   static const char Mn;
00924   static const char Mx;
00925   static const int Vals;
00926 
00927   static const char NullCh;
00928   static const char TabCh;
00929   static const char LfCh;
00930   static const char CrCh;
00931   static const char EofCh;
00932   static const char HashCh;
00933 
00934   TCh(): Val(TCh::NullCh){}
00935   TCh(const char& _Val): Val(_Val){}
00936   operator char() const {return Val;}
00937   explicit TCh(TSIn& SIn){SIn.Load(Val);}
00938   void Save(TSOut& SOut) const {SOut.Save(Val);}
00939   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00940   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00941 
00942   TCh& operator=(const TCh& Ch){Val=Ch.Val; return *this;}
00943   bool operator==(const TCh& Ch) const {return Val==Ch.Val;}
00944   bool operator<(const TCh& Ch) const {return Val<Ch.Val;}
00945   char operator()() const {return Val;}
00946   int GetMemUsed() const {return sizeof(TCh);}
00947 
00948   int GetPrimHashCd() const {return Val;}
00949   int GetSecHashCd() const {return Val;}
00950 
00951   static bool IsWs(const char& Ch){
00952     return (Ch==' ')||(Ch==TabCh)||(Ch==CrCh)||(Ch==LfCh);}
00953   static bool IsAlpha(const char& Ch){
00954     return (('A'<=Ch)&&(Ch<='Z'))||(('a'<=Ch)&&(Ch<='z'));}
00955   static bool IsNum(const char& Ch){return ('0'<=Ch)&&(Ch<='9');}
00956   static bool IsAlNum(const char& Ch){return IsAlpha(Ch)||IsNum(Ch);}
00957   static int GetNum(const char& Ch){Assert(IsNum(Ch)); return Ch-'0';}
00958   static bool IsHex(const char& Ch){return
00959     (('0'<=Ch)&&(Ch<='9'))||(('A'<=Ch)&&(Ch<='F'))||(('a'<=Ch)&&(Ch<='f'));}
00960   static int GetHex(const char& Ch){
00961     if (('0'<=Ch)&&(Ch<='9')){return Ch-'0';}
00962     else if (('A'<=Ch)&&(Ch<='F')){return Ch-'A'+10;}
00963     else if (('a'<=Ch)&&(Ch<='f')){return Ch-'a'+10;}
00964     else Fail; return 0;}
00965   static char GetHexCh(const int& Val){
00966     if ((0<=Val)&&(Val<=9)){return char('0'+char(Val));}
00967     else if ((10<=Val)&&(Val<=15)){return char('A'+char(Val-10));}
00968     else Fail; return 0;}
00969   static char IsUc(const char& Ch){
00970     return ('A'<=Ch)&&(Ch<='Z');}
00971   static char GetUc(const char& Ch){
00972     if (('a'<=Ch)&&(Ch<='z')){return Ch-'a'+'A';} else {return Ch;}}
00973   static char GetUsFromYuAscii(const char& Ch);
00974 
00975   static TStr GetStr(const TCh& Ch){
00976     return TStr(Ch.Val);}
00977 };
00978 
00980 // Unsigned-Char
00981 class TUCh{
00982 public:
00983   uchar Val;
00984 public:
00985   static const uchar Mn;
00986   static const uchar Mx;
00987   static const int Vals;
00988 
00989   TUCh(): Val(TCh::NullCh){}
00990   TUCh(const uchar& _Val): Val(_Val){}
00991   operator uchar() const {return Val;}
00992   explicit TUCh(TSIn& SIn){SIn.Load(Val);}
00993   void Save(TSOut& SOut) const {SOut.Save(Val);}
00994   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
00995   void SaveXml(TSOut& SOut, const TStr& Nm) const;
00996 
00997   TUCh& operator=(const TUCh& UCh){Val=UCh.Val; return *this;}
00998   bool operator==(const TUCh& UCh) const {return Val==UCh.Val;}
00999   bool operator<(const TUCh& UCh) const {return Val<UCh.Val;}
01000   uchar operator()() const {return Val;}
01001   int GetMemUsed() const {return sizeof(TUCh);}
01002 
01003   int GetPrimHashCd() const {return Val;}
01004   int GetSecHashCd() const {return Val;}
01005 };
01006 
01008 // Short-Integer
01009 class TSInt{
01010 public:
01011   int16 Val;
01012 public:
01013   TSInt(): Val(0){}
01014   TSInt(const int16& _Val): Val(_Val){}
01015   operator int16() const {return Val;}
01016   explicit TSInt(TSIn& SIn){SIn.Load(Val);}
01017   void Load(TSIn& SIn){SIn.Load(Val);}
01018   void Save(TSOut& SOut) const {SOut.Save(Val);}
01019   int GetPrimHashCd() const {return Val;}
01020   int GetSecHashCd() const {return Val/0x10;}
01021 };
01022 
01024 // Integer
01025 class TInt{
01026 public:
01027   int Val;
01028 public:
01029   static const int Mn;
01030   static const int Mx;
01031   static const int Kilo;
01032   static const int Mega;
01033   static const int Giga;
01034   static TRnd Rnd;
01035 
01036   TInt(): Val(0){}
01037   TInt(const int& _Val): Val(_Val){}
01038   operator int() const {return Val;}
01039   explicit TInt(TSIn& SIn){SIn.Load(Val);}
01040   void Load(TSIn& SIn){SIn.Load(Val);}
01041   void Save(TSOut& SOut) const {SOut.Save(Val);}
01042   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01043   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01044 
01045   TInt& operator=(const TInt& Int){Val=Int.Val; return *this;}
01046   TInt& operator=(const int& Int){Val=Int; return *this;}
01047   bool operator==(const TInt& Int) const {return Val==Int.Val;}
01048   bool operator==(const int& Int) const {return Val==Int;}
01049   bool operator!=(const int& Int) const {return Val!=Int;}
01050   bool operator<(const TInt& Int) const {return Val<Int.Val;}
01051   bool operator<(const int& Int) const {return Val<Int;}
01052   int operator()() const {return Val;}
01053   TInt& operator+=(const int& Int){Val+=Int; return *this;}
01054   TInt& operator-=(const int& Int){Val-=Int; return *this;}
01055   TInt operator++(int){Val++; return *this;}
01056   TInt operator--(int){Val--; return *this;}
01057   int GetMemUsed() const {return sizeof(TInt);}
01058 
01059   int GetPrimHashCd() const {return Val;}
01060   int GetSecHashCd() const {return Val/0x10;}
01061 
01062   static int Abs(const int& Int){return Int<0?-Int:Int;}
01063   static int Sign(const int& Int){return Int<0?-1:(Int>0?1:0);}
01064   static void Swap(int& Int1, int& Int2){
01065     int SwapInt1=Int1; Int1=Int2; Int2=SwapInt1;}
01066   static int GetRnd(const int& Range=0){return Rnd.GetUniDevInt(Range);}
01067 
01068   static bool IsOdd(const int& Int){return ((Int%2)==1);}
01069   static bool IsEven(const int& Int){return ((Int%2)==0);}
01070 
01071   static int GetMn(const int& Int1, const int& Int2){
01072     return Int1<Int2?Int1:Int2;}
01073   static int GetMx(const int& Int1, const int& Int2){
01074     return Int1>Int2?Int1:Int2;}
01075   static int GetMn(const int& Int1, const int& Int2, const int& Int3){
01076     return GetMn(Int1, GetMn(Int2, Int3));}
01077   static int GetMn(const int& Int1, const int& Int2,
01078    const int& Int3, const int& Int4){
01079     return GetMn(GetMn(Int1, Int2), GetMn(Int3, Int4));}
01080   static int GetMx(const int& Int1, const int& Int2, const int& Int3){
01081     return GetMx(Int1, GetMx(Int2, Int3));}
01082   static int GetMx(const int& Int1, const int& Int2,
01083    const int& Int3, const int& Int4){
01084     return GetMx(GetMx(Int1, Int2), GetMx(Int3, Int4));}
01085   static int GetInRng(const int& Val, const int& Mn, const int& Mx){
01086     IAssert(Mn<=Mx); return Val<Mn?Mn:(Val>Mx?Mx:Val);}
01087 
01088   TStr GetStr() const {return TInt::GetStr(Val);}
01089   static TStr GetStr(const int& Val){
01090     char Bf[255]; sprintf(Bf, "%d", Val); return TStr(Bf);}
01091   static TStr GetStr(const TInt& Int){
01092     return GetStr(Int.Val);}
01093   static TStr GetStr(const int& Val, const char* FmtStr);
01094   static TStr GetStr(const int& Val, const TStr& FmtStr){
01095     return GetStr(Val, FmtStr.CStr());}
01096 
01097   static TStr GetHexStr(const int& Val){
01098     char Bf[255]; sprintf(Bf, "%X", Val); return TStr(Bf);}
01099   static TStr GetHexStr(const TInt& Int){
01100     return GetHexStr(Int.Val);}
01101 
01102   static TStr GetKiloStr(const int& Val){
01103     if (Val>=100*1000){return GetStr(Val/1000)+"K";}
01104     else if (Val>=1000){return GetStr(Val/1000)+"."+GetStr((Val%1000)/100)+"K";}
01105     else {return GetStr(Val);}}
01106   static TStr GetMegaStr(const int& Val){
01107     if (Val>=100*1000000){return GetStr(Val/1000000)+"M";}
01108     else if (Val>=1000000){
01109       return GetStr(Val/1000000)+"."+GetStr((Val%1000000)/100000)+"M";}
01110     else {return GetKiloStr(Val);}}
01111 
01112   // frugal
01113   static char* SaveFrugalInt(char *pDest, int i);
01114   static char* LoadFrugalInt(char *pSrc, int& i);
01115   static void TestFrugalInt();
01116   static void SaveFrugalIntV(TSOut& SOut, const TVec<TInt>& IntV);
01117   static void LoadFrugalIntV(TSIn& SIn, TVec<TInt>& IntV, bool ClrP=true);
01118 };
01119 
01121 // Unsigned-Integer
01122 class TUInt{
01123 public:
01124   uint Val;
01125 public:
01126   static const uint Mn;
01127   static const uint Mx;
01128   static TRnd Rnd;
01129 
01130   TUInt(): Val(0){}
01131   TUInt(const uint& _Val): Val(_Val){}
01132   operator uint() const {return Val;}
01133   explicit TUInt(TSIn& SIn){SIn.Load(Val);}
01134   void Load(TSIn& SIn){SIn.Load(Val);}
01135   void Save(TSOut& SOut) const {SOut.Save(Val);}
01136   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01137   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01138 
01139   TUInt& operator=(const TUInt& UInt){Val=UInt.Val; return *this;}
01140   TUInt& operator=(const uint& _Val){Val=_Val; return *this;}
01141   TUInt operator++(int){Val++; return *this;}
01142   TUInt operator--(int){Val--; return *this;}
01143   //bool operator==(const TUInt& UInt) const {return Val==UInt.Val;}
01144   //bool operator==(const uint& UInt) const {return Val==UInt;}
01145   //bool operator!=(const uint& UInt) const {return Val!=UInt;}
01146   //bool operator<(const TUInt& UInt) const {return Val<UInt.Val;}
01147   uint operator()() const {return Val;}
01148   uint& operator()() {return Val;}
01149   TUInt& operator~(){Val=~Val; return *this;}
01150   TUInt& operator&=(const TUInt& UInt){Val&=UInt.Val; return *this;}
01151   TUInt& operator|=(const TUInt& UInt){Val|=UInt.Val; return *this;}
01152   TUInt& operator^=(const TUInt& UInt){Val^=UInt.Val; return *this;}
01153   TUInt& operator>>=(const int& ShiftBits){Val>>=ShiftBits; return *this;}
01154   TUInt& operator<<=(const int& ShiftBits){Val<<=ShiftBits; return *this;}
01155   int GetMemUsed() const {return sizeof(TUInt);}
01156 
01157   int GetPrimHashCd() const {return int(Val);}
01158   int GetSecHashCd() const {return Val/0x10;}
01159 
01160   static uint GetRnd(const uint& Range=0){return Rnd.GetUniDevUInt(Range);}
01161 
01162   TStr GetStr() const {return TUInt::GetStr(Val);}
01163   static TStr GetStr(const uint& Val){
01164     char Bf[255]; sprintf(Bf, "%u", Val); return TStr(Bf);}
01165   static TStr GetStr(const TInt& UInt){
01166     return GetStr(UInt.Val);}
01167   static TStr GetStr(const uint& Val, const char* FmtStr);
01168   static TStr GetStr(const uint& Val, const TStr& FmtStr){
01169     return GetStr(Val, FmtStr.CStr());}
01170 
01171   static TStr GetKiloStr(const uint& Val){
01172     if (Val>100*1000){return GetStr(Val/1000)+"K";}
01173     else if (Val>1000){return GetStr(Val/1000)+"."+GetStr((Val%1000)/100)+"K";}
01174     else {return GetStr(Val);}}
01175   static TStr GetMegaStr(const uint& Val){
01176     if (Val>100*1000000){return GetStr(Val/1000000)+"M";}
01177     else if (Val>1000000){
01178       return GetStr(Val/1000000)+"."+GetStr((Val%1000000)/100000)+"M";}
01179     else {return GetKiloStr(Val);}}
01180 
01181   static uint JavaUIntToCppUInt(const uint& JavaUInt){
01182     uint B1=(JavaUInt & 0xFF000000) >> 24;
01183     uint B2=(JavaUInt & 0x00FF0000) >> 16;
01184     uint B3=(JavaUInt & 0x0000FF00) >> 8;
01185     uint B4=(JavaUInt & 0x000000FF) >> 0;
01186     uint CppUInt=(B4<<24)+(B3<<16)+(B2<<8)+(B1<<0);
01187     return CppUInt;}
01188 
01189   static bool IsIpStr(const TStr& IpStr, uint& Ip, const char& SplitCh = '.');
01190   static bool IsIpStr(const TStr& IpStr, const char& SplitCh = '.') { uint Ip; return IsIpStr(IpStr, Ip, SplitCh); }
01191   static uint GetUIntFromIpStr(const TStr& IpStr, const char& SplitCh = '.');
01192   static TStr GetStrFromIpUInt(const uint& Ip);
01193 };
01194 
01196 // Unsigned-Integer-64Bit
01197 class TUInt64{
01198 public:
01199   uint64 Val;
01200 public:
01201   static const TUInt64 Mn;
01202   static const TUInt64 Mx;
01203 
01204   TUInt64(): Val(0){}
01205   TUInt64(const TUInt64& Int): Val(Int.Val){}
01206   TUInt64(const uint64& Int): Val(Int){}
01207   TUInt64(const uint& MsVal, const uint& LsVal): Val(0){
01208     Val=(((uint64)MsVal) << 32) | ((uint64)LsVal);}
01209   explicit TUInt64(void* Pt): Val(0){
01210      TConv_Pt64Ints32 Conv(Pt); Val=Conv.GetUInt64();}
01211   operator uint64() const {return Val;}
01212   explicit TUInt64(TSIn& SIn){SIn.Load(Val);}
01213   void Load(TSIn& SIn){SIn.Load(Val);}
01214   void Save(TSOut& SOut) const {SOut.Save(Val);}
01215   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01216   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01217 
01218   TUInt64& operator=(const TUInt64& Int){Val=Int.Val; return *this;}
01219   TUInt64& operator+=(const TUInt64& Int){Val+=Int.Val; return *this;}
01220   TUInt64& operator-=(const TUInt64& Int){Val-=Int.Val; return *this;}
01221   TUInt64 operator++(int){Val++; return *this;}
01222   TUInt64 operator--(int){Val--; return *this;}
01223   int GetMemUsed() const {return sizeof(TUInt64);}
01224 
01225   int GetPrimHashCd() const { return (int)GetMsVal() + (int)GetLsVal(); } //TODO: to check
01226   int GetSecHashCd() const { return ((int)GetMsVal() + (int)GetLsVal()) / 0x10; } //TODO: to check
01227 
01228   uint GetMsVal() const {
01229     return (uint)(Val >> 32);}
01230   uint GetLsVal() const {
01231     return (uint)(Val & 0xffffffff);}
01232 
01233   //TStr GetStr() const {return TStr::Fmt("%Lu", Val);}
01234   //static TStr GetStr(const TUInt64& Int){return TStr::Fmt("%Lu", Int.Val);}
01235   //static TStr GetHexStr(const TUInt64& Int){return TStr::Fmt("%LX", Int.Val);}
01236   #ifdef GLib_WIN
01237   TStr GetStr() const {return TStr::Fmt("%I64u", Val);}
01238   static TStr GetStr(const TUInt64& Int){return TStr::Fmt("%I64u", Int.Val);}
01239   static TStr GetHexStr(const TUInt64& Int){return TStr::Fmt("%I64X", Int.Val);}
01240   #else
01241   TStr GetStr() const {return TStr::Fmt("%llu", Val);}
01242   static TStr GetStr(const TUInt64& Int){return TStr::Fmt("%llu", Int.Val);}
01243   static TStr GetHexStr(const TUInt64& Int){return TStr::Fmt("%llX", Int.Val);}
01244   #endif
01245 
01246   static TStr GetKiloStr(const uint64& Val){
01247     if (Val>100*1000){return GetStr(Val/1000)+"K";}
01248     else if (Val>1000){return GetStr(Val/1000)+"."+GetStr((Val%1000)/100)+"K";}
01249     else {return GetStr(Val);}}
01250   static TStr GetMegaStr(const uint64& Val){
01251     if (Val>100*1000000){return GetStr(Val/1000000)+"M";}
01252     else if (Val>1000000){
01253       return GetStr(Val/1000000)+"."+GetStr((Val%1000000)/100000)+"M";}
01254     else {return GetKiloStr(Val);}}
01255   /*static TStr GetGigaStr(const uint64& Val){
01256     if (Val>100*1000000000){return GetStr(Val/1000000000)+"G";}
01257     else if (Val>1000000000){
01258       return GetStr(Val/1000000000)+"."+GetStr((Val%1000000000)/100000000)+"G";}
01259     else {return GetMegaStr(Val);}}*/
01260 };
01261 
01263 // Float
01264 class TFlt{
01265 public:
01266   double Val;
01267 public:
01268   static const double Mn;
01269   static const double Mx;
01270   static const double NInf;
01271   static const double PInf;
01272   static const double Eps;
01273   static const double EpsHalf;
01274   static TRnd Rnd;
01275 
01276   TFlt(): Val(0){}
01277   TFlt(const double& _Val): Val(_Val){}
01278   operator double() const {return Val;}
01279   explicit TFlt(TSIn& SIn){SIn.Load(Val);}
01280   void Save(TSOut& SOut) const {SOut.Save(Val);}
01281   explicit TFlt(TSIn& SIn, const bool& IsTxt){
01282     if (IsTxt){TStr Str(SIn, true); Val=Str.GetFlt(0);} else {SIn.Load(Val);}}
01283   void Load(TSIn& SIn){SIn.Load(Val);}
01284   void Save(TSOut& SOut, const bool& IsTxt) const {
01285     if (IsTxt){GetStr(Val).Save(SOut, true);} else {SOut.Save(Val);}}
01286   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01287   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01288 
01289   TFlt& operator=(const TFlt& Flt){Val=Flt.Val; return *this;}
01290   TFlt& operator=(const double& Flt){Val=Flt; return *this;}
01291   bool operator==(const TFlt& Flt) const _CMPWARN {return Val==Flt.Val;}
01292   bool operator==(const double& Flt) const _CMPWARN {return Val==Flt;}
01293   bool operator!=(const double& Flt) const _CMPWARN {return Val!=Flt;}
01294   double operator()() const {return Val;}
01295   TFlt& operator+=(const double& Flt){Val+=Flt; return *this;}
01296   TFlt& operator-=(const double& Flt){Val-=Flt; return *this;}
01297   TFlt& operator*=(const double& Flt){Val*=Flt; return *this;}
01298   TFlt& operator/=(const double& Flt){Val/=Flt; return *this;}
01299   TFlt operator++(int){Val++; return *this;}
01300   TFlt operator--(int){Val--; return *this;}
01301   int GetMemUsed() const {return sizeof(TFlt);}
01302 
01303   int GetPrimHashCd() const {
01304     int Expn; return int((frexp(Val, &Expn)-0.5)*double(TInt::Mx));}
01305   int GetSecHashCd() const {
01306     int Expn; frexp(Val, &Expn); return Expn;}
01307 
01308   static double Abs(const double& Flt){return Flt<0?-Flt:Flt;}
01309   static int Sign(const double& Flt){return Flt<0?-1:(Flt>0?1:0);}
01310   static int Round(const double& Flt){return int(floor(Flt+0.5));}
01311   static double GetRnd(){return Rnd.GetUniDev();}
01312   static bool Eq6(const double& LFlt, const double& RFlt){
01313     return fabs(LFlt-RFlt)<0.000001;}
01314 
01315   static double GetMn(const double& Flt1, const double& Flt2){
01316     return Flt1<Flt2?Flt1:Flt2;}
01317   static double GetMn(const double& Flt1, const double& Flt2, const double& Flt3){
01318     return GetMn(GetMn(Flt1, Flt2), Flt3); }
01319   static double GetMn(const double& Flt1, const double& Flt2, const double& Flt3, const double& Flt4){
01320     return GetMn(GetMn(Flt1, Flt2), GetMn(Flt3, Flt4)); }
01321 
01322   static double GetMx(const double& Flt1, const double& Flt2){
01323     return Flt1>Flt2?Flt1:Flt2;}
01324   static double GetMx(const double& Flt1, const double& Flt2, const double Flt3){
01325     return GetMx(GetMx(Flt1, Flt2), Flt3); }
01326   static double GetMx(const double& Flt1, const double& Flt2, const double Flt3, const double& Flt4){
01327     return GetMx(GetMx(Flt1, Flt2), GetMx(Flt3, Flt4)); }
01328 
01329   static double GetInRng(const double& Val, const double& Mn, const double& Mx){
01330     IAssert(Mn<=Mx); return Val<Mn?Mn:(Val>Mx?Mx:Val);}
01331   static double IsNum(const double& Val){
01332     return (Mn<=Val)&&(Val<=Mx);}
01333 
01334   TStr GetStr() const {return TFlt::GetStr(Val);}
01335   static TStr GetStr(const double& Val, const int& Width=-1, const int& Prec=-1);
01336   static TStr GetStr(const TFlt& Flt, const int& Width=-1, const int& Prec=-1){
01337     return GetStr(Flt.Val, Width, Prec);}
01338   static TStr GetStr(const double& Val, const char* FmtStr);
01339   static TStr GetStr(const double& Val, const TStr& FmtStr){
01340     return GetStr(Val, FmtStr.CStr());}
01341   static TStr GetPrcStr(const double& RelVal, const double& FullVal){
01342     return GetStr(100*RelVal/FullVal, "%3.0f%%");}
01343 
01344   static TStr GetKiloStr(const double& Val){
01345     if (fabs(Val)>100*1000){return TStr::Fmt("%.0fK", Val/1000);}
01346     else if (fabs(Val)>1000){return TStr::Fmt("%.1fK", Val/1000);}
01347     else {return TStr::Fmt("%.0f", Val);}}
01348   static TStr GetMegaStr(const double& Val){
01349     if (fabs(Val)>100*1000000){return TStr::Fmt("%.0fM", Val/1000000);}
01350     else if (fabs(Val)>1000000){return TStr::Fmt("%.1fM", Val/1000000);}
01351     else {return GetKiloStr(Val);}}
01352   static TStr GetGigaStr(const double& Val){
01353     if (fabs(Val)>100*1000000000.0){return TStr::Fmt("%.0fG", Val/1000000000.0);}
01354     else if (fabs(Val)>1000000000.0){return TStr::Fmt("%.1fG", Val/1000000000.0);}
01355     else {return GetMegaStr(Val);}}
01356 };
01357 
01359 // Ascii-Float
01360 class TAscFlt: public TFlt{
01361 public:
01362   TAscFlt(): TFlt(){}
01363   TAscFlt(const double& Val): TFlt(Val){}
01364   explicit TAscFlt(TSIn& SIn): TFlt(SIn, true){}
01365   void Save(TSOut& SOut) const {TFlt::Save(SOut, true);}
01366 };
01367 
01369 // Short-Float
01370 class TSFlt{
01371 public:
01372   sdouble Val;
01373 public:
01374   static const sdouble Mn;
01375   static const sdouble Mx;
01376 
01377   TSFlt(): Val(0){}
01378   TSFlt(const sdouble& _Val): Val(sdouble(_Val)){}
01379   //TSFlt(const double& _Val): Val(sdouble(_Val)){}
01380   operator sdouble() const {return Val;}
01381   //operator double() const {return Val;}
01382   explicit TSFlt(TSIn& SIn){SIn.Load(Val);}
01383   void Save(TSOut& SOut) const {SOut.Save(Val);}
01384   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01385   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01386 
01387   TSFlt& operator=(const TSFlt& SFlt){Val=SFlt.Val; return *this;}
01388   bool operator==(const TSFlt& SFlt) const _CMPWARN {return Val==SFlt.Val;}
01389   bool operator==(const double& Flt) const _CMPWARN {return Val==Flt;}
01390   bool operator!=(const double& Flt) const _CMPWARN {return Val!=Flt;}
01391   bool operator<(const TSFlt& SFlt) const {return Val<SFlt.Val;}
01392   sdouble operator()() const {return Val;}
01393   TSFlt& operator+=(const double& SFlt){Val+=sdouble(SFlt); return *this;}
01394   TSFlt& operator-=(const double& SFlt){Val-=sdouble(SFlt); return *this;}
01395   TSFlt& operator*=(const double& SFlt){Val*=sdouble(SFlt); return *this;}
01396   TSFlt& operator/=(const double& SFlt){Val/=sdouble(SFlt); return *this;}
01397   TSFlt operator++(int){Val++; return *this;}
01398   TSFlt operator--(int){Val--; return *this;}
01399   int GetMemUsed() const {return sizeof(TSFlt);}
01400 
01401   int GetPrimHashCd() const {
01402     int Expn; return int((frexp(Val, &Expn)-0.5)*double(TInt::Mx));}
01403   int GetSecHashCd() const {
01404     int Expn; frexp(Val, &Expn); return Expn;}
01405 };
01406 
01408 // Long-Float
01409 class TLFlt{
01410 public:
01411   ldouble Val;
01412 public:
01413   static const ldouble Mn;
01414   static const ldouble Mx;
01415 
01416   TLFlt(): Val(0){}
01417   TLFlt(const ldouble& _Val): Val(_Val){}
01418   operator ldouble() const {return Val;}
01419   explicit TLFlt(TSIn& SIn){SIn.Load(Val);}
01420   void Save(TSOut& SOut) const {SOut.Save(Val);}
01421   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01422   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01423 
01424   TLFlt& operator=(const TLFlt& LFlt){Val=LFlt.Val; return *this;}
01425   bool operator==(const TLFlt& LFlt) const _CMPWARN {return Val==LFlt.Val;}
01426   bool operator==(const ldouble& LFlt) const _CMPWARN {return Val==LFlt;}
01427   bool operator!=(const ldouble& LFlt) const _CMPWARN {return Val!=LFlt;}
01428   bool operator<(const TLFlt& LFlt) const {return Val<LFlt.Val;}
01429   ldouble operator()() const {return Val;}
01430   TLFlt& operator+=(const ldouble& LFlt){Val+=LFlt; return *this;}
01431   TLFlt& operator-=(const ldouble& LFlt){Val-=LFlt; return *this;}
01432   int GetMemUsed() const {return sizeof(TLFlt);}
01433 
01434   int GetPrimHashCd() const {Fail; return 0;}
01435   int GetSecHashCd() const {Fail; return 0;}
01436 
01437   static TStr GetStr(const ldouble& Val, const int& Width=-1, const int& Prec=-1);
01438   static TStr GetStr(const TLFlt& LFlt, const int& Width=-1, const int& Prec=-1){
01439     return GetStr(LFlt.Val, Width, Prec);}
01440   static TStr GetStr(const ldouble& Val, const char* FmtStr);
01441   static TStr GetStr(const ldouble& Val, const TStr& FmtStr){
01442     return GetStr(Val, FmtStr.CStr());}
01443 };
01444 
01446 // Float-Rectangle
01447 class TFltRect{
01448 public:
01449   TFlt MnX, MnY, MxX, MxY;
01450 public:
01451   TFltRect():
01452     MnX(), MnY(), MxX(), MxY(){}
01453   TFltRect(const TFltRect& FltRect):
01454     MnX(FltRect.MnX), MnY(FltRect.MnY), MxX(FltRect.MxX), MxY(FltRect.MxY){}
01455   TFltRect(
01456    const double& _MnX, const double& _MnY,
01457    const double& _MxX, const double& _MxY):
01458     MnX(_MnX), MnY(_MnY), MxX(_MxX), MxY(_MxY){}
01459   TFltRect(TSIn& SIn):
01460     MnX(SIn), MnY(SIn), MxX(SIn), MxY(SIn){}
01461   void Save(TSOut& SOut) const {
01462     MnX.Save(SOut); MnY.Save(SOut); MxX.Save(SOut); MxY.Save(SOut);}
01463   void LoadXml(const PXmlTok& XmlTok, const TStr& Nm);
01464   void SaveXml(TSOut& SOut, const TStr& Nm) const;
01465 
01466   TFltRect& operator=(const TFltRect& FltRect){
01467     MnX=FltRect.MnX; MnY=FltRect.MnY; MxX=FltRect.MxX; MxY=FltRect.MxY;
01468     return *this;}
01469 
01470   // get coordinates
01471   double GetMnX() const {return MnX;}
01472   double GetMnY() const {return MnY;}
01473   double GetMxX() const {return MxX;}
01474   double GetMxY() const {return MxY;}
01475 
01476   // get lengths
01477   double GetXLen() const {return MxX-MnX;}
01478   double GetYLen() const {return MxY-MnY;}
01479 
01480   // get centers
01481   double GetXCenter() const {return MnX+(MxX-MnX)/2;}
01482   double GetYCenter() const {return MnY+(MxY-MnY)/2;}
01483 
01484   // tests
01485   bool IsXYIn(const double& X, const double& Y) const {
01486     return (MnX<=X)&&(X<=MxX)&&(MnY<=Y)&&(Y<=MxY);}
01487   static bool Intersection(const TFltRect& Rect1, const TFltRect& Rect2);
01488 
01489   // string
01490   TStr GetStr() const;
01491 };
01492