Exemple #1
0
        /// <summary>
        /// Parses an XML_SMV element and stores the result.
        /// 
        /// The XML_SMV element should contain the name, and optionally the type, const property and constant name.
        /// 
        /// If the const property is true and no name is specified, the regular name is used as the name
        /// of the singleton constant and the name of the type is renamed to name_t.
        /// 
        /// </summary>
        /// <param name="E">XML_SMV element</param>
        private static void ParseSMVelementAndAttributes(Specification S, XmlElement E)
        {
            string typeName = null;
            bool isConstant = false;
            string constantName = null;
            SMV.MULTIVECTOR_TYPE mvType = SMV.MULTIVECTOR_TYPE.MULTIVECTOR;

            { // handle attributes
                XmlAttributeCollection A = E.Attributes;

                // handle all attributes
                for (int i = 0; i < A.Count; i++)
                {
                    // name
                    if (A[i].Name == XML_NAME)
                        typeName = A[i].Value;

                    // const
                    else if (A[i].Name == XML_CONST)
                        isConstant = (A[i].Value.ToLower() == XML_TRUE);

                    // type
                    else if (A[i].Name == XML_TYPE)
                    {
                        if (A[i].Value == XML_MULTIVECTOR)
                            mvType = SMV.MULTIVECTOR_TYPE.MULTIVECTOR;
                        else if (A[i].Value == XML_BLADE)
                            mvType = SMV.MULTIVECTOR_TYPE.BLADE;
                        else if (A[i].Value == XML_ROTOR)
                            mvType = SMV.MULTIVECTOR_TYPE.ROTOR;
                        else if (A[i].Value == XML_VERSOR)
                            mvType = SMV.MULTIVECTOR_TYPE.VERSOR;
                        else throw new G25.UserException("XML parsing error: Invalid value for attribute'" + XML_TYPE + "':'" + A[i].Value + "' in element '" + XML_SMV + "'.");
                    }
                }

                // sanity check on name
                if (typeName == null)
                    throw new G25.UserException("XML parsing error: Missing '" + XML_NAME + "' attribute in element '" + XML_SMV + "'.");

                // if constant and no constantName provided, use the typeName as the constantName, and set typeName to typeName + "_t"
                if (isConstant && (constantName == null))
                {
                    // if a constant should be generated and no constant name is specified
                    constantName = typeName;
                    typeName = constantName + Specification.CONSTANT_TYPE_SUFFIX;
                }

                // check if name is already present
                if (S.IsTypeName(typeName))
                    throw new G25.UserException("In specialized multivector definition: type '" + typeName + "' already exists.");

            } // end of 'handle attributes'

            // parse list of basis blades and optional comment
            List<G25.rsbbp.BasisBlade> L = ParseBasisBladeList(S, E.FirstChild, typeName);
            string comment = ParseComment(S, E.FirstChild);

            if (L == null)
                throw new G25.UserException("XML parsing error in element '" + XML_SMV + "': Missing basis blade list for specialized multivector '" + typeName + "'");

            SMV smv = new SMV(typeName, L.ToArray(), mvType, comment);

            // add new type to list of specialized multivectors
            S.AddSpecializedMV(smv);

            // if constant name is specified, the user wants a constant:
            if (constantName != null)
                S.AddConstant(new ConstantSMV(constantName, smv, null, comment));
        }