Example #1
0
void KreImporter::readRatings( const QDomNodeList& l, Recipe *recipe )
{
	for ( int i = 0; i < l.count(); i++ ) {
		QDomElement child = l.item( i ).toElement();
		if ( child.tagName() == "rating" ) {
			Rating r;

			QDomNodeList ratingChildren = child.childNodes();
			for ( int j = 0; j < ratingChildren.count(); j++ ) {
				QDomElement ratingChild = ratingChildren.item( j ).toElement();
				if ( ratingChild.tagName() == "comment" ) {
					r.setComment(ratingChild.text());
				}
				else if ( ratingChild.tagName() == "rater" ) {
					r.setRater(ratingChild.text());
				}
				else if ( ratingChild.tagName() == "criterion" ) {
					readCriterion(ratingChild.childNodes(),r);
				}
			}
			recipe->ratingList.append(r);
		}
	}
}
static int createNBodyCtx(lua_State* luaSt)
{
    static NBodyCtx ctx;
    static const char* criterionName = NULL;
    double nStepf = 0.0;

    static const MWNamedArg argTable[] =
        {
            { "timestep",    LUA_TNUMBER,  NULL, TRUE,  &ctx.timestep    },
            { "timeEvolve",  LUA_TNUMBER,  NULL, TRUE,  &ctx.timeEvolve  },
            { "theta",       LUA_TNUMBER,  NULL, FALSE, &ctx.theta       },
            { "eps2",        LUA_TNUMBER,  NULL, TRUE,  &ctx.eps2        },
            { "treeRSize",   LUA_TNUMBER,  NULL, FALSE, &ctx.treeRSize   },
            { "sunGCDist",   LUA_TNUMBER,  NULL, FALSE, &ctx.sunGCDist   },
            { "criterion",   LUA_TSTRING,  NULL, FALSE, &criterionName   },
            { "useQuad",     LUA_TBOOLEAN, NULL, FALSE, &ctx.useQuad     },
            { "allowIncest", LUA_TBOOLEAN, NULL, FALSE, &ctx.allowIncest },
            { "quietErrors", LUA_TBOOLEAN, NULL, FALSE, &ctx.quietErrors },
            END_MW_NAMED_ARG
        };

    criterionName = NULL;
    ctx = defaultNBodyCtx;

    if (lua_gettop(luaSt) != 1)
        return luaL_argerror(luaSt, 1, "Expected named argument table");

    handleNamedArgumentTable(luaSt, argTable, 1);

    /* FIXME: Hacky handling of enum. Will result in not good error
     * messages as well as not fitting in. */
    if (criterionName) /* Not required */
    {
        ctx.criterion = readCriterion(luaSt, criterionName);
    }

    if ((ctx.criterion != Exact) && (ctx.theta < 0.0))
    {
        return luaL_argerror(luaSt, 1, "Theta argument required for criterion != 'Exact'");
    }
    else if (ctx.criterion == Exact)
    {
        /* These don't mean anything here */
        ctx.theta = 0.0;
        ctx.useQuad = FALSE;
    }

    nStepf = mw_ceil(ctx.timeEvolve / ctx.timestep);
    if (nStepf >= (double) UINT_MAX)
    {
        luaL_error(luaSt,
                   "Number of timesteps exceeds UINT_MAX: %f timesteps (%f / %f)\n",
                   nStepf,
                   ctx.timeEvolve, ctx.timestep);
    }

    ctx.nStep = (unsigned int) nStepf;

    pushNBodyCtx(luaSt, &ctx);
    return 1;
}