Beispiel #1
0
        /// <summary>
        /// Converts a G25.fgs to an XML string representation.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="F"></param>
        /// <returns>XML string representation of 'F'.</returns>
        public static string FunctionToXmlString(Specification S, G25.fgs F)
        {
            StringBuilder SB = new StringBuilder();
            SB.Append("<" + XML_FUNCTION);

            // name
            SB.Append(" " + XML_NAME + "=\"" + F.Name + "\"");

            // output name, if different
            if (F.Name != F.OutputName)
                SB.Append(" " + XML_OUTPUT_NAME + "=\"" + F.OutputName + "\"");

            // return type, if set
            if (F.ReturnTypeName.Length > 0)
                SB.Append(" " + XML_RETURN_TYPE + "=\"" + F.ReturnTypeName + "\"");

            // argument types, names
            for (int a = 0; a < F.NbArguments; a++)
            {
                string argTypeName = F.ArgumentTypeNames[a];

                if (argTypeName.EndsWith(Specification.CONSTANT_TYPE_SUFFIX)) // check if it is a constant
                {
                    G25.SMV smv = S.GetType(argTypeName) as G25.SMV;
                    if ((smv != null) && smv.IsConstant())
                    { // if constant, remove the "_t" from the typename
                        argTypeName = argTypeName.Substring(0, argTypeName.Length - Specification.CONSTANT_TYPE_SUFFIX.Length);
                    }
                }

                SB.Append(" " + XML_ARG + (a + 1).ToString() + "=\"" + F.ArgumentTypeNames[a] + "\"");
                if (F.ArgumentVariableNames[a] != fgs.DefaultArgumentName(a))
                    SB.Append(" " + XML_ARGNAME + (a + 1).ToString() + "=\"" + F.ArgumentVariableNames[a] + "\"");
            }

            // options
            {
                foreach (KeyValuePair<String, String> KVP in F.Options)
                {
                    SB.Append(" " + XML_OPTION + KVP.Key + "=\"" + KVP.Value + "\"");
                }
            }

            // float names, if not all float names of algebra are used:
            if (!F.UsesAllFloatTypes(S.m_floatTypes))
            {
                for (int f = 0; f < F.NbFloatNames; f++)
                {
                    SB.Append(" " + XML_FLOAT_TYPE + "=\"" + F.FloatNames[f] + "\"");
                }
            }

            // metric name, if not default
            if (F.MetricName != "default")
                SB.Append(" " + XML_METRIC + "=\"" + F.MetricName + "\"");

            // metric name, if not default
            if (F.Comment.Length > 0)
                SB.Append(" " + XML_COMMENT + "=\"" + F.Comment + "\"");

            SB.Append("/>");

            return SB.ToString();
        }
Beispiel #2
0
        /// <summary>
        /// Parses an XML_CONSTANT element and stores the result.
        /// 
        /// The XML_CONSTANT element should contain the name, type and basis blades values.
        /// </summary>
        /// <param name="E">XML_CONSTANT element</param>
        private static void ParseConstantElementAndAttributes(Specification S, XmlElement E)
        {
            string constantName = null;
            string typeName = null;

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

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

                    // type
                    else if (A[i].Name == XML_TYPE)
                        typeName = A[i].Value;
                }

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

                // check if name is already present
                if (!S.IsSpecializedMultivectorName(typeName))
                    throw new G25.UserException("In constant definition: type '" + typeName + "' is not a specialized multivector.");

            } // end of 'handle attributes'

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

            SMV type = S.GetType(typeName) as SMV;

            // add new type to list of specialized multivectors (constuctor should check if all are constant
            S.AddConstant(new ConstantSMV(constantName, type, L, comment));
        }