public virtual bool Contains(Values.IValue right, Values.IValue left) // left in right { throw new TypeInconsistancyException("Variable of type " + GetType() + " cannot contain a variable of type " + left.GetType()); }
/// <summary> /// Provides the value associated to this Term /// </summary> /// <param name="instance">The instance on which the value is computed</param> /// <param name="globalFind">Indicates that the search should be performed globally</param> /// <returns></returns> public override Values.IValue GetValue(InterpretationContext context) { Values.IValue retVal = null; ExplanationPart previous = SetupExplanation(); Values.IValue leftValue = null; Values.IValue rightValue = null; try { leftValue = Left.GetValue(context); if (leftValue != null) { switch (Operation) { case OPERATOR.EXP: case OPERATOR.MULT: case OPERATOR.ADD: case OPERATOR.SUB: case OPERATOR.DIV: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = leftValue.Type.PerformArithmericOperation(context, leftValue, Operation, rightValue); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.AND: { if (leftValue.Type == EFSSystem.BoolType) { Values.BoolValue lb = leftValue as Values.BoolValue; if (lb.Val) { rightValue = Right.GetValue(context); if (rightValue != null) { if (rightValue.Type == EFSSystem.BoolType) { retVal = rightValue as Values.BoolValue; } else { AddError("Cannot apply an operator " + Operation.ToString() + " on a variable of type " + rightValue.GetType()); } } else { AddError("Error while computing value for " + Right.ToString()); } } else { retVal = lb; } } else { AddError("Cannot apply an operator " + Operation.ToString() + " on a variable of type " + leftValue.GetType()); } } break; case OPERATOR.OR: { if (leftValue.Type == EFSSystem.BoolType) { Values.BoolValue lb = leftValue as Values.BoolValue; if (!lb.Val) { rightValue = Right.GetValue(context); if (rightValue != null) { if (rightValue.Type == EFSSystem.BoolType) { retVal = rightValue as Values.BoolValue; } else { AddError("Cannot apply an operator " + Operation.ToString() + " on a variable of type " + rightValue.GetType()); } } else { AddError("Error while computing value for " + Right.ToString()); } } else { retVal = lb; } } else { AddError("Cannot apply an operator " + Operation.ToString() + " on a variable of type " + leftValue.GetType()); } } break; case OPERATOR.LESS: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(leftValue.Type.Less(leftValue, rightValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.LESS_OR_EQUAL: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(leftValue.Type.CompareForEquality(leftValue, rightValue) || leftValue.Type.Less(leftValue, rightValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.GREATER: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(leftValue.Type.Greater(leftValue, rightValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.GREATER_OR_EQUAL: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(leftValue.Type.CompareForEquality(leftValue, rightValue) || leftValue.Type.Greater(leftValue, rightValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.EQUAL: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(leftValue.Type.CompareForEquality(leftValue, rightValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.NOT_EQUAL: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(!leftValue.Type.CompareForEquality(leftValue, rightValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.IN: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(rightValue.Type.Contains(rightValue, leftValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; case OPERATOR.NOT_IN: { rightValue = Right.GetValue(context); if (rightValue != null) { retVal = EFSSystem.GetBoolean(!rightValue.Type.Contains(rightValue, leftValue)); } else { AddError("Error while computing value for " + Right.ToString()); } } break; } } else { AddError("Error while computing value for " + Left.ToString()); } } catch (Exception e) { AddError(e.Message); } if (explain) { CompleteExplanation(previous, Name + " = " + explainNamable(retVal)); } return(retVal); }