|
SNAP Library, User Reference
2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
|
Go to the source code of this file.
Classes | |
| class | TExpBi |
Enumerations | |
| enum | TExpValType { evtUndef, evtFlt, evtStr, evtVec, evtLst } |
| enum | TExpFuncArgType { efatUndef, efatVoid, efatFlt, efatFltFlt, efatFltStr, efatStr, efatStrFlt, efatStrStr, efatStrAny } |
| enum | TExpBiId { ebi_Undef, ebi_True, ebi_False, ebi_E, ebi_Pi, ebi_Sin, ebi_Cos, ebi_Tan, ebi_ASin, ebi_ACos, ebi_ATan, ebi_SinH, ebi_CosH, ebi_TanH, ebi_Pow, ebi_Exp, ebi_Sqr, ebi_Sqrt, ebi_Log, ebi_Log10, ebi_Ceil, ebi_Floor, ebi_Int, ebi_Frac, ebi_Abs, ebi_UniDev, ebi_NrmDev, ebi_ExpDev, ebi_GamDev, ebi_PoiDev, ebi_BinDev, ebi_UniDevStep, ebi_NrmDevStep, ebi_ExpDevStep } |
| enum | TExpBiArgType { ebatUndef, ebatVoid, ebatFlt, ebatFltFlt } |
| enum | TExpType { etUndef, etVal, etVec, etLst, etOp, etVar, etBiConst, etFunc, etBiFunc } |
| enum | TExpOp { eoUndef, eoUPlus, eoUMinus, eoPlus, eoMinus, eoMul, eoDiv, eoIDiv, eoMod, eoNot, eoAnd, eoOr, eoEq, eoNEq, eoLss, eoGtr, eoLEq, eoGEq, eoIf } |
| enum | TExpHelpObjType { ehotUndef, ehotOp, ehotVar, ehotFunc, ehotTempl } |
Functions | |
| TExpVal (const TExpValType &_ValType=evtUndef) | |
| TExpVal (const TFlt &_Flt) | |
| TExpVal (const double &_Flt) | |
| TExpVal (const TStr &_Str) | |
| static PExpVal | New (const TExpValType &ValType=evtUndef) |
| static PExpVal | New (const TFlt &Flt) |
| static PExpVal | New (const double &Flt) |
| static PExpVal | New (const TStr &Str) |
| ~TExpVal () | |
| TExpVal (TSIn &SIn) | |
| static PExpVal | Load (TSIn &SIn) |
| void | Save (TSOut &SOut) const |
| TExpVal & | operator= (const TExpVal &) |
| bool | operator== (const TExpVal &ExpVal) const |
| bool | operator< (const TExpVal &ExpVal) const |
| void | AddToVec (const PExpVal &ExpVal) |
| void | AddToLst (const PExpVal &ExpVal) |
| TExpValType | GetValType () const |
| bool | IsFltVal (TFlt &_Flt) const |
| bool | IsFltVal (double &_Flt) const |
| double | GetFltVal () const |
| int | GetFltValAsInt (const bool &ThrowExceptP=true) const |
| TStr | GetStrVal () const |
| void | SaveTxt (TOLx &Lx) const |
| void | SaveTxt (const PSOut &SOut) const |
| TStr | GetStr () const |
| static PExpVal | MkClone (const PExpVal &ExpVal) |
| static PExpVal | GetUndefExpVal () |
| static PExpVal | GetZeroExpVal () |
| TExpEnv () | |
| virtual | ~TExpEnv () |
| TExpEnv (TSIn &SIn) | |
| TExpEnv & | operator= (const TExpEnv &) |
| bool | operator== (const TExpEnv &) const |
| virtual void | PutVarVal (const TStr &, const PExpVal &) |
| virtual PExpVal | GetVarVal (const TStr &, bool &IsVar) |
| virtual PExpVal | GetVarVal (const TStr &VarNm) |
| virtual int | GetVars () const |
| virtual void | GetVarNmVal (const int &, TStr &, PExpVal &) const |
| virtual PExpVal | GetFuncVal (const TStr &, const TExpValV &, bool &IsFunc) |
| virtual TRnd & | GetRnd () |
| static bool | IsFuncOk (const TStr &RqFuncNm, const TExpFuncArgType &RqFuncArgType, const TStr &FuncNm, const TExpValV &ArgValV) |
| static TExpOp | GetExpOpFromLxSym (const TLxSym &LxSym) |
| static TLxSym | GetLxSymFromExpOp (const TExpOp &ExpOp) |
| static PExp | LoadTxtFact (TILx &Lx, const TFSet &Expect) |
| static PExp | LoadTxtMulExp (TILx &Lx, const TFSet &Expect) |
| static PExp | LoadTxtAddExp (TILx &Lx, const TFSet &Expect) |
| static PExp | LoadTxtRelExp (TILx &Lx, const TFSet &Expect) |
| static PExp | LoadTxtExp (TILx &Lx, const TFSet &Expect) |
| void | SaveTxtOp (TOLx &Lx) const |
| PExpVal | EvalExpOp (const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA) |
| PExpVal | EvalExp (const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA) |
| TExp (const TExpType &_ExpType=etUndef) | |
| TExp (const TExpOp &_ExpOp, const PExp &Exp1, const PExp &Exp2=NULL, const PExp &Exp3=NULL) | |
| TExp (const PExpVal &_ExpVal) | |
| TExp (const TStr &_VarNm) | |
| TExp (const TStr &_FuncNm, const TExpV &_ArgExpV) | |
| ~TExp () | |
| TExp (TSIn &SIn) | |
| TExp & | operator= (const TExp &) |
| bool | operator== (const TExp &) const |
| static bool | IsExpStrOk (const TStr &ExpStr, TStr &MsgStr) |
| static PExp | LoadTxt (const PSIn &SIn, bool &Ok, TStr &MsgStr, const TFSet &Expect=TFSet()|syEof) |
| static PExp | LoadTxt (const TStr &ExpStr, bool &Ok, TStr &MsgStr) |
| static PExp | LoadTxt (const TStr &ExpStr) |
| TStr | GetTopObjNm () const |
| int | GetArgExps () const |
| TStr | GetArgExpStr (const int &ArgExpN) const |
| PExpVal | Eval (bool &Ok, TStr &MsgStr, const bool &DbgP, TStr &DbgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv) |
| PExpVal | Eval (const PExpEnv &ExpEnv=TExpEnv::DfExpEnv) |
| PExpVal | Eval (bool &Ok, TStr &MsgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv) |
| PExpVal | Eval (const PExpEnv &ExpEnv, const bool &DbgP, TStr &DbgStr) |
| static PExpVal | LoadAndEvalExpL (const TStr &ExpLStr, bool &Ok, TStr &MsgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv) |
| static TStr | GetExpTypeStr (const TExpType &ExpType) |
| static TStr | GetExpOpStr (const TExpOp &ExpOp) |
| static void | GetBiDescV (TStrPrV &BiDescV) |
| TExpHelpItem () | |
| TExpHelpItem (const TStr &_Nm, const TStr &_TypeStr, const TStr &_DescStr, const TStr &_DfValStr) | |
| static PExpHelpItem | New (const TStr &Nm, const TStr &TypeStr, const TStr &DescStr, const TStr &DfValStr) |
| ~TExpHelpItem () | |
| TExpHelpItem (TSIn &SIn) | |
| TExpHelpItem & | operator= (const TExpHelpItem &) |
| bool | operator== (const TExpHelpItem &) const |
| TStr | GetNm () const |
| TStr | GetTypeStr () const |
| TStr | GetDescStr () const |
| TStr | GetDfValStr () const |
| TExpHelpObj () | |
| TExpHelpObj (const TExpHelpObjType &_Type, const TStr &_CatNm, const PExpHelpItem &_HdItem, const TExpHelpItemV &_ArgItemV) | |
| static PExpHelpObj | New (const TExpHelpObjType &Type, const TStr &CatNm, const PExpHelpItem &HdItem, const TExpHelpItemV &ArgItemV=TExpHelpItemV()) |
| ~TExpHelpObj () | |
| TExpHelpObj (TSIn &SIn) | |
| TExpHelpObj & | operator= (const TExpHelpObj &) |
| bool | operator== (const TExpHelpObj &) const |
| TExpHelpObjType | GetType () const |
| TStr | GetCatNm () const |
| PExpHelpItem | GetHdItem () const |
| int | GetArgItems () const |
| PExpHelpItem | GetArgItem (const int &ArgItemN) const |
| TStr | GetHdArgNmStr () const |
| static TExpHelpObjType | GetObjTypeFromStr (const TStr &TypeStr) |
| TExpHelp () | |
| static PExpHelp | New () |
| ~TExpHelp () | |
| TExpHelp (TSIn &SIn) | |
| TExpHelp & | operator= (const TExpHelp &) |
| bool | operator== (const TExpHelp &) const |
| static PExpHelp | LoadXml (const PSIn &SIn) |
| static PExpHelp | LoadXml (const TStr &FNm) |
| void | AddObj (const PExpHelpObj &Obj) |
| void | GetCatNmV (TStrV &CatNmV) const |
| void | GetObjHdNmV (const TStr &CatNm, TStrV &ObjHdNmV) const |
| PExpHelpObj | GetObj (const TStr &ObjNm) const |
Variables | |
| static ClassTPVL(TExpVal, PExpVal, TExpValV, TExpValL, TExpValLN) private PExpVal | ZeroExpVal = NULL |
| TInt | ValType |
| TAscFlt | Flt |
| TStr | Str |
| TExpValV | ValV |
| TExpValL | ValL |
| static PExpEnv | DfExpEnv = PExpEnv(new TExpEnv()) |
| ClassTPV(TExp, PExp, TExpV) private TInt | ExpType |
| TBool | IsParen |
| PExpVal | ExpVal |
| TStr | ExpNm |
| TInt | ExpOp |
| TInt | ExpBiId |
| TExpV | ArgExpV |
| static const TFSet | MulOpSymSet |
| static const TFSet | UAddOpSymSet |
| static const TFSet | AddOpSymSet |
| static const TFSet | RelOpSymSet |
| static const TFSet | FactExpExpect |
| static const TFSet | MulExpExpect |
| static const TFSet | AddExpExpect |
| static const TFSet | RelExpExpect |
| static const TFSet | ExpExpect |
| ClassTPV(TExpHelpItem, PExpHelpItem, TExpHelpItemV) private TStr | TypeStr |
| TStr | DescStr |
| TStr | DfValStr |
| ClassTPV(TExpHelpObj, PExpHelpObj, TExpHelpObjV) private TStr | CatNm |
| PExpHelpItem | HdItem |
| TExpHelpItemV | ArgItemV |
| enum TExpBiArgType |
Definition at line 132 of file exp.h.
{
ebatUndef, ebatVoid, ebatFlt, ebatFltFlt
} TExpBiArgType;
| enum TExpBiId |
Definition at line 108 of file exp.h.
{
// constants
ebi_Undef, ebi_True, ebi_False, ebi_E, ebi_Pi,
// trigonometric funcions
ebi_Sin, ebi_Cos, ebi_Tan,
ebi_ASin, ebi_ACos, ebi_ATan,
ebi_SinH, ebi_CosH, ebi_TanH,
// exponential functions
ebi_Pow, ebi_Exp, ebi_Sqr, ebi_Sqrt,
ebi_Log, ebi_Log10,
// number manipulation functions
ebi_Ceil, ebi_Floor, ebi_Int, ebi_Frac, ebi_Abs,
// random deviates
ebi_UniDev, ebi_NrmDev, ebi_ExpDev,
ebi_GamDev, ebi_PoiDev, ebi_BinDev,
ebi_UniDevStep, ebi_NrmDevStep, ebi_ExpDevStep,
} TExpBiId;
| enum TExpFuncArgType |
| enum TExpHelpObjType |
| enum TExpOp |
| enum TExpType |
| enum TExpValType |
| void AddToLst | ( | const PExpVal & | ExpVal | ) |
| void AddToVec | ( | const PExpVal & | ExpVal | ) |
| PExpVal TExp::Eval | ( | bool & | Ok, |
| TStr & | MsgStr, | ||
| const bool & | DbgP, | ||
| TStr & | DbgStr, | ||
| const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv |
||
| ) |
Definition at line 898 of file exp.cpp.
{
Ok=true; MsgStr="Ok";
PExpVal ExpVal; TChA DbgChA;
if (DbgP){DbgChA+="Debug Expression: ";}
try {
ExpVal=EvalExp(ExpEnv, DbgP, DbgChA);
}
catch (PExcept E){
Ok=false; MsgStr=E->GetMsgStr();
}
if (!Ok){return TExpVal::GetUndefExpVal();}
if (DbgP){
DbgChA+='['; DbgChA+=GetStr(); DbgChA+=" -> ";
DbgChA+=ExpVal->GetStr(); DbgChA+="] "; DbgChA+=MsgStr;
DbgStr=DbgChA;
}
return ExpVal;
}
| PExpVal Eval | ( | const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv | ) |
| PExpVal Eval | ( | bool & | Ok, |
| TStr & | MsgStr, | ||
| const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv |
||
| ) |
| PExpVal TExp::EvalExp | ( | const PExpEnv & | ExpEnv, |
| const bool & | DbgP, | ||
| TChA & | DbgChA | ||
| ) | [private] |
Definition at line 517 of file exp.cpp.
{
PExpVal OutExpVal;
TExpType _ExpType=TExpType(int(ExpType));
switch (_ExpType){
case etUndef:
OutExpVal=TExpVal::GetUndefExpVal();
break;
case etVal:
OutExpVal=ExpVal;
break;
case etVec:{
PExpVal ExpVal=TExpVal::New(evtVec);
for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
PExpVal ArgExpVal=
PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
ExpVal->AddToVec(ArgExpVal);
}
OutExpVal=ExpVal;
break;}
case etLst:{
PExpVal ExpVal=TExpVal::New(evtLst);
for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
PExpVal ArgExpVal=
PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
ExpVal->AddToLst(ArgExpVal);
}
OutExpVal=ExpVal;
break;}
case etOp:
OutExpVal=EvalExpOp(ExpEnv, DbgP, DbgChA); break;
case etVar:{
bool IsVar=false;
PExpVal ExpVal=ExpEnv->GetVarVal(ExpNm.GetUc(), IsVar);
if (!IsVar){TExcept::Throw(TStr("Variable not defined (")+ExpNm+").");}
OutExpVal=ExpVal;
break;}
case etBiConst:
OutExpVal=ExpBi.GetBiConstVal(TExpBiId(int(ExpBiId)));
break;
case etFunc:
case etBiFunc:{
TExpValV ArgExpValV(ArgExpV.Len(), 0);
for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
PExpVal ArgExpVal=
PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
ArgExpValV.Add(ArgExpVal);
}
switch (_ExpType){
case etFunc:{
bool IsFunc=false;
PExpVal ExpVal=ExpEnv->GetFuncVal(ExpNm.GetUc(), ArgExpValV, IsFunc);
if (!IsFunc){
TExcept::Throw(TStr("Function not defined (")+ExpNm+").");}
OutExpVal=ExpVal;
break;}
case etBiFunc:
OutExpVal=ExpBi.GetBiFuncVal(TExpBiId(int(ExpBiId)), ArgExpValV, ExpEnv);
break;
default: Fail; OutExpVal=NULL;
}
break;}
default: Fail; OutExpVal=NULL;
}
if (DbgP){
switch (_ExpType){
case etVal:
case etOp:
break;
case etUndef:
case etVec:
case etLst:{
TStr ExpTypeStr=TExp::GetExpTypeStr(_ExpType);
DbgChA+='['; DbgChA+=ExpTypeStr; DbgChA+='=';
DbgChA+=OutExpVal->GetStr(); DbgChA+="] ";
break;}
case etVar:
case etBiConst:
case etFunc:
case etBiFunc:
DbgChA+='['; DbgChA+=ExpNm; DbgChA+='=';
DbgChA+=OutExpVal->GetStr(); DbgChA+="] ";
break;
default: Fail;
}
}
return OutExpVal;
}
| PExpVal TExp::EvalExpOp | ( | const PExpEnv & | ExpEnv, |
| const bool & | DbgP, | ||
| TChA & | DbgChA | ||
| ) | [private] |
Definition at line 377 of file exp.cpp.
{
PExpVal OutExpVal;
TExpOp _ExpOp=TExpOp(int(ExpOp));
switch (_ExpOp){
case eoUPlus:
case eoUMinus:
case eoNot:{
PExpVal ExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
TExpValType ExpValType=ExpVal->GetValType();
if (ExpValType==evtFlt){
TFlt Flt;
switch (_ExpOp){
case eoUPlus: Flt=ExpVal->GetFltVal(); break;
case eoUMinus: Flt=-ExpVal->GetFltVal(); break;
case eoNot: Flt=double(ExpVal->GetFltValAsInt()==0);
default: Fail; Flt=0;
}
OutExpVal=TExpVal::New(Flt);
} else {
TExcept::Throw("Bad argument types.");
}
break;}
case eoPlus:
case eoMinus:
case eoMul:
case eoDiv:
case eoIDiv:
case eoMod:
case eoAnd:
case eoOr:{
PExpVal LExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
PExpVal RExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
TExpValType LExpValType=LExpVal->GetValType();
TExpValType RExpValType=RExpVal->GetValType();
if ((LExpValType==evtFlt)&&(RExpValType==evtFlt)){
// check left expression
double LVal=LExpVal->GetFltVal();
int LValExpon; frexp(LVal, &LValExpon);
if (LValExpon>150){LExpVal=TExpVal::GetZeroExpVal();}
// check right expression
double RVal=LExpVal->GetFltVal();
int RValExpon; frexp(RVal, &RValExpon);
if (RValExpon>150){RExpVal=TExpVal::GetZeroExpVal();}
// calculate
TFlt Flt;
switch (_ExpOp){
case eoPlus: Flt=LExpVal->GetFltVal()+RExpVal->GetFltVal(); break;
case eoMinus: Flt=LExpVal->GetFltVal()-RExpVal->GetFltVal(); break;
case eoMul: Flt=LExpVal->GetFltVal()*RExpVal->GetFltVal(); break;
case eoDiv:
if (RExpVal->GetFltVal()==0){TExcept::Throw("Division by zero.");}
else {Flt=LExpVal->GetFltVal()/RExpVal->GetFltVal();}
break;
case eoIDiv:
if (RExpVal->GetFltValAsInt()==0){TExcept::Throw("Division by zero.");}
else {Flt=LExpVal->GetFltValAsInt()/RExpVal->GetFltValAsInt();}
break;
case eoMod:
if (RExpVal->GetFltValAsInt()==0){TExcept::Throw("Division by zero.");}
else {Flt=LExpVal->GetFltValAsInt()%RExpVal->GetFltValAsInt();}
break;
case eoAnd:
Flt=(LExpVal->GetFltValAsInt()!=0)&&(RExpVal->GetFltValAsInt()!=0); break;
case eoOr:
Flt=(LExpVal->GetFltValAsInt()!=0)||(RExpVal->GetFltValAsInt()!=0); break;
default: Fail; Flt=0;
}
OutExpVal=TExpVal::New(Flt);
} else
if ((_ExpOp==eoPlus)&&(LExpValType==evtStr)&&(RExpValType==evtStr)){
TStr Str=LExpVal->GetStrVal()+RExpVal->GetStrVal();
OutExpVal=TExpVal::New(Str);
} else {
TExcept::Throw("Bad argument types.");
}
break;}
case eoEq:
case eoNEq:
case eoLss:
case eoGtr:
case eoLEq:
case eoGEq:{
PExpVal LExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
PExpVal RExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
TExpValType LExpValType=LExpVal->GetValType();
TExpValType RExpValType=RExpVal->GetValType();
if ((LExpValType==evtFlt)&&(RExpValType==evtFlt)){
TFlt Flt;
switch (_ExpOp){
case eoEq: Flt=double(LExpVal->GetFltVal()==RExpVal->GetFltVal()); break;
case eoNEq: Flt=double(LExpVal->GetFltVal()!=RExpVal->GetFltVal()); break;
case eoLss: Flt=double(LExpVal->GetFltVal()<RExpVal->GetFltVal()); break;
case eoGtr: Flt=double(LExpVal->GetFltVal()>RExpVal->GetFltVal()); break;
case eoLEq: Flt=double(LExpVal->GetFltVal()<=RExpVal->GetFltVal()); break;
case eoGEq: Flt=double(LExpVal->GetFltVal()>=RExpVal->GetFltVal()); break;
default: Fail; Flt=0;
}
OutExpVal=TExpVal::New(Flt);
} else
if ((LExpValType==evtStr)&&(RExpValType==evtStr)){
TFlt Flt;
switch (_ExpOp){
case eoEq: Flt=double(LExpVal->GetStrVal()==RExpVal->GetStrVal()); break;
case eoNEq: Flt=double(LExpVal->GetStrVal()!=RExpVal->GetStrVal()); break;
case eoLss: Flt=double(LExpVal->GetStrVal()<RExpVal->GetStrVal()); break;
case eoGtr: Flt=double(LExpVal->GetStrVal()>RExpVal->GetStrVal()); break;
case eoLEq: Flt=double(LExpVal->GetStrVal()<=RExpVal->GetStrVal()); break;
case eoGEq: Flt=double(LExpVal->GetStrVal()>=RExpVal->GetStrVal()); break;
default: Fail; Flt=0;
}
OutExpVal=TExpVal::New(Flt);
} else {
TExcept::Throw("Bad argument types.");
}
break;}
case eoIf:{
PExpVal CondExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
TExpValType CondExpValType=CondExpVal->GetValType();
if (CondExpValType==evtFlt){
PExpVal ExpVal;
if (CondExpVal->GetFltVal()!=0){
ExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
} else {
ExpVal=ArgExpV[2]->EvalExp(ExpEnv, DbgP, DbgChA);
}
OutExpVal=ExpVal;
} else {
TExcept::Throw("Bad argument types.");
}
break;}
default: Fail; OutExpVal=NULL;
}
if (DbgP){
DbgChA+="['"; DbgChA+=TExp::GetExpOpStr(_ExpOp);
DbgChA+="'='"; DbgChA+=OutExpVal->GetStr(); DbgChA+="'] ";
}
return OutExpVal;
}
| int TExp::GetArgExps | ( | ) | const |
| TStr TExp::GetArgExpStr | ( | const int & | ArgExpN | ) | const |
| PExpHelpItem GetArgItem | ( | const int & | ArgItemN | ) | const |
| int GetArgItems | ( | ) | const |
| void TExp::GetBiDescV | ( | TStrPrV & | BiDescV | ) | [static] |
Definition at line 967 of file exp.cpp.
{
BiDescV.Clr();
// constants
BiDescV.Add(TStrPr("True", "Logical 'True' == 1."));
BiDescV.Add(TStrPr("False", "Logical 'False' == 0."));
BiDescV.Add(TStrPr("E", "Nat. logarithm basis (2.7182...)."));
BiDescV.Add(TStrPr("Pi", "Constant pi (3.1415...)."));
// trigonometric funcions
BiDescV.Add(TStrPr("Sin(X)", "Sine of angle in radians."));
BiDescV.Add(TStrPr("Cos(X)", "Cosine of angle in radians."));
BiDescV.Add(TStrPr("Tan(X)", "Tangent of angle in radians."));
BiDescV.Add(TStrPr("ASin(X)", "Arc sine of (-1..+1)."));
BiDescV.Add(TStrPr("ACos(X)", "Arc cosine of (-1..+1)."));
BiDescV.Add(TStrPr("ATan(X)", "Arc tangent of (-inf..+inf)."));
BiDescV.Add(TStrPr("SinH(X)", "Hyperbolic sine."));
BiDescV.Add(TStrPr("CosH(X)", "Hyperbolic cosine."));
BiDescV.Add(TStrPr("TanH(X)", "Hyperbolic tangent."));
// exponential functions
BiDescV.Add(TStrPr("Pow(X, Y)", "X to the power of Y."));
BiDescV.Add(TStrPr("Exp(X)", "Exponential E to the power of X."));
BiDescV.Add(TStrPr("Sqr(X)", "X squared."));
BiDescV.Add(TStrPr("Sqrt(X)", "Positive square root."));
BiDescV.Add(TStrPr("Log(X)", "Natural logarithm."));
BiDescV.Add(TStrPr("Log10(X)", "Base 10 logarithm."));
// number manipulation functions
BiDescV.Add(TStrPr("Ceil(X)", "The smallest integer not less than X."));
BiDescV.Add(TStrPr("Floor(X)", "The largest integer not greater than X."));
BiDescV.Add(TStrPr("Int(X)", "Integer part of X."));
BiDescV.Add(TStrPr("Frac(X)", "Fractional part of X."));
BiDescV.Add(TStrPr("Abs(X)", "Absolute value of X."));
// random deviates
BiDescV.Add(TStrPr("UniDev()", "Uniform deviate (0..1)."));
BiDescV.Add(TStrPr("NrmDev()", "Normal deviate (0, 1)."));
BiDescV.Add(TStrPr("ExpDev()", "Exponential deviate."));
BiDescV.Add(TStrPr("GamDev(Order)", "Gamma deviate of Order."));
BiDescV.Add(TStrPr("PoiDev(Mean)", "Poisson deviate."));
BiDescV.Add(TStrPr("BinDev(Prb, Trials)", "Binomial deviate."));
// operators
BiDescV.Add(TStrPr("+N", "Unary plus."));
BiDescV.Add(TStrPr("-N", "Unary minus."));
BiDescV.Add(TStrPr("!L", "Not."));
BiDescV.Add(TStrPr("N1+N2", "Plus."));
BiDescV.Add(TStrPr("N1-N2", "Minus."));
BiDescV.Add(TStrPr("N1*N2", "Multiply."));
BiDescV.Add(TStrPr("N1/N2", "Division."));
BiDescV.Add(TStrPr("N1#N2", "Integer division."));
BiDescV.Add(TStrPr("N1%N2", "Modulo."));
BiDescV.Add(TStrPr("L1&L2", "And."));
BiDescV.Add(TStrPr("L1|L2", "Or."));
BiDescV.Add(TStrPr("E1=E2", "Equal."));
BiDescV.Add(TStrPr("E1<>E2", "Not equal."));
BiDescV.Add(TStrPr("E1<E2", "Less."));
BiDescV.Add(TStrPr("E1>E2", "Greater."));
BiDescV.Add(TStrPr("E1<=E2", "Less or equal."));
BiDescV.Add(TStrPr("E1>=E2", "Greater or equal."));
BiDescV.Add(TStrPr("L?E1:E2", "If L then return E1 else return E2."));
}
| void TExpHelp::GetCatNmV | ( | TStrV & | CatNmV | ) | const |
| TStr GetDescStr | ( | ) | const |
| TStr GetDfValStr | ( | ) | const |
| TExpOp TExp::GetExpOpFromLxSym | ( | const TLxSym & | LxSym | ) | [static, private] |
Definition at line 606 of file exp.cpp.
{
switch (LxSym){
case syPlus: return eoPlus;
case syMinus: return eoMinus;
case syAsterisk: return eoMul;
case sySlash: return eoDiv;
case syPercent: return eoMod;
case syExclamation: return eoNot;
case syVBar: return eoOr;
case syAmpersand: return eoAnd;
case syQuestion: return eoIf;
case syHash: return eoIDiv;
case syEq: return eoEq;
case syNEq: return eoNEq;
case syLss: return eoLss;
case syGtr: return eoGtr;
case syLEq: return eoLEq;
case syGEq: return eoGEq;
default: Fail; return eoUndef;
}
}
| static TStr GetExpOpStr | ( | const TExpOp & | ExpOp | ) | [static] |
Definition at line 264 of file exp.h.
{
return TLxSymStr::GetSymStr(TExp::GetLxSymFromExpOp(ExpOp));}
| TStr TExp::GetExpTypeStr | ( | const TExpType & | ExpType | ) | [static] |
Definition at line 952 of file exp.cpp.
{
switch (ExpType){
case etUndef: return "Undef";
case etVal: return "Val";
case etVec: return "Vec";
case etLst: return "Lst";
case etOp: return "Op";
case etVar: return "Var";
case etBiConst: return "BiConst";
case etFunc: return "Func";
case etBiFunc: return "BiFunc";
default: Fail; return "";
}
}
| double GetFltVal | ( | ) | const |
Definition at line 48 of file exp.h.
{
if (GetValType()==evtFlt){return Flt;} else {return 0;}}
| int TExpVal::GetFltValAsInt | ( | const bool & | ThrowExceptP = true | ) | const |
| virtual PExpVal GetFuncVal | ( | const TStr & | , |
| const TExpValV & | , | ||
| bool & | IsFunc | ||
| ) | [virtual] |
Definition at line 93 of file exp.h.
{
IsFunc=false; return TExpVal::GetUndefExpVal();}
| TStr TExpHelpObj::GetHdArgNmStr | ( | ) | const |
Definition at line 1032 of file exp.cpp.
{
TChA ChA;
switch (Type){
case ehotOp: {// operator
TStr OpStr=HdItem->GetNm();
if (ArgItemV.Len()==1){
ChA+=OpStr; ChA+=" "; ChA+=ArgItemV[0]->GetNm();
} else
if (ArgItemV.Len()==2){
ChA+=ArgItemV[0]->GetNm();
ChA+=" "; ChA+=OpStr; ChA+=" ";
ChA+=ArgItemV[1]->GetNm();
} else
if (ArgItemV.Len()==3){
ChA+=ArgItemV[0]->GetNm();
ChA+=" "; ChA+=OpStr; ChA+=" ";
ChA+=ArgItemV[1]->GetNm();
ChA+=" "; ChA+=":"; ChA+=" ";
ChA+=ArgItemV[2]->GetNm();
} else {
Fail;
}
break;}
case ehotVar: // variable
ChA+=HdItem->GetNm(); break;
case ehotFunc: // function
ChA+=HdItem->GetTypeStr(); ChA+=" <- ";
ChA+=HdItem->GetNm();
ChA+="(";
{for (int ArgN=0; ArgN<ArgItemV.Len(); ArgN++){
if (ArgN>0){ChA+=", ";}
ChA+=ArgItemV[ArgN]->GetNm();
}}
ChA+=")";
break;
case ehotTempl: // template
ChA+=HdItem->GetTypeStr(); break;
default: Fail;
}
return ChA;
}
| TLxSym TExp::GetLxSymFromExpOp | ( | const TExpOp & | ExpOp | ) | [static, private] |
Definition at line 628 of file exp.cpp.
{
switch (ExpOp){
case eoUPlus: return syPlus;
case eoUMinus: return syMinus;
case eoNot: return syExclamation;
case eoPlus: return syPlus;
case eoMinus: return syMinus;
case eoMul: return syAsterisk;
case eoDiv: return sySlash;
case eoIDiv: return syHash;
case eoMod: return syPercent;
case eoAnd: return syAmpersand;
case eoOr: return syVBar;
case eoEq: return syEq;
case eoNEq: return syNEq;
case eoLss: return syLss;
case eoGtr: return syGtr;
case eoLEq: return syLEq;
case eoGEq: return syGEq;
case eoIf: return syQuestion;
default: Fail; return syUndef;
}
}
| PExpHelpObj TExpHelp::GetObj | ( | const TStr & | ObjNm | ) | const |
| void TExpHelp::GetObjHdNmV | ( | const TStr & | CatNm, |
| TStrV & | ObjHdNmV | ||
| ) | const |
| TExpHelpObjType TExpHelpObj::GetObjTypeFromStr | ( | const TStr & | TypeStr | ) | [static] |
| TStr TExp::GetTopObjNm | ( | ) | const |
| TExpHelpObjType GetType | ( | ) | const |
Definition at line 333 of file exp.h.
{return TExpHelpObjType(int(Type));}
| TStr GetTypeStr | ( | ) | const |
| PExpVal TExpVal::GetUndefExpVal | ( | ) | [static] |
Definition at line 123 of file exp.cpp.
{
if (UndefExpVal.Empty()){
UndefExpVal=TExpVal::New();}
return UndefExpVal;
}
| TExpValType GetValType | ( | ) | const |
Definition at line 43 of file exp.h.
{return TExpValType(int(ValType));}
| virtual void GetVarNmVal | ( | const int & | , |
| TStr & | , | ||
| PExpVal & | |||
| ) | const [virtual] |
Definition at line 85 of file exp.h.
{
IsVar=false; return TExpVal::GetUndefExpVal();}
| PExpVal TExpVal::GetZeroExpVal | ( | ) | [static] |
Definition at line 129 of file exp.cpp.
{
if (ZeroExpVal.Empty()){
ZeroExpVal=TExpVal::New(double(0));}
return ZeroExpVal;
}
| static bool IsExpStrOk | ( | const TStr & | ExpStr, |
| TStr & | MsgStr | ||
| ) | [static] |
Definition at line 44 of file exp.h.
{
if (GetValType()==evtFlt){_Flt=Flt; return true;} else {return false;}}
| bool IsFltVal | ( | double & | _Flt | ) | const |
Definition at line 46 of file exp.h.
{
if (GetValType()==evtFlt){_Flt=Flt; return true;} else {return false;}}
| bool TExpEnv::IsFuncOk | ( | const TStr & | RqFuncNm, |
| const TExpFuncArgType & | RqFuncArgType, | ||
| const TStr & | FuncNm, | ||
| const TExpValV & | ArgValV | ||
| ) | [static] |
Definition at line 137 of file exp.cpp.
{
if (RqFuncNm.GetUc()!=FuncNm.GetUc()){return false;}
switch (RqFuncArgType){
case efatVoid: return ArgValV.Len()==0;
case efatFlt:
if (ArgValV.Len()!=1){return false;}
if (ArgValV[0]->GetValType()!=evtFlt){return false;}
return true;
case efatStr:
if (ArgValV.Len()!=1){return false;}
if (ArgValV[0]->GetValType()!=evtStr){return false;}
return true;
case efatFltFlt:
if (ArgValV.Len()!=2){return false;}
if (ArgValV[0]->GetValType()!=evtFlt){return false;}
if (ArgValV[1]->GetValType()!=evtFlt){return false;}
return true;
case efatFltStr:
if (ArgValV.Len()!=2){return false;}
if (ArgValV[0]->GetValType()!=evtFlt){return false;}
if (ArgValV[1]->GetValType()!=evtStr){return false;}
return true;
case efatStrFlt:
if (ArgValV.Len()!=2){return false;}
if (ArgValV[0]->GetValType()!=evtStr){return false;}
if (ArgValV[1]->GetValType()!=evtFlt){return false;}
return true;
case efatStrStr:
if (ArgValV.Len()!=2){return false;}
if (ArgValV[0]->GetValType()!=evtStr){return false;}
if (ArgValV[1]->GetValType()!=evtStr){return false;}
return true;
case efatStrAny:
if (ArgValV.Len()!=2){return false;}
if (ArgValV[0]->GetValType()!=evtStr){return false;}
return true;
default: Fail; return false;
}
}
| PExpVal TExp::LoadAndEvalExpL | ( | const TStr & | ExpLStr, |
| bool & | Ok, | ||
| TStr & | MsgStr, | ||
| const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv |
||
| ) | [static] |
Definition at line 918 of file exp.cpp.
{
// create final expression value
PExpVal ExpVal;
// transform exp. str. to input stream
PSIn SIn=TStrIn::New(ExpLStr);
// create lexical
TILx Lx(SIn, TFSet()|iloCmtAlw|iloCsSens|iloExcept);
TFSet Expect=TFSet()|sySemicolon|syEof;
// load & evaluate expression separated by semicolon
while (Lx.Sym!=syEof){
// create expression
PExp Exp; Ok=true; MsgStr="Ok";
try {
Lx.GetSym(ExpExpect);
Exp=LoadTxtExp(Lx, Expect);
}
catch (PExcept Except){
Ok=false; MsgStr=Except->GetMsgStr();
Exp=PExp(new TExp(etUndef));
}
// evaluate expression
if (Ok){
ExpVal=Exp->Eval(Ok, MsgStr, ExpEnv);
//printf("%s\n", ExpVal->GetStr().CStr());
if (!Ok){
return NULL;}
} else {
return NULL;
}
}
return ExpVal;
}
| static PExp LoadTxt | ( | const PSIn & | SIn, |
| bool & | Ok, | ||
| TStr & | MsgStr, | ||
| const TFSet & | Expect = TFSet()|syEof |
||
| ) | [static] |
Definition at line 236 of file exp.h.
{
PSIn SIn=TStrIn::New(ExpStr); return LoadTxt(SIn, Ok, MsgStr);}
| PExp TExp::LoadTxtAddExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 704 of file exp.cpp.
{
TExpOp PrefExpOp=eoUndef;
if (Lx.Sym==syPlus){PrefExpOp=eoUPlus; Lx.GetSym(MulExpExpect);}
else if (Lx.Sym==syMinus){PrefExpOp=eoUMinus; Lx.GetSym(MulExpExpect);}
PExp Exp=LoadTxtMulExp(Lx, TFSet(Expect)|AddOpSymSet);
if (PrefExpOp!=eoUndef){
Exp=PExp(new TExp(PrefExpOp, Exp));}
while (AddOpSymSet.In(Lx.Sym)){
TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
Lx.GetSym(MulExpExpect);
PExp RExp=LoadTxtMulExp(Lx, TFSet(Expect)|AddOpSymSet);
Exp=PExp(new TExp(ExpOp, Exp, RExp));
}
return Exp;
}
| PExp TExp::LoadTxtExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 731 of file exp.cpp.
{
PExp Exp=LoadTxtRelExp(Lx, TFSet(Expect)|syQuestion);
if (Lx.Sym==syQuestion){
TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
Lx.GetSym(ExpExpect);
PExp ThenExp=LoadTxtExp(Lx, TFSet()|syColon);
Lx.GetSym(ExpExpect);
PExp ElseExp=LoadTxtExp(Lx, Expect);
Exp=PExp(new TExp(ExpOp, Exp, ThenExp, ElseExp));
}
return Exp;
}
| PExp TExp::LoadTxtFact | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 652 of file exp.cpp.
{
PExp Exp;
switch (Lx.Sym){
case syFlt:{
PExpVal ExpVal=TExpVal::New(Lx.Flt);
Exp=PExp(new TExp(ExpVal));
Lx.GetSym(Expect);
break;}
case syIdStr:{
TStr ExpNm=Lx.Str;
Lx.GetSym(TFSet(Expect)|syLParen);
if (Lx.Sym==syLParen){
TExpV ArgExpV;
Lx.GetSym(TFSet(ExpExpect)|syRParen);
while (Lx.Sym!=syRParen){
if (Lx.Sym==syComma){Lx.GetSym(ExpExpect);}
PExp ArgExp=LoadTxtExp(Lx, TFSet()|syComma|syRParen);
ArgExpV.Add(ArgExp);
}
Lx.GetSym(Expect);
Exp=PExp(new TExp(ExpNm, ArgExpV));
} else {
Exp=PExp(new TExp(ExpNm));
}
break;}
case syQStr:{
PExpVal ExpVal=TExpVal::New(Lx.Str);
Exp=PExp(new TExp(ExpVal));
Lx.GetSym(Expect);
break;}
case syLParen:{
Lx.GetSym(ExpExpect);
Exp=LoadTxtExp(Lx, TFSet()|syRParen);
Exp->IsParen=true;
Lx.GetSym(Expect);
break;}
default: Fail;
}
return Exp;
}
| PExp TExp::LoadTxtMulExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 693 of file exp.cpp.
{
PExp Exp=LoadTxtFact(Lx, TFSet(Expect)|MulOpSymSet);
while (MulOpSymSet.In(Lx.Sym)){
TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
Lx.GetSym(FactExpExpect);
PExp RExp=LoadTxtFact(Lx, TFSet(Expect)|MulOpSymSet);
Exp=PExp(new TExp(ExpOp, Exp, RExp));
}
return Exp;
}
| PExp TExp::LoadTxtRelExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 720 of file exp.cpp.
{
PExp Exp=LoadTxtAddExp(Lx, TFSet(Expect)|RelOpSymSet);
if (RelOpSymSet.In(Lx.Sym)){
TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
Lx.GetSym(AddExpExpect);
PExp RExp=LoadTxtAddExp(Lx, Expect);
Exp=PExp(new TExp(ExpOp, Exp, RExp));
}
return Exp;
}
| static PExpVal MkClone | ( | const PExpVal & | ExpVal | ) | [static] |
| static PExpVal New | ( | const TExpValType & | ValType = evtUndef | ) | [static] |
| static PExpVal New | ( | const double & | Flt | ) | [static] |
| static PExpHelpItem New | ( | const TStr & | Nm, |
| const TStr & | TypeStr, | ||
| const TStr & | DescStr, | ||
| const TStr & | DfValStr | ||
| ) | [static] |
Definition at line 282 of file exp.h.
{
return PExpHelpItem(new TExpHelpItem(Nm, TypeStr, DescStr, DfValStr));}
| static PExpHelpObj New | ( | const TExpHelpObjType & | Type, |
| const TStr & | CatNm, | ||
| const PExpHelpItem & | HdItem, | ||
| const TExpHelpItemV & | ArgItemV = TExpHelpItemV() |
||
| ) | [static] |
Definition at line 318 of file exp.h.
{
return PExpHelpObj(new TExpHelpObj(Type, CatNm, HdItem, ArgItemV));}
| static PExpHelp New | ( | ) | [static] |
| bool operator< | ( | const TExpVal & | ExpVal | ) | const |
| TExpHelpItem& operator= | ( | const TExpHelpItem & | ) |
| TExpHelpObj& operator= | ( | const TExpHelpObj & | ) |
| bool operator== | ( | const TExpVal & | ExpVal | ) | const |
| bool operator== | ( | const TExpEnv & | ) | const |
| bool operator== | ( | const TExpHelpItem & | ) | const |
| bool operator== | ( | const TExpHelpObj & | ) | const |
| bool operator== | ( | const TExpHelp & | ) | const |
| void TExp::SaveTxtOp | ( | TOLx & | Lx | ) | const [private] |
Definition at line 744 of file exp.cpp.
{
IAssert(TExpType(static_cast<int>(ExpType))==etOp);
TExpOp _ExpOp=TExpOp(int(ExpOp));
TLxSym OpSym=GetLxSymFromExpOp(_ExpOp);
switch (_ExpOp){
case eoUPlus:
case eoUMinus:
case eoNot:
Lx.PutSym(OpSym); ArgExpV[0]->SaveTxt(Lx);
break;
case eoPlus: case eoMinus:
case eoMul: case eoDiv:
case eoIDiv: case eoMod:
case eoAnd: case eoOr:
case eoEq: case eoNEq:
case eoLss: case eoGtr:
case eoLEq: case eoGEq:
ArgExpV[0]->SaveTxt(Lx); Lx.PutSym(OpSym); ArgExpV[1]->SaveTxt(Lx);
break;
case eoIf:
ArgExpV[0]->SaveTxt(Lx); Lx.PutSym(OpSym);
ArgExpV[1]->SaveTxt(Lx); Lx.PutSym(syColon); ArgExpV[2]->SaveTxt(Lx);
break;
default: Fail;
}
}
| TExp::TExp | ( | const TExpOp & | _ExpOp, |
| const PExp & | Exp1, | ||
| const PExp & | Exp2 = NULL, |
||
| const PExp & | Exp3 = NULL |
||
| ) |
| TExp::TExp | ( | const PExpVal & | _ExpVal | ) |
| TExp::TExp | ( | const TStr & | _VarNm | ) |
| TExp::TExp | ( | const TStr & | _FuncNm, |
| const TExpV & | _ArgExpV | ||
| ) |
| TExpHelpItem | ( | const TStr & | _Nm, |
| const TStr & | _TypeStr, | ||
| const TStr & | _DescStr, | ||
| const TStr & | _DfValStr | ||
| ) |
| TExpHelpItem | ( | TSIn & | SIn | ) |
| TExpHelpObj | ( | ) |
| TExpHelpObj | ( | const TExpHelpObjType & | _Type, |
| const TStr & | _CatNm, | ||
| const PExpHelpItem & | _HdItem, | ||
| const TExpHelpItemV & | _ArgItemV | ||
| ) |
| TExpHelpObj | ( | TSIn & | SIn | ) |
| TExpVal | ( | const TExpValType & | _ValType = evtUndef | ) |
| TExpVal | ( | const double & | _Flt | ) |
| ~TExpHelpItem | ( | ) |
| ~TExpHelpObj | ( | ) |
const TFSet TExp::AddExpExpect [static] |
const TFSet TExp::AddOpSymSet [static] |
| ClassTPV (TExpHelpObj, PExpHelpObj, TExpHelpObjV) private TStr CatNm |
PExpEnv TExpEnv::DfExpEnv = PExpEnv(new TExpEnv()) [static] |
const TFSet TExp::ExpExpect [static] |
const TFSet TExp::FactExpExpect [static] |
const TFSet TExp::MulExpExpect [static] |
const TFSet TExp::MulOpSymSet [static] |
const TFSet TExp::RelExpExpect [static] |
const TFSet TExp::RelOpSymSet [static] |
| ClassTPV (TExpHelpItem, PExpHelpItem, TExpHelpItemV) private TStr TypeStr |
const TFSet TExp::UAddOpSymSet [static] |
PExpVal TExpVal::ZeroExpVal = NULL [static] |