SNAP Library 2.1, User Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
00001 00002 // Property-Tag 00003 TStr TPpTag::GetStr(const int& Tag){ 00004 switch (Tag){ 00005 case ptUndef: return "Undef"; 00006 case ptBool: return "Bool"; 00007 case ptInt: return "Int"; 00008 case ptFlt: return "Flt"; 00009 case ptStr: return "Str"; 00010 case ptValV: return "ValV"; 00011 case ptSel: return "Sel"; 00012 case ptSet: return "Set"; 00013 default: Fail; return TStr(); 00014 } 00015 } 00016 00017 TPpTagVal TPpTag::GetTag(const TStr& Str){ 00018 if (Str=="Undef"){return ptUndef;} 00019 else if (Str=="Bool"){return ptBool;} 00020 else if (Str=="Int"){return ptInt;} 00021 else if (Str=="Flt"){return ptFlt;} 00022 else if (Str=="Str"){return ptStr;} 00023 else if (Str=="ValV"){return ptValV;} 00024 else if (Str=="Sel"){return ptSel;} 00025 else if (Str=="Set"){return ptSet;} 00026 else {Fail; return ptUndef;} 00027 } 00028 00030 // Property-Value 00031 bool TPpVal::operator==(const TPpVal& PpVal) const { 00032 if (Tag!=PpVal.Tag){return false;} 00033 switch (Tag){ 00034 case ptUndef: return true; 00035 case ptBool: return Bool==PpVal.Bool; 00036 case ptInt: return Int==PpVal.Int; 00037 case ptFlt: return Flt==PpVal.Flt; 00038 case ptStr: return Str==PpVal.Str; 00039 case ptValV: return ValV==PpVal.ValV; 00040 case ptSel: 00041 case ptSet: 00042 default: Fail; return false; 00043 } 00044 } 00045 00046 TStr TPpVal::GetValStr(const bool& DoAddTag) const { 00047 TChA ChA; 00048 if (DoAddTag){ChA+='<'; ChA+=TPpTag::GetStr(Tag); ChA+='>';} 00049 switch (Tag){ 00050 case ptUndef: break; 00051 case ptBool: ChA+=TBool::GetStr(Bool); break; 00052 case ptInt: ChA+=TInt::GetStr(Int); break; 00053 case ptFlt: ChA+=TFlt::GetStr(Flt); break; 00054 case ptStr: ChA+='"'; ChA+=Str; ChA+='"'; break; 00055 case ptValV:{ 00056 ChA+='['; 00057 for (int ValN=0; ValN<ValV.Len(); ValN++){ 00058 if (ValN>0){ChA+=' ';} 00059 ChA+=ValV[ValN].GetValStr(DoAddTag); 00060 } 00061 ChA+=']'; break;} 00062 default: Fail; 00063 } 00064 return ChA; 00065 } 00066 00067 TPpVal TPpVal::LoadTxt(TILx& Lx){ 00068 TPpTagVal Tag=TPpTag::LoadTxt(Lx); 00069 if (Tag==ptUndef){ 00070 return TPpVal(); 00071 } else { 00072 Lx.GetSym(syColon); 00073 switch (Tag){ 00074 case ptBool: return TPpVal(Lx.GetBool()); 00075 case ptInt: return TPpVal(Lx.GetInt()); 00076 case ptFlt: return TPpVal(Lx.GetFlt()); 00077 case ptStr: return TPpVal(Lx.GetQStr()); 00078 case ptValV:{ 00079 TPpValV ValV; 00080 Lx.GetSym(syLBracket); 00081 while (Lx.PeekSym()==syIdStr){ValV.Add(LoadTxt(Lx));} 00082 Lx.GetSym(syRBracket); 00083 return TPpVal(ValV);} 00084 default: Fail; return TPpVal(); 00085 } 00086 } 00087 } 00088 00089 void TPpVal::SaveTxt(TOLx& Lx) const { 00090 Lx.PutIdStr(TPpTag::GetStr(Tag)); 00091 if (int(Tag)!=ptUndef){ 00092 Lx.PutSym(syColon); 00093 switch (Tag){ 00094 case ptBool: Lx.PutBool(Bool); break; 00095 case ptInt: Lx.PutInt(Int); break; 00096 case ptFlt: Lx.PutFlt(Flt); break; 00097 case ptStr: Lx.PutQStr(Str); break; 00098 case ptValV:{ 00099 Lx.PutSym(syLBracket); 00100 for (int ValN=0; ValN<ValV.Len(); ValN++){ValV[ValN].SaveTxt(Lx);} 00101 Lx.PutSym(syRBracket); break;} 00102 default: Fail; 00103 } 00104 } 00105 } 00106 00108 // Property 00109 TStr TPp::PpNm="Pp"; 00110 00111 int TPp::GetPpN(const TStr& IdNm) const { 00112 TStr UcIdNm=IdNm.GetUc(); 00113 for (int PpN=0; PpN<PpV.Len(); PpN++){ 00114 if (PpV[PpN]->UcIdNm==UcIdNm){return PpN;}} 00115 return -1; 00116 } 00117 00118 void TPp::GetChA(const int& Lev, const bool& Brief, TChA& ChA) const { 00119 for (int LevN=0; LevN<Lev; LevN++){ChA+="| ";} 00120 if (!Brief){ChA+=TPpTag::GetStr(Tag);} 00121 ChA+=" '"; ChA+=IdNm; ChA+="' ("; ChA+=DescNm; ChA+=") = "; 00122 ChA+=Val.GetValStr(true); ChA+="\r\n"; 00123 if ((int(Tag)==ptSel)||(int(Tag)==ptSet)){ 00124 for (int PpN=0; PpN<PpV.Len(); PpN++){ 00125 PpV[PpN]->GetChA(Lev+1, Brief, ChA); 00126 } 00127 } 00128 } 00129 00130 void TPp::PutVal(const TPpVal& _Val){ 00131 Val=_Val; 00132 if (Val.GetTag()!=ptUndef){ 00133 switch (Tag){ 00134 case ptUndef: Fail; break; 00135 case ptBool: IAssert(Val.GetTag()==int(Tag)); break; 00136 case ptInt: 00137 case ptFlt: 00138 IAssert(Val.GetTag()==int(Tag)); 00139 if (MnVal.GetTag()!=ptUndef){IAssert(MnVal<=Val);} 00140 if (MxVal.GetTag()!=ptUndef){IAssert(Val<=MxVal);} 00141 break; 00142 case ptStr: 00143 if (Val.GetTag()==ptInt){Val=CcValV[Val.GetInt()];} 00144 IAssert(Val.GetTag()==ptStr); 00145 IAssert((CcValV.Len()==0)||(CcValV.SearchForw(Val)!=-1)); break; 00146 case ptValV:{ 00147 IAssert(Val.GetTag()==int(Tag)); 00148 Fail; //**TPpValV ValV=Val.GetValV(); 00149 //**for (int ValN=0; ValN<ValV.Len(); ValN++){ 00150 //**IAssert(ValV[ValN].GetTag()==int(ValVTag));} 00151 break;} 00152 case ptSel: 00153 if (Val.GetTag()==ptInt){Val=TPpVal(PpV[Val.GetInt()]->GetIdNm());} 00154 IAssert((Val.GetTag()==ptStr)&&(IsPp(Val.GetStr()))); break; 00155 case ptSet: Fail; break; 00156 default: Fail; 00157 } 00158 } 00159 } 00160 00161 PPp TPp::GetPp(const TStr& IdPath) const { 00162 IAssertSubPp(); 00163 TStr IdNm; TStr RestIdPath; 00164 IdPath.SplitOnCh(IdNm, '|', RestIdPath); 00165 PPp Pp=PpV[GetPpN(IdNm)]; 00166 while (!RestIdPath.Empty()){ 00167 RestIdPath.SplitOnCh(IdNm, '|', RestIdPath); 00168 Pp=Pp->PpV[Pp->GetPpN(IdNm)]; 00169 } 00170 IAssert(!Pp.Empty()); return Pp; 00171 } 00172 00173 PPp TPp::LoadTxt(TILx& Lx){ 00174 Lx.GetSym(syLBracket); 00175 TStr IdNm=Lx.GetIdStr(); 00176 TStr DescNm; 00177 if (Lx.PeekSym()==syLBracket){ 00178 Lx.GetSym(syLBracket); DescNm=Lx.GetQStr(); Lx.GetSym(syRBracket); 00179 } 00180 Lx.GetSym(syColon); 00181 TPpTagVal Tag=TPpTag::LoadTxt(Lx); 00182 TPpTagVal ValVTag=ptUndef; 00183 if (Tag==ptValV){ 00184 Lx.GetSym(syLBracket); ValVTag=TPpTag::LoadTxt(Lx); Lx.GetSym(syRBracket);} 00185 TPpVal Val; 00186 if (Lx.PeekSym()==syEq){ 00187 Lx.GetSym(syEq); Val=TPpVal::LoadTxt(Lx);} 00188 TPpVal DfVal; 00189 if (Lx.PeekSym()==syLBracket){ 00190 Lx.GetSym(syLBracket); DfVal=TPpVal::LoadTxt(Lx); Lx.GetSym(syRBracket);} 00191 bool IsMnMxValDef=false; TPpVal MnVal, MxVal; 00192 if (Lx.PeekSym()==syLss){ 00193 Lx.GetSym(syLss); 00194 IsMnMxValDef=true; MnVal=TPpVal::LoadTxt(Lx); MxVal=TPpVal::LoadTxt(Lx); 00195 Lx.GetSym(syGtr); 00196 } 00197 TPpValV CcValV; 00198 if (Lx.PeekSym()==syLBrace){ 00199 Lx.GetSym(syLBrace); 00200 while (Lx.PeekSym()!=syRBrace){CcValV.Add(TPpVal::LoadTxt(Lx));} 00201 Lx.GetSym(syRBrace); 00202 } 00203 TPpV PpV; 00204 if ((Tag==ptSel)||(Tag==ptSet)){ 00205 while (Lx.IsVar(PpNm)){ 00206 Lx.GetVar(PpNm); PpV.Add(LoadTxt(Lx));} 00207 } 00208 Lx.GetSym(syRBracket); 00209 // construct property 00210 PPp Pp=PPp(new TPp(IdNm, DescNm, Tag, ValVTag)); 00211 Pp->AddPpV(PpV); 00212 Pp->PutCcValV(CcValV); 00213 if (IsMnMxValDef){Pp->PutMnMxVal(MnVal, MxVal);} 00214 Pp->PutDfVal(DfVal); 00215 Pp->PutVal(Val); 00216 // return property 00217 return Pp; 00218 } 00219 00220 void TPp::SaveTxt(TOLx& Lx, const int& Lev) const { 00221 Lx.PutSym(syLBracket); 00222 //Lx.PutIndent(Lev); 00223 Lx.PutIdStr(IdNm); 00224 if (!DescNm.Empty()){ 00225 Lx.PutSym(syLBracket); Lx.PutQStr(DescNm); Lx.PutSym(syRBracket);} 00226 Lx.PutSym(syColon); 00227 TPpTag::SaveTxt(Lx, Tag); 00228 if (int(Tag)==ptValV){ 00229 Lx.PutSym(syLBracket); TPpTag::SaveTxt(Lx, ValVTag); Lx.PutSym(syRBracket);} 00230 if (Val.GetTag()!=ptUndef){ 00231 Lx.PutSym(syEq); Val.SaveTxt(Lx); 00232 } 00233 if (DfVal.GetTag()!=ptUndef){ 00234 Lx.PutSym(syLBracket); DfVal.SaveTxt(Lx); Lx.PutSym(syRBracket);} 00235 if ((MnVal.GetTag()!=ptUndef)||(MxVal.GetTag()!=ptUndef)){ 00236 Lx.PutSym(syLss); MnVal.SaveTxt(Lx); MxVal.SaveTxt(Lx); Lx.PutSym(syGtr); 00237 } 00238 if (CcValV.Len()>0){ 00239 Lx.PutSym(syLBrace); 00240 for (int CcValN=0; CcValN<CcValV.Len(); CcValN++){ 00241 CcValV[CcValN].SaveTxt(Lx);} 00242 Lx.PutSym(syRBrace); 00243 } 00244 if ((int(Tag)==ptSel)||(int(Tag)==ptSet)){ 00245 for (int PpN=0; PpN<PpV.Len(); PpN++){ 00246 Lx.PutVar(PpNm); PpV[PpN]->SaveTxt(Lx, Lev+1);} 00247 } 00248 Lx.PutSym(syRBracket); 00249 } 00250