/// <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(); }