Exemple #1
0
 /// <summary>Calculates the operations that are allowed for two double values.
 /// </summary>
 /// <param name="oper"></param>
 /// <param name="elLeft"></param>
 /// <param name="elRight"></param>
 /// <param name="valLeft"></param>
 /// <param name="valRight"></param>
 /// <returns></returns>
 private bool CalculateDoubleOperation(tkOperation oper, Element elLeft, Element elRight, ExpressionValue valLeft, ExpressionValue valRight)
 {
     elLeft.calcVal.type = tkValueType.vtDouble;
     switch (oper)
     {
         case tkOperation.operLess:
             elLeft.calcVal.bln = valLeft.dbl < valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtBoolean;
             break;
         case tkOperation.operLessEqual:
             elLeft.calcVal.bln = valLeft.dbl <= valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtBoolean;
             break;
         case tkOperation.operGreater:
             elLeft.calcVal.bln = valLeft.dbl > valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtBoolean;
             break;
         case tkOperation.operGrEqual:
             elLeft.calcVal.bln = valLeft.dbl >= valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtBoolean;
             break;
         case tkOperation.operEqual:
             elLeft.calcVal.bln = valLeft.dbl == valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtBoolean;
             break;
         case tkOperation.operNotEqual:
             elLeft.calcVal.bln = valLeft.dbl != valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtBoolean;
             break;
         case tkOperation.operMinus:
             elLeft.calcVal.dbl = valLeft.dbl - valRight.dbl;
             elLeft.calcVal.type = tkValueType.vtDouble;
             break;
         case tkOperation.operMult:
             elLeft.calcVal.dbl = valLeft.dbl * valRight.dbl;
             break;
         case tkOperation.operExpon:
             elLeft.calcVal.dbl = Math.Pow(valLeft.dbl, valRight.dbl);
             break;
         case tkOperation.operMOD:
             elLeft.calcVal.dbl = (double)((int)valLeft.dbl % (int)valRight.dbl);
             break;
         case tkOperation.operDiv:
             if (valRight.dbl == 0.0)
             {
                 _errorMessage = SymbologyMessageStrings.Expression_ZeroDivision;
                 return false;
             }
             elLeft.calcVal.dbl = valLeft.dbl / valRight.dbl;
             break;
         case tkOperation.operDivInt:
             if (valRight.dbl == 0.0)
             {
                 _errorMessage = SymbologyMessageStrings.Expression_ZeroDivision;
                 return false;
             }
             elLeft.calcVal.dbl = (double)((int)valLeft.dbl / (int)valRight.dbl);
             break;
         case tkOperation.operPlus:
             elLeft.calcVal.dbl = valLeft.dbl + valRight.dbl;
             break;
         default:
             {
                 _errorMessage = SymbologyMessageStrings.Expression_OperationNotSupported;
                 return false;
             }
     }
     return true;
 }
Exemple #2
0
 /// <summary>Calculates the operations that are allowed for two string values.
 /// </summary>
 /// <param name="oper"></param>
 /// <param name="elLeft"></param>
 /// <param name="elRight"></param>
 /// <param name="valLeft"></param>
 /// <param name="valRight"></param>
 /// <returns></returns>
 private bool CalculateStringOperation(tkOperation oper, Element elLeft, Element elRight, ExpressionValue valLeft, ExpressionValue valRight)
 {
     int res = string.Compare(valLeft.str.ToLower(), valRight.str.ToLower());
     elLeft.calcVal.bln = false;
     elLeft.calcVal.type = tkValueType.vtBoolean;
     switch (oper)
     {
         case tkOperation.operPlus:
             elLeft.calcVal.str = valLeft.str + valRight.str;
             elLeft.calcVal.type = tkValueType.vtString;
             break;
         case tkOperation.operLess:
             if (res < 0) elLeft.calcVal.bln = true;
             break;
         case tkOperation.operLessEqual:
             if (res <= 0) elLeft.calcVal.bln = true;
             break;
         case tkOperation.operGreater:
             if (res > 0) elLeft.calcVal.bln = true;
             break;
         case tkOperation.operGrEqual:
             if (res >= 0) elLeft.calcVal.bln = true;
             break;
         case tkOperation.operEqual:
             if (res == 0) elLeft.calcVal.bln = true;
             break;
         case tkOperation.operNotEqual:
             if (res != 0) elLeft.calcVal.bln = true;
             break;
         default:
             _errorMessage = SymbologyMessageStrings.Expression_OperationNotSupported;
             return false;
     }
     return true;
 }
Exemple #3
0
 /// <summary> Calculates the operations that are allowed for two boolean values.
 /// </summary>
 /// <param name="oper"></param>
 /// <param name="elLeft"></param>
 /// <param name="elRight"></param>
 /// <param name="valLeft"></param>
 /// <param name="valRight"></param>
 /// <returns></returns>
 private bool CalculateBoolOperation(tkOperation oper, Element elLeft, Element elRight, ExpressionValue valLeft, ExpressionValue valRight)
 {
     switch (oper)
     {
         // logical operators
         case tkOperation.operOR:
             elLeft.calcVal.bln = valLeft.bln || valRight.bln;
             break;
         case tkOperation.operAND:
             elLeft.calcVal.bln = valLeft.bln && valRight.bln;
             break;
         case tkOperation.operXOR:
             elLeft.calcVal.bln = valLeft.bln ^ valRight.bln;
             break;
         case tkOperation.operEqual:
             elLeft.calcVal.bln = valLeft.bln == valRight.bln;
             break;
         case tkOperation.operNotEqual:
             elLeft.calcVal.bln = valLeft.bln != valRight.bln;
             break;
         default:
             {
                 _errorMessage = SymbologyMessageStrings.Expression_OperationNotSupported;
                 return false;
             }
     }
     elLeft.calcVal.type = tkValueType.vtBoolean;
     return true;
 }