コード例 #1
0
        /// <summary>
        /// Provides the double value according to the value provided
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double getDoubleValue(Values.IValue value)
        {
            double retVal = 0;

            if (!(value is Values.EmptyValue))
            {
                Constants.EnumValue enumValue = value as Constants.EnumValue;
                if (enumValue != null)
                {
                    value = enumValue.Value;
                }

                Values.IntValue intValue = value as Values.IntValue;
                if (intValue != null)
                {
                    retVal = (double)intValue.Val;
                }
                else
                {
                    Values.DoubleValue doubleValue = value as Values.DoubleValue;

                    if (doubleValue != null)
                    {
                        retVal = doubleValue.Val;
                    }
                    else if (value != null)
                    {
                        throw new Exception("Value " + value.Name + " cannot be converted to double");
                    }
                }
            }

            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="Operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override Values.IValue PerformArithmericOperation(Interpreter.InterpretationContext context, Values.IValue left, Interpreter.BinaryExpression.OPERATOR Operation, Values.IValue right)  // left +/-/*/div/exp right
        {
            Values.IValue retVal = null;

            Constants.EnumValue enumValue = left as Constants.EnumValue;
            if (enumValue != null)
            {
                left = enumValue.Value;
            }

            enumValue = right as Constants.EnumValue;
            if (enumValue != null)
            {
                right = enumValue.Value;
            }

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            if (int1 == null || int2 == null)
            {
                retVal = EFSSystem.DoubleType.PerformArithmericOperation(context, left, Operation, right);
            }
            else
            {
                retVal = EFSSystem.IntegerType.PerformArithmericOperation(context, left, Operation, right);
            }

            return(retVal);
        }
コード例 #3
0
        /// <summary>
        /// Compares two ranges for equality
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override bool CompareForEquality(Values.IValue left, Values.IValue right)
        {
            bool retVal = false;

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            if (int1 != null && int2 != null)
            {
                retVal = (int1.Val == int2.Val);
            }
            else
            {
                Values.DoubleValue double1 = left as Values.DoubleValue;
                Values.DoubleValue double2 = right as Values.DoubleValue;

                if (double1 != null && double2 != null)
                {
                    retVal = Types.DoubleType.CompareDoubleForEquality(double1.Val, double2.Val);;
                }
                else
                {
                    retVal = base.CompareForEquality(left, right);
                }
            }

            return(retVal);
        }
コード例 #4
0
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.IValue retVal = null;

            if (Term != null)
            {
                retVal = Term.GetValue(context);
            }
            else
            {
                if (NOT.CompareTo(UnaryOp) == 0)
                {
                    Values.BoolValue b = Expression.GetValue(context) as Values.BoolValue;
                    if (b != null)
                    {
                        if (b.Val)
                        {
                            retVal = EFSSystem.BoolType.False;
                        }
                        else
                        {
                            retVal = EFSSystem.BoolType.True;
                        }
                    }
                    else
                    {
                        AddError("Expression " + Expression.ToString() + " does not evaluate to boolean");
                    }
                }
                else if (MINUS.CompareTo(UnaryOp) == 0)
                {
                    Values.IValue   val      = Expression.GetValue(context);
                    Values.IntValue intValue = val as Values.IntValue;
                    if (intValue != null)
                    {
                        retVal = new Values.IntValue(intValue.Type, -intValue.Val);
                    }
                    else
                    {
                        Values.DoubleValue doubleValue = val as Values.DoubleValue;
                        if (doubleValue != null)
                        {
                            retVal = new Values.DoubleValue(doubleValue.Type, -doubleValue.Val);
                        }
                    }

                    if (retVal == null)
                    {
                        AddError("Cannot negate value for " + Expression.ToString());
                    }
                }
                else
                {
                    retVal = Expression.GetValue(context);
                }
            }

            return(retVal);
        }
コード例 #5
0
        /// <summary>
        /// Parses the image and provides the corresponding value
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Values.IValue getValue(string image)
        {
            Values.IValue retVal = null;

            if (Char.IsLetter(image[0]) || image[0] == '_')
            {
                retVal = findEnumValue(image);
                if (retVal == null)
                {
                    Log.Error("Cannot create range value from " + image);
                }
            }
            else
            {
                try
                {
                    switch (getPrecision())
                    {
                    case Generated.acceptor.PrecisionEnum.aIntegerPrecision:
                    {
                        Decimal val = Decimal.Parse(image);
                        Decimal min = MinValueAsLong;
                        Decimal max = MaxValueAsLong;
                        if (val >= min && val <= max)
                        {
                            retVal = new Values.IntValue(this, val);
                        }
                    }
                    break;

                    case Generated.acceptor.PrecisionEnum.aDoublePrecision:
                    {
                        System.Globalization.CultureInfo info = System.Globalization.CultureInfo.InvariantCulture;

                        double val = getDouble(image);
                        double min = MinValueAsDouble;
                        double max = MaxValueAsDouble;
                        if (val >= min && val <= max && image.IndexOf('.') >= 0)
                        {
                            retVal = new Values.DoubleValue(this, val);
                        }
                        break;
                    }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Cannot create range value", exception);
                }
            }

            return(retVal);
        }
コード例 #6
0
        /// <summary>
        /// Converts a value in this type
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <returns></returns>
        public Values.IValue convert(Values.IValue value)
        {
            Values.IValue retVal = null;

            Constants.EnumValue enumValue = value as Constants.EnumValue;
            if (enumValue != null && enumValue.Range != null)
            {
                retVal = findEnumValue(enumValue.Name);
                if (retVal == null)
                {
                    Log.Error("Cannot convert " + enumValue.Name + " to " + FullName);
                }
            }
            else
            {
                try
                {
                    switch (getPrecision())
                    {
                    case Generated.acceptor.PrecisionEnum.aIntegerPrecision:
                    {
                        Decimal val = getValueAsInt(value);
                        Decimal min = MinValueAsLong;
                        Decimal max = MaxValueAsLong;
                        if (val >= min && val <= max)
                        {
                            retVal = new Values.IntValue(this, val);
                        }
                    }
                    break;

                    case Generated.acceptor.PrecisionEnum.aDoublePrecision:
                    {
                        double val = getValueAsDouble(value);
                        double min = MinValueAsDouble;
                        double max = MaxValueAsDouble;
                        if (val >= min && val <= max)
                        {
                            retVal = new Values.DoubleValue(this, val);
                        }
                        break;
                    }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Cannot convert range value", exception);
                }
            }

            return(retVal);
        }
コード例 #7
0
        public override bool Greater(Values.IValue left, Values.IValue right)  // left > right
        {
            bool retVal = false;

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            if (int1 != null && int2 != null)
            {
                retVal = int1.Val > int2.Val;
            }

            return(retVal);
        }
コード例 #8
0
        public override bool CompareForEquality(Values.IValue left, Values.IValue right)
        {
            bool retVal = false;

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            if (int1 != null && int2 != null)
            {
                retVal = int1.Val == int2.Val;
            }

            return(retVal);
        }
コード例 #9
0
        /// <summary>
        /// Gets a value based on its image
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Values.IValue getValue(string image)
        {
            Values.IValue retVal = null;

            try
            {
                retVal = new Values.IntValue(this, Decimal.Parse(image));
            }
            catch (Exception e)
            {
                AddException(e);
            }

            return(retVal);
        }
コード例 #10
0
        /// <summary>
        /// Finds the type of the structure corresponding to the provided NID_PACKET
        /// </summary>
        /// <param name="nameSpace">The namespace where the type has to be found</param>
        /// <param name="nidPacket">The id of the packet</param>
        /// <returns></returns>
        private Values.StructureValue FindStructure(int nidPacket)
        {
            Types.Structure structure = null;
            DataDictionary.Types.NameSpace nameSpace;

            if (nidPacket != 44)
            {
                nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages.PACKET.TRACK_TO_TRAIN");
                foreach (DataDictionary.Types.NameSpace subNameSpace in nameSpace.SubNameSpaces)
                {
                    Types.Structure       structureType  = (Types.Structure)EFSSystem.findType(subNameSpace, subNameSpace.FullName + ".Message");
                    Values.StructureValue structureValue = new Values.StructureValue(structureType, nameSpace);

                    foreach (KeyValuePair <string, Variables.IVariable> pair in structureValue.SubVariables)
                    {
                        string variableName = pair.Key;
                        if (variableName.Equals("NID_PACKET"))
                        {
                            Values.IntValue value = pair.Value.Value as Values.IntValue;
                            if (value.Val == nidPacket)
                            {
                                structure = structureType;
                            }
                        }
                        if (structure != null)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Messages.PACKET.DATA_USED_BY_APPLICATIONS_OUTSIDE_THE_ERTMS_ETCS_SYSTEM");
                structure = (Types.Structure)EFSSystem.findType(nameSpace, nameSpace.FullName + ".Message");
            }

            Values.StructureValue retVal = null;
            if (structure != null)
            {
                retVal = new Values.StructureValue(structure, nameSpace);
            }

            return(retVal);
        }
コード例 #11
0
        public override bool Less(Values.IValue left, Values.IValue right)  // left < right
        {
            bool retVal = false;

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            if (int1 != null && int2 != null)
            {
                retVal = int1.Val < int2.Val;
            }
            else
            {
                retVal = EFSSystem.DoubleType.Less(left, right);
            }

            return(retVal);
        }
コード例 #12
0
        /// <summary>
        /// Provides the double value from the IValue provided
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private double getValue(Values.IValue val)
        {
            double retVal = 0;

            Constants.EnumValue enumValue = val as Constants.EnumValue;
            if (enumValue != null)
            {
                val = enumValue.Value;
            }

            Values.DoubleValue vd = val as Values.DoubleValue;
            if (vd != null)
            {
                retVal = vd.Val;
            }
            else
            {
                Values.IntValue vi = val as Values.IntValue;
                if (vi != null)
                {
                    retVal = (double)vi.Val;
                }
                else
                {
                    Functions.Function function = val as Functions.Function;
                    if (function != null)
                    {
                        Functions.Graph graph = function.Graph;
                        if (graph != null)
                        {
                            if (graph.Segments.Count == 1)
                            {
                                retVal = graph.Val(0);
                            }
                        }
                    }
                }
            }

            return(retVal);
        }
コード例 #13
0
        /// <summary>
        /// Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="Operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override Values.IValue PerformArithmericOperation(Interpreter.InterpretationContext context, Values.IValue left, Interpreter.BinaryExpression.OPERATOR Operation, Values.IValue right)  // left +/-/*/div/exp right
        {
            Values.IntValue retVal = null;

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            switch (Operation)
            {
            case Interpreter.BinaryExpression.OPERATOR.EXP:
                retVal = new Values.IntValue(EFSSystem.IntegerType, (Decimal)Math.Pow((double)int1.Val, (double)int2.Val));
                break;

            case Interpreter.BinaryExpression.OPERATOR.MULT:
                retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val * int2.Val));
                break;

            case Interpreter.BinaryExpression.OPERATOR.DIV:
                if (int2.Val == 0)
                {
                    throw new Exception("Division by zero");
                }
                else
                {
                    retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val / int2.Val));
                }
                break;

            case Interpreter.BinaryExpression.OPERATOR.ADD:
                retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val + int2.Val));
                break;

            case Interpreter.BinaryExpression.OPERATOR.SUB:
                retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val - int2.Val));
                break;
            }

            return(retVal);
        }
コード例 #14
0
        /// <summary>
        /// Provides the value as a decimal value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private Decimal getValueAsInt(Values.IValue value)
        {
            Decimal retVal;

            Values.IntValue intVal = value as Values.IntValue;
            if (intVal != null)
            {
                retVal = intVal.Val;
            }
            else
            {
                Values.DoubleValue doubleVal = value as Values.DoubleValue;
                if (doubleVal != null)
                {
                    retVal = new Decimal(Math.Round(doubleVal.Val));
                }
                else
                {
                    throw new Exception("Cannot convert value " + value + " to " + FullName);
                }
            }

            return(retVal);
        }
コード例 #15
0
        /// <summary>
        /// Provides the value as a double value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private Double getValueAsDouble(Values.IValue value)
        {
            Double retVal;

            Values.IntValue intVal = value as Values.IntValue;
            if (intVal != null)
            {
                retVal = Decimal.ToDouble(intVal.Val);
            }
            else
            {
                Values.DoubleValue doubleVal = value as Values.DoubleValue;
                if (doubleVal != null)
                {
                    retVal = doubleVal.Val;
                }
                else
                {
                    throw new Exception("Cannot convert value " + value + " to " + FullName);
                }
            }

            return(retVal);
        }
コード例 #16
0
        // left +/-/*/div/exp right
        /// <summary>
        /// Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="Operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override Values.IValue PerformArithmericOperation(Interpreter.InterpretationContext context, Values.IValue left, Interpreter.BinaryExpression.OPERATOR Operation, Values.IValue right)
        {
            Values.IntValue retVal = null;

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            switch (Operation)
            {
                case Interpreter.BinaryExpression.OPERATOR.EXP:
                    retVal = new Values.IntValue(EFSSystem.IntegerType, (Decimal)Math.Pow((double)int1.Val, (double)int2.Val));
                    break;

                case Interpreter.BinaryExpression.OPERATOR.MULT:
                    retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val * int2.Val));
                    break;

                case Interpreter.BinaryExpression.OPERATOR.DIV:
                    if (int2.Val == 0)
                        throw new Exception("Division by zero");
                    else
                        retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val / int2.Val));
                    break;

                case Interpreter.BinaryExpression.OPERATOR.ADD:
                    retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val + int2.Val));
                    break;

                case Interpreter.BinaryExpression.OPERATOR.SUB:
                    retVal = new Values.IntValue(EFSSystem.IntegerType, (int1.Val - int2.Val));
                    break;
            }

            return retVal;
        }
コード例 #17
0
        /// <summary>
        /// Gets a value based on its image
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Values.IValue getValue(string image)
        {
            Values.IValue retVal = null;

            try
            {
                retVal = new Values.IntValue(this, Decimal.Parse(image));
            }
            catch (Exception e)
            {
                AddException(e);
            }

            return retVal;
        }
コード例 #18
0
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.IValue retVal = null;

            if (Term != null)
            {
                retVal = Term.GetValue(context);
            }
            else
            {
                if (NOT.CompareTo(UnaryOp) == 0)
                {
                    Values.BoolValue b = Expression.GetValue(context) as Values.BoolValue;
                    if (b != null)
                    {
                        if (b.Val)
                        {
                            retVal = EFSSystem.BoolType.False;
                        }
                        else
                        {
                            retVal = EFSSystem.BoolType.True;
                        }
                    }
                    else
                    {
                        AddError("Expression " + Expression.ToString() + " does not evaluate to boolean");
                    }
                }
                else if (MINUS.CompareTo(UnaryOp) == 0)
                {
                    Values.IValue val = Expression.GetValue(context);
                    Values.IntValue intValue = val as Values.IntValue;
                    if (intValue != null)
                    {
                        retVal = new Values.IntValue(intValue.Type, -intValue.Val);
                    }
                    else
                    {
                        Values.DoubleValue doubleValue = val as Values.DoubleValue;
                        if (doubleValue != null)
                        {
                            retVal = new Values.DoubleValue(doubleValue.Type, -doubleValue.Val);
                        }
                    }

                    if (retVal == null)
                    {
                        AddError("Cannot negate value for " + Expression.ToString());
                    }
                }
                else
                {
                    retVal = Expression.GetValue(context);
                }
            }

            return retVal;
        }
コード例 #19
0
        /// <summary>
        /// Parses the image and provides the corresponding value
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Values.IValue getValue(string image)
        {
            Values.IValue retVal = null;

            if (Char.IsLetter(image[0]) || image[0] == '_')
            {
                retVal = findEnumValue(image);
                if (retVal == null)
                {
                    Log.Error("Cannot create range value from " + image);
                }
            }
            else
            {
                try
                {
                    switch (getPrecision())
                    {
                        case Generated.acceptor.PrecisionEnum.aIntegerPrecision:
                            {
                                Decimal val = Decimal.Parse(image);
                                Decimal min = MinValueAsLong;
                                Decimal max = MaxValueAsLong;
                                if (val >= min && val <= max)
                                {
                                    retVal = new Values.IntValue(this, val);
                                }
                            }
                            break;

                        case Generated.acceptor.PrecisionEnum.aDoublePrecision:
                            {
                                System.Globalization.CultureInfo info = System.Globalization.CultureInfo.InvariantCulture;

                                double val = getDouble(image);
                                double min = MinValueAsDouble;
                                double max = MaxValueAsDouble;
                                if (val >= min && val <= max && image.IndexOf('.') >= 0)
                                {
                                    retVal = new Values.DoubleValue(this, val);
                                }
                                break;
                            }
                    }

                }
                catch (Exception exception)
                {
                    Log.Error("Cannot create range value", exception);
                }
            }

            return retVal;
        }
コード例 #20
0
        /// <summary>
        /// Converts a value in this type
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <returns></returns>
        public Values.IValue convert(Values.IValue value)
        {
            Values.IValue retVal = null;

            Constants.EnumValue enumValue = value as Constants.EnumValue;
            if (enumValue != null && enumValue.Range != null)
            {
                retVal = findEnumValue(enumValue.Name);
                if (retVal == null)
                {
                    Log.Error("Cannot convert " + enumValue.Name + " to " + FullName);
                }
            }
            else
            {
                try
                {
                    switch (getPrecision())
                    {
                        case Generated.acceptor.PrecisionEnum.aIntegerPrecision:
                            {
                                Decimal val = getValueAsInt(value);
                                Decimal min = MinValueAsLong;
                                Decimal max = MaxValueAsLong;
                                if (val >= min && val <= max)
                                {
                                    retVal = new Values.IntValue(this, val);
                                }
                            }
                            break;
                        case Generated.acceptor.PrecisionEnum.aDoublePrecision:
                            {
                                double val = getValueAsDouble(value);
                                double min = MinValueAsDouble;
                                double max = MaxValueAsDouble;
                                if (val >= min && val <= max)
                                {
                                    retVal = new Values.DoubleValue(this, val);
                                }
                                break;
                            }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Cannot convert range value", exception);
                }
            }

            return retVal;
        }