Ejemplo n.º 1
0
        /// <summary>
        ///     Provides the graph of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the graph</param>
        /// <param name="parameter"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = null;

            Graph graph = createGraphForValue(context, context.FindOnStack(Function).Value, explain, parameter);

            if (graph != null)
            {
                double speed     = GetDoubleValue(context.FindOnStack(Speed).Value);
                double solutionX = graph.SolutionX(speed);
                if (solutionX == double.MaxValue)
                {
                    // No value found, return Unknown
                    Range     distanceType    = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance");
                    EnumValue unknownDistance = distanceType.findEnumValue("Unknown");
                    retVal = Graph.createGraph(distanceType.getValueAsDouble(unknownDistance));
                }
                else
                {
                    // Create the graph for this solution
                    retVal = Graph.createGraph(solutionX);
                }
            }
            else
            {
                Function.AddError("Cannot create graph for " + Function);
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides the special values based on the special_or_reserved_values information
        /// </summary>
        /// <param name="special_or_reserved_values"></param>
        /// <returns></returns>
        private List <DataDictionary.Constants.EnumValue> getSpecialValues(SpecialOrReservedValue[] special_or_reserved_values)
        {
            List <DataDictionary.Constants.EnumValue> retVal = new List <DataDictionary.Constants.EnumValue>();

            if (special_or_reserved_values != null)
            {
                foreach (SpecialOrReservedValue value in special_or_reserved_values)
                {
                    if (value.match is MatchRange)
                    {
                        // Skip
                    }
                    else
                    {
                        DataDictionary.Constants.EnumValue enumValue = (DataDictionary.Constants.EnumValue)DataDictionary.Generated.acceptor.getFactory().createEnumValue();
                        if (value.match is string)
                        {
                            enumValue.Name = FormatIdentifier(value.meaning.value);
                            enumValue.setValue((string)value.match);
                        }
                        OrderedInsert(enumValue, retVal);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Provides the enum value which corresponds to the name provided
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public EnumValue findEnumValue(string name)
        {
            EnumValue retVal = null;

            retVal = (EnumValue)NamableUtils.FindByName(name, SpecialValues);

            return(retVal);
        }
 public void AddValue(DataDictionary.Constants.EnumValue value)
 {
     value.Name = "<EnumValue" + (GetNodeCount(false) + 1) + ">";
     value.setValue("");
     Item.appendValues(value);
     Nodes.Add(new EnumerationValueTreeNode(value));
     SortSubNodes();
 }
Ejemplo n.º 5
0
        /// <summary>
        ///     Appends an enum value to the enum provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        protected EnumValue CreateEnumValue(Enum enclosing, string name)
        {
            EnumValue retVal = (EnumValue)Factory.createEnumValue();

            enclosing.appendValues(retVal);
            retVal.Name = name;

            return(retVal);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Provides the enum value which corresponds to the name provided
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public EnumValue FindEnumValue(string name)
        {
            EnumValue retVal = (EnumValue)NamableUtils.FindByName(name, Values);

            if (retVal == null && EnclosingEnum != null)
            {
                retVal = EnclosingEnum.FindEnumValue(name);
            }

            return(retVal);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Adds a model element in this model element
        /// </summary>
        /// <param name="copy"></param>
        public override void AddModelElement(IModelElement element)
        {
            {
                EnumValue item = element as EnumValue;
                if (item != null)
                {
                    appendSpecialValues(item);
                }
            }

            base.AddModelElement(element);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Converts a value in this type
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <returns></returns>
        public override IValue convert(IValue value)
        {
            IValue retVal = null;

            EnumValue enumValue = value as EnumValue;

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

                    case acceptor.PrecisionEnum.aDoublePrecision:
                    {
                        double val = getValueAsDouble(value);
                        double min = MinValueAsDouble;
                        double max = MaxValueAsDouble;
                        if (val >= min && val <= max)
                        {
                            retVal = new DoubleValue(this, val);
                        }
                        break;
                    }
                    }
                }
                catch (Exception exception)
                {
                    AddException(exception);
                }
            }

            return(retVal);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Converts a value into a string
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="displayActualDefaultValue">
        ///     Indicates that the actual default value should be displayed instead of
        ///     "&lt;default&gt;"
        /// </param>
        /// <returns></returns>
        private static string ValueStringonizer(object obj, bool displayActualDefaultValue)
        {
            string retVal;

            IValue value = DerefVariable(obj);

            StructureValue structureValue = value as StructureValue;
            ListValue      listValue      = value as ListValue;

            if (structureValue != null)
            {
                retVal = "";
            }
            else if (listValue != null)
            {
                retVal = "";
            }
            else
            {
                if (displayActualDefaultValue)
                {
                    // Dereference enumeration constants to get the actual value
                    EnumValue enumValue = value as EnumValue;
                    while (enumValue != null)
                    {
                        value = enumValue.Value;
                        if (value != enumValue.Value)
                        {
                            enumValue = value as EnumValue;
                        }
                        else
                        {
                            enumValue = null;
                        }
                    }

                    retVal = value.Name;
                }
                else
                {
                    if (IsDefaultValue(value))
                    {
                        retVal = DefaultConst;
                    }
                    else
                    {
                        retVal = value.Name;
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Derefs enumerate values
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private IValue derefEnum(IValue val)
        {
            IValue retVal = val;

            EnumValue enumValue = retVal as EnumValue;

            if (enumValue != null)
            {
                retVal = enumValue.Value;
            }

            return(retVal);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Inserts the enum value using the correct order (by value)
        /// </summary>
        /// <param name="enumValue"></param>
        /// <param name="values"></param>
        private void OrderedInsert(DataDictionary.Constants.EnumValue enumValue, List <DataDictionary.Constants.EnumValue> values)
        {
            int i = 0;

            foreach (DataDictionary.Constants.EnumValue val in values)
            {
                long v1 = long.Parse(val.getValue());
                long v2 = long.Parse(enumValue.getValue());
                if (v1 > v2)
                {
                    break;
                }
                i = i + 1;
            }

            values.Insert(i, enumValue);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Ensures that the length of the section is consistent with EFS's length scale
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        private IValue SegmentLength(double length)
        {
            IValue retVal = new DoubleValue(EFSSystem.DoubleType, length);

            NameSpace defaultNameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                                                                                    "Default.BaseTypes");
            Range LengthType = defaultNameSpace.findTypeByName("Length") as Range;

            EnumValue infinity = LengthType.findEnumValue("Infinity");

            if (!LengthType.Less(retVal, infinity))
            {
                retVal = infinity;
            }

            return(retVal);
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Provides the double value from the IValue provided
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private double getValue(IValue val)
        {
            double retVal = 0;

            EnumValue enumValue = val as EnumValue;

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

            DoubleValue vd = val as DoubleValue;

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

            return(retVal);
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     Performs the dereferencing and launches an exception if the enum cannot be used for arithmetic operations
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static IValue derefEnumForArithmeticOperation(IValue value)
        {
            IValue retVal = value;

            EnumValue enumValue = value as EnumValue;

            if (enumValue != null)
            {
                if (enumValue.getForbidArithmeticOperation())
                {
                    throw new Exception("Cannot perform arithmetic operation with " + value.LiteralName);
                }
                else
                {
                    retVal = enumValue.Value;
                }
            }

            return(retVal);
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Handles setting all the update information for this element (this updates source)
        /// </summary>
        /// <param name="source"></param>
        public override void SetUpdateInformation(ModelElement source)
        {
            base.SetUpdateInformation(source);

            Enum sourceEnum = source as Enum;

            if (sourceEnum != null)
            {
                Requirements.Clear();
                setUpdates(source.Guid);

                foreach (EnumValue value in Values)
                {
                    EnumValue matchingValue = sourceEnum.FindEnumValue(value.Name);
                    value.setUpdates(matchingValue.Guid);
                }
                foreach (Enum subEnum in SubEnums)
                {
                    Enum matchingEnum = sourceEnum.FindSubEnum(subEnum.Name);
                    subEnum.SetUpdateInformation(matchingEnum);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     Provides the int value from the IValue provided
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private int getValue(IValue val)
        {
            int retVal = 0;

            EnumValue enumValue = val as EnumValue;

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

            IntValue vi = val as IntValue;

            if (vi != null)
            {
                retVal = (int)vi.Val;
            }
            else
            {
                throw new Exception("Cannot get integer value from " + val.LiteralName);
            }

            return(retVal);
        }
Ejemplo n.º 17
0
 public virtual void AddSpecialValueHandler(object sender, EventArgs e)
 {
     Item.appendSpecialValues(EnumValue.CreateDefault(Item.SpecialValues));
 }
 /// <summary>
 /// Adds a new special value to this range
 /// </summary>
 /// <param name="value"></param>
 public void AppendSpecialValue(DataDictionary.Constants.EnumValue value)
 {
     Item.appendSpecialValues(value);
     Nodes.Add(new EnumerationValueTreeNode(value));
     SortSubNodes();
 }
 public override void AddSpecialValueHandler(object sender, EventArgs e)
 {
     DataDictionary.Constants.EnumValue value = (DataDictionary.Constants.EnumValue)DataDictionary.Generated.acceptor.getFactory().createEnumValue();
     value.Name = "<unnamed>";
     AppendSpecialValue(value);
 }
Ejemplo n.º 20
0
 public void AddValueHandler(object sender, EventArgs args)
 {
     DataDictionary.Constants.EnumValue value = (DataDictionary.Constants.EnumValue)DataDictionary.Generated.acceptor.getFactory().createEnumValue();
     valuesTreeNode.AddValue(value);
 }
Ejemplo n.º 21
0
        /// <summary>
        ///     Converts a DataDictionary.Values.IValue into an EFSIPCInterface.Value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public Value ConvertOut(IValue value)
        {
            // Handles the boolean case
            {
                BoolValue v = value as BoolValue;
                if (v != null)
                {
                    return(new Values.BoolValue(v.Val));
                }
            }

            // Handles the integer case
            {
                IntValue v = value as IntValue;
                if (v != null)
                {
                    return(new Values.IntValue(v.Val));
                }
            }

            // Handles the double case
            {
                DoubleValue v = value as DoubleValue;
                if (v != null)
                {
                    return(new Values.DoubleValue(v.Val));
                }
            }

            // Handles the string case
            {
                StringValue v = value as StringValue;
                if (v != null)
                {
                    return(new Values.StringValue(v.Val));
                }
            }

            // Handles the state case
            {
                State v = value as State;
                if (v != null)
                {
                    return(new StateValue(v.FullName));
                }
            }

            // Handles the enumeration value case
            {
                EnumValue v = value as EnumValue;
                if (v != null)
                {
                    return(new Values.EnumValue(v.FullName));
                }
            }

            // Handles the list case
            {
                ListValue v = value as ListValue;
                if (v != null)
                {
                    List <Value> list = new List <Value>();

                    foreach (IValue item in v.Val)
                    {
                        list.Add(ConvertOut(item));
                    }

                    return(new Values.ListValue(list));
                }
            }

            // Handles the structure case
            {
                StructureValue v = value as StructureValue;
                if (v != null)
                {
                    Dictionary <string, Value> record = new Dictionary <string, Value>();

                    foreach (KeyValuePair <string, INamable> pair in v.Val)
                    {
                        IVariable variable = pair.Value as IVariable;
                        if (variable != null)
                        {
                            record.Add(variable.Name, ConvertOut(variable.Value));
                        }
                    }

                    return(new Values.StructureValue(record));
                }
            }

            // Handles the function case
            {
                DataDictionary.Functions.Function v = value as DataDictionary.Functions.Function;
                if (v != null)
                {
                    List <Segment> segments = new List <Segment>();

                    if (v.FormalParameters.Count == 1)
                    {
                        Graph graph = v.CreateGraph(new InterpretationContext(), (Parameter)v.FormalParameters[0], null);

                        if (graph != null)
                        {
                            foreach (Graph.Segment segment in graph.Segments)
                            {
                                double length = segment.End - segment.Start;
                                segments.Add(new Segment
                                {
                                    A      = segment.Expression.A,
                                    V0     = segment.Expression.V0,
                                    D0     = segment.Start,
                                    Length = length
                                });
                            }
                        }
                    }

                    return(new FunctionValue(segments));
                }
            }

            // Handles the 'empty' value
            {
                EmptyValue emptyValue = value as EmptyValue;
                if (emptyValue != null)
                {
                    return(null);
                }
            }

            throw new FaultException <EFSServiceFault>(new EFSServiceFault("Cannot convert value " + value));
        }