} // end of WriteLargestCoordinateFunctions() /// <summary> /// Writes getters and setters for the SMV coordinates.. /// </summary> /// <param name="SB">Where the code goes.</param> /// <param name="S">Used for basis vector names and output language.</param> /// <param name="cgd">Not used yet.</param> /// <param name="FT">Float point type of 'SMV'.</param> /// <param name="smv">The specialized multivector for which the struct should be written.</param> public static void WriteGetSetCoord(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SMV smv) { int nbTabs = 1; string className = FT.GetMangledName(S, smv.Name); // for variable coordinates: for (int i = 0; i < smv.NbNonConstBasisBlade; i++) { RefGA.BasisBlade B = smv.NonConstBasisBlade(i); string name = smv.NonConstBasisBlade(i).ToLangString(S.m_basisVectorNames); string accessName = G25.CG.Shared.SmvUtil.GetCoordAccessString(S, smv, i); // get string getComment = "Returns the " + B.ToString(S.m_basisVectorNames) + " coordinate."; new G25.CG.Shared.Comment(getComment).Write(SB, S, nbTabs); SB.AppendLine("\t" + Keywords.PublicAccessModifier(S) + " " + FT.type + " " + G25.CG.Shared.Main.GETTER_PREFIX + name + "() { return " + accessName + ";}"); // set string setComment = "Sets the " + B.ToString(S.m_basisVectorNames) + " coordinate."; new G25.CG.Shared.Comment(setComment).Write(SB, S, nbTabs); SB.AppendLine("\t" + Keywords.PublicAccessModifier(S) + " void " + G25.CG.Shared.Main.SETTER_PREFIX + name + "(" + FT.type + " " + name + ") { " + accessName + " = " + name + ";}"); } // for constant coordinates: for (int i = 0; i < smv.NbConstBasisBlade; i++) { RefGA.BasisBlade B = smv.ConstBasisBlade(i); // get string getComment = "Returns the " + B.ToString(S.m_basisVectorNames) + " coordinate."; new G25.CG.Shared.Comment(getComment).Write(SB, S, nbTabs); SB.AppendLine("\t" + Keywords.PublicAccessModifier(S) + " " + FT.type + " " + G25.CG.Shared.Main.GETTER_PREFIX + B.ToLangString(S.m_basisVectorNames) + "() { return " + FT.DoubleToString(S, smv.ConstBasisBladeValue(i)) + ";}"); } // write a getter for the scalar which returns 0 if no scalar coordinate is present if (smv.GetElementIdx(RefGA.BasisBlade.ONE) < 0) { RefGA.BasisBlade B = RefGA.BasisBlade.ONE; string getComment = "Returns the scalar coordinate (which is always 0)."; new G25.CG.Shared.Comment(getComment).Write(SB, S, nbTabs); SB.AppendLine("\t" + Keywords.PublicAccessModifier(S) + " " + FT.type + " " + G25.CG.Shared.Main.GETTER_PREFIX + B.ToLangString(S.m_basisVectorNames) + "() { return " + FT.DoubleToString(S, 0.0) + ";}"); } // getter for the coordinates (stored in array) if ((S.m_coordStorage == COORD_STORAGE.ARRAY) && (smv.NbNonConstBasisBlade > 0)) { string constantName = G25.CG.Shared.SmvUtil.GetCoordinateOrderConstant(S, smv); string COORD_ORDER = "coordOrder"; new G25.CG.Shared.Comment("Returns array of coordinates."). SetParamComment(COORD_ORDER, "pass the value '" + className + "." + constantName + "'"). Write(SB, S, nbTabs); SB.AppendLine("\t" + Keywords.PublicAccessModifier(S) + " " + FT.type + "[] c(" + G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM + " " + COORD_ORDER + ") { return m_c;}"); } }
/// <summary> /// Writes getters and setters for the SMV coordinates.. /// </summary> /// <param name="SB">Where the code goes.</param> /// <param name="S">Used for basis vector names and output language.</param> /// <param name="cgd">Not used yet.</param> /// <param name="FT">Float point type of 'SMV'.</param> /// <param name="smv">The specialized multivector for which the struct should be written.</param> public static void WriteGetSetCoord(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SMV smv) { // write variable coordinates for (int i = 0; i < smv.NbNonConstBasisBlade; i++) { string name = smv.NonConstBasisBlade(i).ToLangString(S.m_basisVectorNames); string accessName = G25.CG.Shared.SmvUtil.GetCoordAccessString(S, smv, i); SB.AppendLine("\t/// Returns the " + smv.NonConstBasisBlade(i).ToString(S.m_basisVectorNames) + " coordinate."); SB.AppendLine("\tinline " + FT.type + " " + MainGenerator.GETTER_PREFIX + name + "() const { return " + accessName + ";}"); SB.AppendLine("\t/// Sets the " + smv.NonConstBasisBlade(i).ToString(S.m_basisVectorNames) + " coordinate."); SB.AppendLine("\tinline void " + MainGenerator.SETTER_PREFIX + name + "(" + FT.type + " " + name + ") { " + accessName + " = " + name + ";}"); } // write constant coordinates for (int i = 0; i < smv.NbConstBasisBlade; i++) { RefGA.BasisBlade B = smv.ConstBasisBlade(i); SB.AppendLine("\t/// Returns the " + B.ToString(S.m_basisVectorNames) + " coordinate."); SB.AppendLine("\tinline " + FT.type + " " + MainGenerator.GETTER_PREFIX + B.ToLangString(S.m_basisVectorNames) + "() const { return " + FT.DoubleToString(S, smv.ConstBasisBladeValue(i)) + ";}"); } // write a getter for the scalar which returns 0 if no scalar coordinate is present if (smv.GetElementIdx(RefGA.BasisBlade.ONE) < 0) { RefGA.BasisBlade B = RefGA.BasisBlade.ONE; SB.AppendLine("\t/// Returns the scalar coordinate (which is always 0)."); SB.AppendLine("\tinline " + FT.type + " " + MainGenerator.GETTER_PREFIX + B.ToLangString(S.m_basisVectorNames) + "() const { return " + FT.DoubleToString(S, 0.0) + ";}"); } // getter for the coordinates (stored in array) if ((S.m_coordStorage == COORD_STORAGE.ARRAY) && (smv.NbNonConstBasisBlade > 0)) { SB.AppendLine("\t/// Returns array of coordinates."); SB.AppendLine("\tinline const " + FT.type + " *getC(" + G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM + ") const { return m_c;}"); } }
} // end of ComputeReturnTypeExpSmv() /// <summary> /// Emits a returnType sincosexp(inputType) function. /// </summary> /// <param name="FT"></param> /// <param name="CF"></param> protected void WriteFunction(FloatType FT, G25.fgs CF) { // get template name string templateName = "not set"; if (IsCos(m_fgs)) { templateName = "seriesCos"; } else if (IsSin(m_fgs)) { templateName = "seriesSin"; } else if (IsCosh(m_fgs)) { templateName = "seriesCosh"; } else if (IsSinh(m_fgs)) { templateName = "seriesSinh"; } else if (IsExp(m_fgs)) { templateName = "seriesExp"; } // library functions over scalars: string sqrtFunc = CodeUtil.OpNameToLangString(m_specification, FT, "sqrt"); string cosFunc = CodeUtil.OpNameToLangString(m_specification, FT, "cos"); string sinFunc = CodeUtil.OpNameToLangString(m_specification, FT, "sin"); string coshFunc = CodeUtil.OpNameToLangString(m_specification, FT, "cosh"); string sinhFunc = CodeUtil.OpNameToLangString(m_specification, FT, "sinh"); // get arguments setup: System.Collections.Hashtable args = new System.Collections.Hashtable(); args["S"] = m_specification; args["FT"] = FT; args["funcName"] = CF.OutputName; args["inputType"] = FT.GetMangledName(m_specification, m_inputTypeName); args["returnType"] = FT.GetMangledName(m_specification, m_returnTypeName); args["gpFuncII"] = m_gpFuncII[FT.type]; args["gpFuncRI"] = m_gpFuncRI[FT.type]; args["gpFuncRR"] = m_gpFuncRR[FT.type]; args["gpFuncIdouble"] = m_gpFuncIdouble[FT.type]; args["gpFuncRdouble"] = m_gpFuncRdouble[FT.type]; args["addFuncRR"] = m_addFuncRR[FT.type]; args["subFuncRR"] = m_subFuncRR[FT.type]; args["normE2funcR"] = m_normE2funcR[FT.type]; args["SASfuncI"] = m_SASfuncI[FT.type]; args["sqrtFunc"] = sqrtFunc; args["cosFunc"] = cosFunc; args["sinFunc"] = sinFunc; args["coshFunc"] = coshFunc; args["sinhFunc"] = sinhFunc; args["mathFuncName"] = m_fgs.Name; if (IsSin(m_fgs) || IsSinh(m_fgs)) // the 'sin' series needs to copy from inputtype to output type { args["copyInputToReturnFunc"] = m_copyInputTypeToReturnType[FT.type]; } // how to access the scalar coordinate of the return type: if (m_gmv.GetName() == m_returnType.GetName()) { string emp = (m_specification.OutputC()) ? "&" : ""; args["scalarTmp1"] = FT.GetMangledName(m_specification, m_returnTypeName) + "_scalar(" + emp + "tmp1)"; } else { // return type is SMV: get access strings for all coordinates, and use the one for the scalar string varName = "tmp1"; bool ptr = false; G25.SMV smv = m_returnType as G25.SMV; string[] accessStr = G25.CG.Shared.CodeUtil.GetAccessStr(m_specification, smv, varName, ptr); args["scalarTmp1"] = accessStr[smv.GetElementIdx(RefGA.BasisBlade.ONE)]; } args["userComment"] = m_fgs.Comment; m_cgd.m_cog.EmitTemplate(m_cgd.m_defSB, templateName, args); if (m_specification.OutputCppOrC()) { m_cgd.m_cog.EmitTemplate(m_cgd.m_declSB, "seriesDecl", args); } m_funcName[FT.type] = CF.OutputName; }