コード例 #1
0
ファイル: xml.cs プロジェクト: Sciumo/gaigen
        /// <summary>
        /// Parses an XML_MV element and stores the result.
        /// 
        /// The XML_MV element should contain the name, compression method (by grade or by group), 
        /// coordinate order (default or custom) 
        /// and memory allocation method of the general multivector.
        /// </summary>
        /// <param name="E">XML_MV element</param>
        private static void ParseMVelementAndAttributes(Specification S, XmlElement E)
        {
            String name = "mv";
            bool compressByGrade = true; // false means 'by group'
            bool defaultCoordinateOrder = true; // false means 'custom'
            GMV.MEM_ALLOC_METHOD memAllocMethod = GMV.MEM_ALLOC_METHOD.FULL;

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

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

                    // compress method (grade or group
                    else if (A[i].Name == XML_COMPRESS)
                    {
                        if (A[i].Value == XML_BY_GRADE)
                            compressByGrade = true;
                        else if (A[i].Value == XML_BY_GROUP)
                            compressByGrade = false;
                        else throw new G25.UserException("XML parsing error: Invalid compression '" + A[i].Value + "' in element '" + XML_MV + "'.");
                    }

                    // coordinate order
                    else if (A[i].Name == XML_COORDINATE_ORDER)
                    {
                        if (A[i].Value == XML_DEFAULT)
                            defaultCoordinateOrder = true;
                        else if (A[i].Value == XML_CUSTOM)
                            defaultCoordinateOrder = false;
                        else throw new G25.UserException("XML parsing error: Invalid coordinate order '" + A[i].Value + "' in element '" + XML_MV + "'.");
                    }

                    // memory allocation method
                    else if (A[i].Name == XML_MEM_ALLOC)
                    {
                        if (A[i].Value == XML_PARITY_PURE)
                            memAllocMethod = GMV.MEM_ALLOC_METHOD.PARITY_PURE;
                        else if (A[i].Value == XML_FULL)
                            memAllocMethod = GMV.MEM_ALLOC_METHOD.FULL;
                        else if (A[i].Value == XML_DYNAMIC)
                            memAllocMethod = GMV.MEM_ALLOC_METHOD.DYNAMIC;
                        else throw new G25.UserException("XML parsing error: Invalid memory allocation method '" + A[i].Value + "' in element '" + XML_MV + "'.");
                    }
                }

            } // end of 'handle attributes'

            // check for sanity
            if ((compressByGrade == false) && (defaultCoordinateOrder == true))
            {
                throw new G25.UserException("Cannot compress by group without a custom coordinate order. Please specify a coordinate order in the '" + XML_MV + "' element.");
            }

            // basis blades go here
            List<List<G25.rsbbp.BasisBlade>> basisBlades = null;

            if (defaultCoordinateOrder)
            {
                // check for sanity
                if (E.FirstChild != null)
                    throw new G25.UserException("The coordinate order is set to default, but the multivector definition element '" + XML_MV + "' contains a custom coordinate order.");

                basisBlades = S.m_basisBladeParser.GetDefaultBasisBlades();
            }
            else
            {
                basisBlades = S.m_basisBladeParser.ParseMVbasisBlades(E);
                if (compressByGrade)
                    basisBlades = S.m_basisBladeParser.SortBasisBladeListByGrade(basisBlades);
            }

            if (rsbbp.ConstantsInList(basisBlades))
                throw new G25.UserException("Constant coordinate(s) were specified in the general multivector type (XML element '" + XML_MV + "')");

            S.SetGeneralMV(new GMV(name, rsbbp.ListToDoubleArray(basisBlades), memAllocMethod));
        }