Beispiel #1
0
        } // end of WriteLargestCoordinateFunctions()

        /// <summary>
        /// Writes code to extract the scalar part of an SMV via a non-member function.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd">Results go here. Also intermediate data for code generation. Also contains plugins and cog.</param>
        public static void WriteExtractScalarPart(Specification S, G25.CG.Shared.CGdata cgd)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder declSB = cgd.m_declSB;
            StringBuilder defSB  = (S.m_inlineFunctions) ? cgd.m_inlineDefSB : cgd.m_defSB;

            declSB.AppendLine("");
            defSB.AppendLine("");

            const string gmvName = "x";

            RefGA.BasisBlade scalarBlade = RefGA.BasisBlade.ONE;
            string           inlineStr   = G25.CG.Shared.Util.GetInlineString(S, S.m_inlineFunctions, " ");

            foreach (G25.FloatType FT in S.m_floatTypes)
            {
                string className   = FT.GetMangledName(S, gmv.Name);
                string funcName    = "_" + FT.type;
                string altFuncName = "_Float";
                string comment     = "/// Returns scalar part of  " + className;

                declSB.AppendLine(comment);
                string funcDecl = FT.type + " " + funcName + "(const " + className + " &" + gmvName + ")";
                declSB.Append(funcDecl);
                declSB.AppendLine(";");

                declSB.AppendLine(comment);
                string altFuncDecl = FT.type + " " + altFuncName + "(const " + className + " &" + gmvName + ")";
                declSB.Append(G25.CG.Shared.Util.GetInlineString(S, true, " ") + altFuncDecl + " {return " + funcName + "(" + gmvName + "); }");
                declSB.AppendLine(";");

                defSB.Append(inlineStr + funcDecl);
                {
                    defSB.AppendLine(" {");

                    int    elementIdx = gmv.GetElementIdx(scalarBlade);
                    double multiplier = 1.0 / gmv.BasisBlade(0, elementIdx).scale;

                    string multiplerString = (multiplier != 1.0) ? (FT.DoubleToString(S, multiplier) + " * ") : "";

                    // this line assumes that the scalar is the first element of the first group (which is a requirement).
                    defSB.AppendLine("\treturn ((x.gu() & 1) != 0) ? " + multiplerString + "x.getC()[0] : " + FT.DoubleToString(S, 0.0) + ";");

                    defSB.AppendLine("}");
                }
            } // end of loop over all float types
        }     // end of WriteExtractScalarPart()