SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wch.h
Go to the documentation of this file.
1 // Wide-Char
3 class TWCh{
4 private:
7 public:
8  static const TWCh Mn;
9  static const TWCh Mx;
10  static const int Vals;
11 
12  TWCh(): MsVal(0), LsVal(0){}
13  TWCh(const uchar& _LsVal): MsVal(0), LsVal(_LsVal){}
14  TWCh(const uchar& _MsVal, const uchar& _LsVal):
15  MsVal(_MsVal), LsVal(_LsVal){}
16  TWCh(const int& _MsVal, const int& _LsVal):
17  MsVal(uchar(_MsVal)), LsVal(uchar(_LsVal)){}
18  operator char() const {return LsVal;}
19  TWCh(TSIn& SIn){SIn.Load(MsVal); SIn.Load(LsVal);}
20  void Save(TSOut& SOut) const {SOut.Save(MsVal); SOut.Save(MsVal);}
21 
22  TWCh& operator=(const TWCh& WCh){
23  MsVal=WCh.MsVal; LsVal=WCh.LsVal; return *this;}
24  bool operator==(const TWCh& WCh) const {
25  return (MsVal==WCh.MsVal)&&(LsVal==WCh.LsVal);}
26  bool operator<(const TWCh& WCh) const {
27  return (MsVal<WCh.MsVal)||((MsVal==WCh.MsVal)&&(LsVal<WCh.LsVal));}
28  int GetMemUsed() const {return sizeof(MsVal)+sizeof(LsVal);}
29 
30  int GetPrimHashCd() const {return LsVal;}
31  int GetSecHashCd() const {return MsVal;}
32 
33  char GetCh() const {
34  if (MsVal==TCh::NullCh){return LsVal;} else {return '#';}}
35 
36  static TWCh LoadTxt(const PSIn& SIn){
37  uchar LsVal=SIn->GetCh(); uchar MsVal=SIn->GetCh();
38  return TWCh(MsVal, LsVal);}
39  void SaveTxt(const PSOut& SOut) const {
40  SOut->PutCh(MsVal); SOut->PutCh(LsVal);}
41 
42  static const TWCh StartWCh;
43  static const TWCh TabWCh;
44  static const TWCh LfWCh;
45  static const TWCh CrWCh;
46  static const TWCh SpaceWCh;
47 };
48 typedef TVec<TWCh> TWChV;
49 
51 // Wide-Char-Array
52 class TWChA{
53 private:
55  void AddCStr(const char* CStr);
56  void PutCStr(const char* CStr);
57 public:
58  TWChA(const int& MxWChs=0): WChV(MxWChs, 0){}
59  TWChA(const TWChA& WChA): WChV(WChA.WChV){}
60  TWChA(const TWChV& _WChV): WChV(_WChV){}
61  TWChA(const char* CStr): WChV(){PutCStr(CStr);}
62  TWChA(const TChA& ChA): WChV(){PutCStr(ChA.CStr());}
63  TWChA(const TStr& Str): WChV(){PutCStr(Str.CStr());}
64  ~TWChA(){}
65  TWChA(TSIn& SIn): WChV(SIn){}
66  void Save(TSOut& SOut){WChV.Save(SOut);}
67 
68  TWChA& operator=(const TWChA& WChA){
69  if (this!=&WChA){WChV=WChA.WChV;} return *this;}
70  TWChA& operator=(const char* CStr){PutCStr(CStr); return *this;}
71  TWChA& operator=(const TChA& ChA){PutCStr(ChA.CStr()); return *this;}
72  TWChA& operator=(const TStr& Str){PutCStr(Str.CStr()); return *this;}
73  bool operator==(const TWChA& WChA) const {return WChV==WChA.WChV;}
74  bool operator==(const char* CStr) const {return strcmp(GetStr().CStr(), CStr)!=0;}
75  TWChA& operator+=(const char& Ch){WChV.Add(TWCh(Ch)); return *this;}
76  TWChA& operator+=(const TWCh& WCh){WChV.Add(WCh); return *this;}
77  TWChA& operator+=(const char* CStr){AddCStr(CStr); return *this;}
78  TWChA& operator+=(const TChA& ChA){AddCStr(ChA.CStr()); return *this;}
79  TWChA& operator+=(const TStr& Str){AddCStr(Str.CStr()); return *this;}
80  TWChA& operator+=(const TWChA& WChA){WChV.AddV(WChA.WChV); return *this;}
81  TWCh operator[](const int& ChN) const {return WChV[ChN];}
82  int GetMemUsed(){return WChV.GetMemUsed();}
83 
84  void Clr(){WChV.Clr();}
85  int Len() const {return WChV.Len();}
86  bool Empty() const {return WChV.Empty();}
87  TStr GetStr() const;
88 
89  void GetSubWChA(const int& BChN, const int& EChN, TWChA& WChA) const {
90  WChV.GetSubValV(BChN, EChN, WChA.WChV);}
91  void InsStr(const int& BChN, const TStr& Str);
92  void DelSubStr(const int& BChN, const int& EChN);
93  bool DelStr(const TStr& Str);
94  void SplitOnCh(TStr& LStr, const char& SplitCh, TStr& RStr) const;
95 
96  int SearchCh(const TWCh& WCh, const int& BChN=0) const {
97  return WChV.SearchForw(WCh, BChN);}
98  int SearchStr(const TWChA& WChA, const int& BChN=0) const {
99  return WChV.SearchVForw(WChA.WChV, BChN);}
100  bool IsChIn(const char& Ch) const {return SearchCh(Ch)!=-1;}
101  bool IsStrIn(const TWChA& WChA) const {return SearchStr(WChA)!=-1;}
102  bool IsPrefix(const TWChA& WChA) const {
103  TWChV SubWChV; WChV.GetSubValV(0, WChA.Len()-1, SubWChV);
104  return SubWChV==WChA.WChV;}
105  bool IsSufix(const TWChA& WChA) const {
106  TWChV SubWChV; WChV.GetSubValV(Len()-WChA.Len(), Len()-1, SubWChV);
107  return SubWChV==WChA.WChV;}
108  int ChangeStr(const TStr& SrcStr, const TStr& DstStr, const int& BChN=0);
109  int ChangeStrAll(const TStr& SrcStr, const TStr& DstStr);
110 
111  static void LoadTxt(const PSIn& SIn, TWChA& WChA);
112  void SaveTxt(const PSOut& SOut) const;
113 
114  static TWChA EmptyWChA;
115 };
116 
117 
TWChA(const char *CStr)
Definition: wch.h:61
TWChA(const TChA &ChA)
Definition: wch.h:62
static void LoadTxt(const PSIn &SIn, TWChA &WChA)
Definition: wch.cpp:35
static const TWCh LfWCh
Definition: wch.h:44
TWCh()
Definition: wch.h:12
static const TWCh Mx
Definition: wch.h:9
TWChV WChV
Definition: wch.h:54
TWChA & operator+=(const TChA &ChA)
Definition: wch.h:78
virtual int PutCh(const char &Ch)=0
TWChA & operator+=(const TWCh &WCh)
Definition: wch.h:76
TWChA & operator+=(const char &Ch)
Definition: wch.h:75
static const char NullCh
Definition: dt.h:1033
TStr GetStr() const
Definition: wch.cpp:28
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr)
int GetPrimHashCd() const
Definition: wch.h:30
static const int Vals
Definition: wch.h:10
TWChA(TSIn &SIn)
Definition: wch.h:65
static const TWCh SpaceWCh
Definition: wch.h:46
int GetSecHashCd() const
Definition: wch.h:31
void InsStr(const int &BChN, const TStr &Str)
int GetMemUsed()
Definition: wch.h:82
TWChA & operator=(const char *CStr)
Definition: wch.h:70
TWChA & operator=(const TWChA &WChA)
Definition: wch.h:68
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
Definition: ds.h:511
void Save(TSOut &SOut)
Definition: wch.h:66
static const TWCh StartWCh
Definition: wch.h:42
void Save(TSOut &SOut) const
Definition: wch.h:20
void SplitOnCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
int ChangeStr(const TStr &SrcStr, const TStr &DstStr, const int &BChN=0)
TWChA & operator=(const TChA &ChA)
Definition: wch.h:71
Definition: fl.h:58
void Save(TSOut &SOut) const
Definition: ds.h:954
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
bool operator<(const TWCh &WCh) const
Definition: wch.h:26
static TWChA EmptyWChA
Definition: wch.h:114
bool DelStr(const TStr &Str)
bool IsSufix(const TWChA &WChA) const
Definition: wch.h:105
TWChA(const TWChA &WChA)
Definition: wch.h:59
bool operator==(const TWCh &WCh) const
Definition: wch.h:24
bool operator==(const char *CStr) const
Definition: wch.h:74
TWCh(const int &_MsVal, const int &_LsVal)
Definition: wch.h:16
~TWChA()
Definition: wch.h:64
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
char * CStr()
Definition: dt.h:255
TWCh & operator=(const TWCh &WCh)
Definition: wch.h:22
void Load(bool &Bool)
Definition: fl.h:84
uchar LsVal
Definition: wch.h:6
TSizeTy SearchVForw(const TVec< TVal, TSizeTy > &ValV, const TSizeTy &BValN=0) const
Returns the starting position of vector ValV.
Definition: ds.h:1566
TWChA & operator=(const TStr &Str)
Definition: wch.h:72
void PutCStr(const char *CStr)
Definition: wch.cpp:21
static const TWCh TabWCh
Definition: wch.h:43
int SearchStr(const TWChA &WChA, const int &BChN=0) const
Definition: wch.h:98
TWCh(const uchar &_MsVal, const uchar &_LsVal)
Definition: wch.h:14
unsigned char uchar
Definition: bd.h:10
TWCh(const uchar &_LsVal)
Definition: wch.h:13
Definition: fl.h:128
static const TWCh Mn
Definition: wch.h:8
void Save(const bool &Bool)
Definition: fl.h:173
TWChA & operator+=(const char *CStr)
Definition: wch.h:77
Definition: dt.h:201
void Clr()
Definition: wch.h:84
uchar MsVal
Definition: wch.h:5
bool IsStrIn(const TWChA &WChA) const
Definition: wch.h:101
void SaveTxt(const PSOut &SOut) const
Definition: wch.h:39
TWCh operator[](const int &ChN) const
Definition: wch.h:81
Definition: dt.h:412
TWCh(TSIn &SIn)
Definition: wch.h:19
TWChA(const TWChV &_WChV)
Definition: wch.h:60
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1552
TWChA(const TStr &Str)
Definition: wch.h:63
void GetSubWChA(const int &BChN, const int &EChN, TWChA &WChA) const
Definition: wch.h:89
static TWCh LoadTxt(const PSIn &SIn)
Definition: wch.h:36
void SaveTxt(const PSOut &SOut) const
Definition: wch.cpp:43
void AddCStr(const char *CStr)
Definition: wch.cpp:15
bool IsChIn(const char &Ch) const
Definition: wch.h:100
char GetCh() const
Definition: wch.h:33
TWChA & operator+=(const TWChA &WChA)
Definition: wch.h:80
bool IsPrefix(const TWChA &WChA) const
Definition: wch.h:102
TVec< TWCh > TWChV
Definition: wch.h:48
TWChA & operator+=(const TStr &Str)
Definition: wch.h:79
Definition: wch.h:52
virtual char GetCh()=0
char * CStr()
Definition: dt.h:476
void DelSubStr(const int &BChN, const int &EChN)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
bool Empty() const
Definition: wch.h:86
TWChA(const int &MxWChs=0)
Definition: wch.h:58
bool operator==(const TWChA &WChA) const
Definition: wch.h:73
int GetMemUsed() const
Definition: wch.h:28
int Len() const
Definition: wch.h:85
static const TWCh CrWCh
Definition: wch.h:45
int SearchCh(const TWCh &WCh, const int &BChN=0) const
Definition: wch.h:96
Definition: wch.h:3
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
Definition: ds.h:1110
void GetSubValV(const TSizeTy &BValN, const TSizeTy &EValN, TVec< TVal, TSizeTy > &ValV) const
Fills ValV with elements at positions BValN...EValN.
Definition: ds.h:1170