Exemple #1
0
        public ValueSpecification evaluateExpression(Dictionary <string, ValueSpecification> c)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("Evaluate Expression");

            foreach (KeyValuePair <string, ValueSpecification> val in c)
            {
                string             valueS = "NotDef";
                ValueSpecification value  = val.Value;
                if (value.GetType().ToString() == "Mascaret.InstanceValue")
                {
                    valueS = ((InstanceValue)value).SpecValue.getFullName();
                }
                else
                {
                    MascaretApplication.Instance.VRComponentFactory.Log(value.GetType().ToString());
                }

                MascaretApplication.Instance.VRComponentFactory.Log("Context : " + val.Key + " = " + valueS);
            }

            OCLExpressionLexer  lex    = new OCLExpressionLexer(new AntlrInputStream(expressionValue));
            CommonTokenStream   tokens = new CommonTokenStream(lex);
            OCLExpressionParser parser = new OCLExpressionParser(tokens);

            parser.context = c;
            parser.expression();
            MascaretApplication.Instance.VRComponentFactory.Log("Parsing  : " + expressionValue);
            MascaretApplication.Instance.VRComponentFactory.Log("Nb Erreur : " + parser.NumberOfSyntaxErrors);


            return((LiteralBoolean)(parser.value));
        }
Exemple #2
0
        public InstanceSpecification getInstanceValue()
        {
            //callbackMethod
            _update();

            ValueSpecification vSpec = null;

            if (values.Count == 1)
            {
                foreach (ValueSpecification valueSpec in values.Values)
                {
                    vSpec = valueSpec;
                }
            }

            // Check if value exist
            if (vSpec == null)
            {
                return(null);
            }

            if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
            {
                throw new Exception("Can not use this method with this kind of parameter !");
            }

            InstanceValue iValue = (InstanceValue)vSpec;

            return(iValue.SpecValue);
        }
Exemple #3
0
        public T getValue <T>()
        {
            //callbackMethod
            _update();

            ValueSpecification vSpec = null;

            if (values.Count == 1)
            {
                foreach (ValueSpecification valueSpec in values.Values)
                {
                    vSpec = valueSpec;
                }
            }

            // Check if value exist
            if (vSpec == null)
            {
                return(default(T));
            }

            // Check if value is a Litteral Specification
            if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
            {
                // The value exist now get the Classifier
                Type         type  = typeof(T);
                IConvertible value = null;
                if (type.Equals(typeof(System.Boolean)))
                {
                    value = vSpec.getBoolFromValue();
                }
                else if (type.Equals(typeof(System.Int32)))
                {
                    value = vSpec.getIntFromValue();
                }
                else if (type.Equals(typeof(System.Double)) || type.Equals(typeof(System.Single)))
                {
                    value = vSpec.getDoubleFromValue();
                }
                else
                {
                    value = vSpec.getStringFromValue();
                }

                return((T)value);
            }
            else
            {
                throw new Exception("Can not use this method with this kind of Value");
            }
        }
Exemple #4
0
        public Dictionary <string, T> getValues <T> ()
        {
            //callbackMethod
            _update();

            Dictionary <string, T> dict = new Dictionary <string, T>();

            foreach (KeyValuePair <string, ValueSpecification> pair in values)
            {
                // Check if value is a Litteral Specification
                ValueSpecification vSpec = pair.Value;
                if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
                {
                    // The value exist now get the Classifier
                    Type         type  = typeof(T);
                    IConvertible value = null;
                    if (type.Equals(typeof(System.Boolean)))
                    {
                        value = vSpec.getBoolFromValue();
                    }
                    else if (type.Equals(typeof(System.Int32)))
                    {
                        value = vSpec.getIntFromValue();
                    }
                    else if (type.Equals(typeof(System.Double)) || type.Equals(typeof(System.Single)))
                    {
                        value = vSpec.getDoubleFromValue();
                    }
                    else
                    {
                        value = vSpec.getStringFromValue();
                    }

                    dict.Add(pair.Key, (T)value);
                }
            }

            return(dict);
        }