SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
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
pp.cpp
Go to the documentation of this file.
1 // Property-Tag
3 TStr TPpTag::GetStr(const int& Tag){
4  switch (Tag){
5  case ptUndef: return "Undef";
6  case ptBool: return "Bool";
7  case ptInt: return "Int";
8  case ptFlt: return "Flt";
9  case ptStr: return "Str";
10  case ptValV: return "ValV";
11  case ptSel: return "Sel";
12  case ptSet: return "Set";
13  default: Fail; return TStr();
14  }
15 }
16 
18  if (Str=="Undef"){return ptUndef;}
19  else if (Str=="Bool"){return ptBool;}
20  else if (Str=="Int"){return ptInt;}
21  else if (Str=="Flt"){return ptFlt;}
22  else if (Str=="Str"){return ptStr;}
23  else if (Str=="ValV"){return ptValV;}
24  else if (Str=="Sel"){return ptSel;}
25  else if (Str=="Set"){return ptSet;}
26  else {Fail; return ptUndef;}
27 }
28 
30 // Property-Value
31 bool TPpVal::operator==(const TPpVal& PpVal) const {
32  if (Tag!=PpVal.Tag){return false;}
33  switch (Tag){
34  case ptUndef: return true;
35  case ptBool: return Bool==PpVal.Bool;
36  case ptInt: return Int==PpVal.Int;
37  case ptFlt: return Flt==PpVal.Flt;
38  case ptStr: return Str==PpVal.Str;
39  case ptValV: return ValV==PpVal.ValV;
40  case ptSel:
41  case ptSet:
42  default: Fail; return false;
43  }
44 }
45 
46 TStr TPpVal::GetValStr(const bool& DoAddTag) const {
47  TChA ChA;
48  if (DoAddTag){ChA+='<'; ChA+=TPpTag::GetStr(Tag); ChA+='>';}
49  switch (Tag){
50  case ptUndef: break;
51  case ptBool: ChA+=TBool::GetStr(Bool); break;
52  case ptInt: ChA+=TInt::GetStr(Int); break;
53  case ptFlt: ChA+=TFlt::GetStr(Flt); break;
54  case ptStr: ChA+='"'; ChA+=Str; ChA+='"'; break;
55  case ptValV:{
56  ChA+='[';
57  for (int ValN=0; ValN<ValV.Len(); ValN++){
58  if (ValN>0){ChA+=' ';}
59  ChA+=ValV[ValN].GetValStr(DoAddTag);
60  }
61  ChA+=']'; break;}
62  default: Fail;
63  }
64  return ChA;
65 }
66 
69  if (Tag==ptUndef){
70  return TPpVal();
71  } else {
72  Lx.GetSym(syColon);
73  switch (Tag){
74  case ptBool: return TPpVal(Lx.GetBool());
75  case ptInt: return TPpVal(Lx.GetInt());
76  case ptFlt: return TPpVal(Lx.GetFlt());
77  case ptStr: return TPpVal(Lx.GetQStr());
78  case ptValV:{
79  TPpValV ValV;
80  Lx.GetSym(syLBracket);
81  while (Lx.PeekSym()==syIdStr){ValV.Add(LoadTxt(Lx));}
82  Lx.GetSym(syRBracket);
83  return TPpVal(ValV);}
84  default: Fail; return TPpVal();
85  }
86  }
87 }
88 
89 void TPpVal::SaveTxt(TOLx& Lx) const {
91  if (int(Tag)!=ptUndef){
92  Lx.PutSym(syColon);
93  switch (Tag){
94  case ptBool: Lx.PutBool(Bool); break;
95  case ptInt: Lx.PutInt(Int); break;
96  case ptFlt: Lx.PutFlt(Flt); break;
97  case ptStr: Lx.PutQStr(Str); break;
98  case ptValV:{
99  Lx.PutSym(syLBracket);
100  for (int ValN=0; ValN<ValV.Len(); ValN++){ValV[ValN].SaveTxt(Lx);}
101  Lx.PutSym(syRBracket); break;}
102  default: Fail;
103  }
104  }
105 }
106 
108 // Property
109 TStr TPp::PpNm="Pp";
110 
111 int TPp::GetPpN(const TStr& IdNm) const {
112  TStr UcIdNm=IdNm.GetUc();
113  for (int PpN=0; PpN<PpV.Len(); PpN++){
114  if (PpV[PpN]->UcIdNm==UcIdNm){return PpN;}}
115  return -1;
116 }
117 
118 void TPp::GetChA(const int& Lev, const bool& Brief, TChA& ChA) const {
119  for (int LevN=0; LevN<Lev; LevN++){ChA+="| ";}
120  if (!Brief){ChA+=TPpTag::GetStr(Tag);}
121  ChA+=" '"; ChA+=IdNm; ChA+="' ("; ChA+=DescNm; ChA+=") = ";
122  ChA+=Val.GetValStr(true); ChA+="\r\n";
123  if ((int(Tag)==ptSel)||(int(Tag)==ptSet)){
124  for (int PpN=0; PpN<PpV.Len(); PpN++){
125  PpV[PpN]->GetChA(Lev+1, Brief, ChA);
126  }
127  }
128 }
129 
130 void TPp::PutVal(const TPpVal& _Val){
131  Val=_Val;
132  if (Val.GetTag()!=ptUndef){
133  switch (Tag){
134  case ptUndef: Fail; break;
135  case ptBool: IAssert(Val.GetTag()==int(Tag)); break;
136  case ptInt:
137  case ptFlt:
138  IAssert(Val.GetTag()==int(Tag));
139  if (MnVal.GetTag()!=ptUndef){IAssert(MnVal<=Val);}
140  if (MxVal.GetTag()!=ptUndef){IAssert(Val<=MxVal);}
141  break;
142  case ptStr:
143  if (Val.GetTag()==ptInt){Val=CcValV[Val.GetInt()];}
144  IAssert(Val.GetTag()==ptStr);
145  IAssert((CcValV.Len()==0)||(CcValV.SearchForw(Val)!=-1)); break;
146  case ptValV:{
147  IAssert(Val.GetTag()==int(Tag));
148  Fail; //**TPpValV ValV=Val.GetValV();
149  //**for (int ValN=0; ValN<ValV.Len(); ValN++){
150  //**IAssert(ValV[ValN].GetTag()==int(ValVTag));}
151  break;}
152  case ptSel:
153  if (Val.GetTag()==ptInt){Val=TPpVal(PpV[Val.GetInt()]->GetIdNm());}
154  IAssert((Val.GetTag()==ptStr)&&(IsPp(Val.GetStr()))); break;
155  case ptSet: Fail; break;
156  default: Fail;
157  }
158  }
159 }
160 
161 PPp TPp::GetPp(const TStr& IdPath) const {
162  IAssertSubPp();
163  TStr IdNm; TStr RestIdPath;
164  IdPath.SplitOnCh(IdNm, '|', RestIdPath);
165  PPp Pp=PpV[GetPpN(IdNm)];
166  while (!RestIdPath.Empty()){
167  RestIdPath.SplitOnCh(IdNm, '|', RestIdPath);
168  Pp=Pp->PpV[Pp->GetPpN(IdNm)];
169  }
170  IAssert(!Pp.Empty()); return Pp;
171 }
172 
174  Lx.GetSym(syLBracket);
175  TStr IdNm=Lx.GetIdStr();
176  TStr DescNm;
177  if (Lx.PeekSym()==syLBracket){
178  Lx.GetSym(syLBracket); DescNm=Lx.GetQStr(); Lx.GetSym(syRBracket);
179  }
180  Lx.GetSym(syColon);
183  if (Tag==ptValV){
184  Lx.GetSym(syLBracket); ValVTag=TPpTag::LoadTxt(Lx); Lx.GetSym(syRBracket);}
185  TPpVal Val;
186  if (Lx.PeekSym()==syEq){
187  Lx.GetSym(syEq); Val=TPpVal::LoadTxt(Lx);}
188  TPpVal DfVal;
189  if (Lx.PeekSym()==syLBracket){
190  Lx.GetSym(syLBracket); DfVal=TPpVal::LoadTxt(Lx); Lx.GetSym(syRBracket);}
191  bool IsMnMxValDef=false; TPpVal MnVal, MxVal;
192  if (Lx.PeekSym()==syLss){
193  Lx.GetSym(syLss);
194  IsMnMxValDef=true; MnVal=TPpVal::LoadTxt(Lx); MxVal=TPpVal::LoadTxt(Lx);
195  Lx.GetSym(syGtr);
196  }
197  TPpValV CcValV;
198  if (Lx.PeekSym()==syLBrace){
199  Lx.GetSym(syLBrace);
200  while (Lx.PeekSym()!=syRBrace){CcValV.Add(TPpVal::LoadTxt(Lx));}
201  Lx.GetSym(syRBrace);
202  }
203  TPpV PpV;
204  if ((Tag==ptSel)||(Tag==ptSet)){
205  while (Lx.IsVar(PpNm)){
206  Lx.GetVar(PpNm); PpV.Add(LoadTxt(Lx));}
207  }
208  Lx.GetSym(syRBracket);
209  // construct property
210  PPp Pp=PPp(new TPp(IdNm, DescNm, Tag, ValVTag));
211  Pp->AddPpV(PpV);
212  Pp->PutCcValV(CcValV);
213  if (IsMnMxValDef){Pp->PutMnMxVal(MnVal, MxVal);}
214  Pp->PutDfVal(DfVal);
215  Pp->PutVal(Val);
216  // return property
217  return Pp;
218 }
219 
220 void TPp::SaveTxt(TOLx& Lx, const int& Lev) const {
221  Lx.PutSym(syLBracket);
222  //Lx.PutIndent(Lev);
223  Lx.PutIdStr(IdNm);
224  if (!DescNm.Empty()){
226  Lx.PutSym(syColon);
227  TPpTag::SaveTxt(Lx, Tag);
228  if (int(Tag)==ptValV){
230  if (Val.GetTag()!=ptUndef){
231  Lx.PutSym(syEq); Val.SaveTxt(Lx);
232  }
233  if (DfVal.GetTag()!=ptUndef){
235  if ((MnVal.GetTag()!=ptUndef)||(MxVal.GetTag()!=ptUndef)){
236  Lx.PutSym(syLss); MnVal.SaveTxt(Lx); MxVal.SaveTxt(Lx); Lx.PutSym(syGtr);
237  }
238  if (CcValV.Len()>0){
239  Lx.PutSym(syLBrace);
240  for (int CcValN=0; CcValN<CcValV.Len(); CcValN++){
241  CcValV[CcValN].SaveTxt(Lx);}
242  Lx.PutSym(syRBrace);
243  }
244  if ((int(Tag)==ptSel)||(int(Tag)==ptSet)){
245  for (int PpN=0; PpN<PpV.Len(); PpN++){
246  Lx.PutVar(PpNm); PpV[PpN]->SaveTxt(Lx, Lev+1);}
247  }
248  Lx.PutSym(syRBracket);
249 }
250 
#define IAssert(Cond)
Definition: bd.h:262
TStr GetStr() const
Definition: pp.h:55
TPp()
Definition: pp.h:86
Definition: lx.h:49
Definition: lx.h:50
static PPp LoadTxt(const PSIn &SIn)
Definition: pp.h:227
TInt Tag
Definition: pp.h:21
TStr GetStr() const
Definition: dt.h:1104
TPpV PpV
Definition: pp.h:81
int GetTag() const
Definition: pp.h:51
void IAssertSubPp() const
Definition: pp.h:82
void PutVar(const TStr &VarNm, const bool &LBracket=false, const bool &NewLn=false, const bool &CheckIdStr=true)
Definition: lx.h:309
Definition: lx.h:50
TPpVal MnVal
Definition: pp.h:79
static TStr GetStr(const int &Tag)
Definition: pp.cpp:3
void PutBool(const TBool &Bool)
Definition: lx.h:275
TInt Int
Definition: pp.h:22
#define Fail
Definition: bd.h:238
bool Empty() const
Definition: bd.h:501
TStr GetUc() const
Definition: dt.h:493
Definition: pp.h:19
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static TPpTagVal GetTag(const TStr &Str)
Definition: pp.cpp:17
void SaveTxt(TOLx &Lx) const
Definition: pp.cpp:89
void PutInt(const TInt &Int)
Definition: lx.h:277
Definition: pp.h:4
Definition: pp.h:4
void GetVar(const TStr &VarNm, const bool &LBracket=false, const bool &NewLn=false)
Definition: lx.h:209
int GetInt()
Definition: lx.h:181
Definition: lx.h:45
Definition: pp.h:4
TStr IdNm
Definition: pp.h:76
void PutSym(const TLxSym &Sym)
Definition: lx.cpp:751
TInt ValVTag
Definition: pp.h:77
void PutQStr(const TStr &Str)
Definition: lx.h:289
double GetFlt()
Definition: lx.h:182
Definition: lx.h:49
TStr Str
Definition: pp.h:22
bool IsVar(const TStr &VarNm)
Definition: lx.h:207
TPpVal()
Definition: pp.h:24
TPt< TPp > PPp
Definition: pp.h:66
Definition: pp.h:4
static TStr PpNm
Definition: pp.h:74
void SplitOnCh(TStr &LStr, const char &SplitCh, TStr &RStr) const
Definition: dt.cpp:901
Definition: lx.h:50
int GetPpN(const TStr &IdNm) const
Definition: pp.cpp:111
TStr DescNm
Definition: pp.h:76
TStr UcIdNm
Definition: pp.h:76
void GetChA(const int &Lev, const bool &Brief, TChA &ChA) const
Definition: pp.cpp:118
TVec< TPpVal > ValV
Definition: pp.h:22
TInt GetInt() const
Definition: pp.h:53
static TPpVal LoadTxt(TILx &Lx)
Definition: pp.cpp:67
Definition: lx.h:49
Definition: lx.h:129
TPpVal Val
Definition: pp.h:78
void SaveTxt(const PSOut &SOut) const
Definition: pp.h:229
TPpValV CcValV
Definition: pp.h:80
Definition: lx.h:251
TStr GetValStr(const bool &DoAddTag=false) const
Definition: pp.cpp:46
TStr GetQStr(const TStr &QStr=TStr())
Definition: lx.h:187
TFlt Flt
Definition: pp.h:22
TBool Bool
Definition: pp.h:22
bool operator==(const TPpVal &PpVal) const
Definition: pp.cpp:31
Definition: lx.h:50
void PutFlt(const TFlt &Flt, const int &Width=-1, const int &Prec=-1)
Definition: lx.h:280
TPpVal DfVal
Definition: pp.h:78
bool GetBool()
Definition: lx.h:180
TInt Tag
Definition: pp.h:77
Definition: pp.h:4
static void SaveTxt(TOLx &Lx, const TInt &Tag)
Definition: pp.h:12
Definition: dt.h:201
TStr GetIdStr(const TStr &IdStr=TStr())
Definition: lx.h:185
TLxSym PeekSym()
Definition: lx.h:200
TPpTagVal
Definition: pp.h:3
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
Definition: pp.h:4
TSizeTy SearchForw(const TVal &Val, const TSizeTy &BValN=0) const
Returns the position of an element with value Val.
Definition: ds.h:1440
static TStr GetStr(const bool &Val)
Definition: dt.h:918
Definition: bd.h:196
Definition: lx.h:46
TStr GetStr() const
Definition: dt.h:1365
TPpVal MxVal
Definition: pp.h:79
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
Definition: pp.h:4
void PutVal(const TPpVal &_Val)
Definition: pp.cpp:130
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
PPp GetPp(const int &PpN) const
Definition: pp.h:158
Definition: pp.h:4
static TPpTagVal LoadTxt(TILx &Lx)
Definition: pp.h:10
bool IsPp(const TStr &IdNm) const
Definition: pp.h:150
void PutIdStr(const TStr &Str, const bool &CheckIdStr=true)
Definition: lx.h:286