SNAP Library 2.1, Developer Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
wch.h
Go to the documentation of this file.
00001 
00002 // Wide-Char
00003 class TWCh{
00004 private:
00005   uchar MsVal;
00006   uchar LsVal;
00007 public:
00008   static const TWCh Mn;
00009   static const TWCh Mx;
00010   static const int Vals;
00011 
00012   TWCh(): MsVal(0), LsVal(0){}
00013   TWCh(const uchar& _LsVal): MsVal(0), LsVal(_LsVal){}
00014   TWCh(const uchar& _MsVal, const uchar& _LsVal):
00015     MsVal(_MsVal), LsVal(_LsVal){}
00016   TWCh(const int& _MsVal, const int& _LsVal):
00017     MsVal(uchar(_MsVal)), LsVal(uchar(_LsVal)){}
00018   operator char() const {return LsVal;}
00019   TWCh(TSIn& SIn){SIn.Load(MsVal); SIn.Load(LsVal);}
00020   void Save(TSOut& SOut) const {SOut.Save(MsVal); SOut.Save(MsVal);}
00021 
00022   TWCh& operator=(const TWCh& WCh){
00023     MsVal=WCh.MsVal; LsVal=WCh.LsVal; return *this;}
00024   bool operator==(const TWCh& WCh) const {
00025     return (MsVal==WCh.MsVal)&&(LsVal==WCh.LsVal);}
00026   bool operator<(const TWCh& WCh) const {
00027     return (MsVal<WCh.MsVal)||((MsVal==WCh.MsVal)&&(LsVal<WCh.LsVal));}
00028   int GetMemUsed() const {return sizeof(MsVal)+sizeof(LsVal);}
00029 
00030   int GetPrimHashCd() const {return LsVal;}
00031   int GetSecHashCd() const {return MsVal;}
00032 
00033   char GetCh() const {
00034     if (MsVal==TCh::NullCh){return LsVal;} else {return '#';}}
00035 
00036   static TWCh LoadTxt(const PSIn& SIn){
00037     uchar LsVal=SIn->GetCh(); uchar MsVal=SIn->GetCh();
00038     return TWCh(MsVal, LsVal);}
00039   void SaveTxt(const PSOut& SOut) const {
00040     SOut->PutCh(MsVal); SOut->PutCh(LsVal);}
00041 
00042   static const TWCh StartWCh;
00043   static const TWCh TabWCh;
00044   static const TWCh LfWCh;
00045   static const TWCh CrWCh;
00046   static const TWCh SpaceWCh;
00047 };
00048 typedef TVec<TWCh> TWChV;
00049 
00051 // Wide-Char-Array
00052 class TWChA{
00053 private:
00054   TWChV WChV;
00055   void AddCStr(const char* CStr);
00056   void PutCStr(const char* CStr);
00057 public:
00058   TWChA(const int& MxWChs=0): WChV(MxWChs, 0){}
00059   TWChA(const TWChA& WChA): WChV(WChA.WChV){}
00060   TWChA(const TWChV& _WChV): WChV(_WChV){}
00061   TWChA(const char* CStr): WChV(){PutCStr(CStr);}
00062   TWChA(const TChA& ChA): WChV(){PutCStr(ChA.CStr());}
00063   TWChA(const TStr& Str): WChV(){PutCStr(Str.CStr());}
00064   ~TWChA(){}
00065   TWChA(TSIn& SIn): WChV(SIn){}
00066   void Save(TSOut& SOut){WChV.Save(SOut);}
00067 
00068   TWChA& operator=(const TWChA& WChA){
00069     if (this!=&WChA){WChV=WChA.WChV;} return *this;}
00070   TWChA& operator=(const char* CStr){PutCStr(CStr); return *this;}
00071   TWChA& operator=(const TChA& ChA){PutCStr(ChA.CStr()); return *this;}
00072   TWChA& operator=(const TStr& Str){PutCStr(Str.CStr()); return *this;}
00073   bool operator==(const TWChA& WChA) const {return WChV==WChA.WChV;}
00074   bool operator==(const char* CStr) const {return strcmp(GetStr().CStr(), CStr)!=0;}
00075   TWChA& operator+=(const char& Ch){WChV.Add(TWCh(Ch)); return *this;}
00076   TWChA& operator+=(const TWCh& WCh){WChV.Add(WCh); return *this;}
00077   TWChA& operator+=(const char* CStr){AddCStr(CStr); return *this;}
00078   TWChA& operator+=(const TChA& ChA){AddCStr(ChA.CStr()); return *this;}
00079   TWChA& operator+=(const TStr& Str){AddCStr(Str.CStr()); return *this;}
00080   TWChA& operator+=(const TWChA& WChA){WChV.AddV(WChA.WChV); return *this;}
00081   TWCh operator[](const int& ChN) const {return WChV[ChN];}
00082   int GetMemUsed(){return WChV.GetMemUsed();}
00083 
00084   void Clr(){WChV.Clr();}
00085   int Len() const {return WChV.Len();}
00086   bool Empty() const {return WChV.Empty();}
00087   TStr GetStr() const;
00088 
00089   void GetSubWChA(const int& BChN, const int& EChN, TWChA& WChA) const {
00090     WChV.GetSubValV(BChN, EChN, WChA.WChV);}
00091   void InsStr(const int& BChN, const TStr& Str);
00092   void DelSubStr(const int& BChN, const int& EChN);
00093   bool DelStr(const TStr& Str);
00094   void SplitOnCh(TStr& LStr, const char& SplitCh, TStr& RStr) const;
00095 
00096   int SearchCh(const TWCh& WCh, const int& BChN=0) const {
00097     return WChV.SearchForw(WCh, BChN);}
00098   int SearchStr(const TWChA& WChA, const int& BChN=0) const {
00099     return WChV.SearchVForw(WChA.WChV, BChN);}
00100   bool IsChIn(const char& Ch) const {return SearchCh(Ch)!=-1;}
00101   bool IsStrIn(const TWChA& WChA) const {return SearchStr(WChA)!=-1;}
00102   bool IsPrefix(const TWChA& WChA) const {
00103     TWChV SubWChV; WChV.GetSubValV(0, WChA.Len()-1, SubWChV);
00104     return SubWChV==WChA.WChV;}
00105   bool IsSufix(const TWChA& WChA) const {
00106     TWChV SubWChV; WChV.GetSubValV(Len()-WChA.Len(), Len()-1, SubWChV);
00107     return SubWChV==WChA.WChV;}
00108   int ChangeStr(const TStr& SrcStr, const TStr& DstStr, const int& BChN=0);
00109   int ChangeStrAll(const TStr& SrcStr, const TStr& DstStr);
00110 
00111   static void LoadTxt(const PSIn& SIn, TWChA& WChA);
00112   void SaveTxt(const PSOut& SOut) const;
00113 
00114   static TWChA EmptyWChA;
00115 };
00116 
00117