コード例 #1
0
ファイル: executor.c プロジェクト: Rela-X/rlang
static
Value *
_pow(const Ast *expr) {
	Ast *op1 = expr->child;
	Ast *op2 = expr->child->next;

	Value *v1 = eval(op1);
	Value *v2 = eval(op2);
	Value *rval = v1;

	switch(expr->eval_type) {
	case T_INT:
		value_set_int(rval, pow(NATIVE_NUMBER(v1),  NATIVE_NUMBER(v2)));
		break;
	case T_FLOAT:
		value_set_float(rval, powf(NATIVE_NUMBER(v1),  NATIVE_NUMBER(v2)));
		break;
	default:
		pty(expr->eval_type);
		assert(false);
	}
	value_free(v2);

	return rval;
}
コード例 #2
0
ファイル: executor.c プロジェクト: Rela-X/rlang
static
Value *
_add(const Ast *expr) {
	Ast *op1 = expr->child;
	Ast *op2 = expr->child->next;

	Value *v1 = eval(op1);
	Value *v2 = eval(op2);
	Value *rval = v1;

	switch(expr->eval_type) {
	case T_INT:
		value_set_int(rval, NATIVE_NUMBER(v1) + NATIVE_NUMBER(v2));
		break;
	case T_FLOAT:
		value_set_float(rval, NATIVE_NUMBER(v1) + NATIVE_NUMBER(v2));
		break;
	case T_STRING:
		// TODO String concat?
	default:
		pty(expr->eval_type);
		assert(false);
	}
	value_free(v2);

	return rval;
}
コード例 #3
0
ファイル: executor.c プロジェクト: Rela-X/rlang
static
Value *
_int(const Ast *expr) {
	Value *rval = value_new();
	value_set_int(rval, atoi(expr->value));

	return rval;
}
コード例 #4
0
ファイル: executor.c プロジェクト: Rela-X/rlang
static
Value *
_neg(const Ast *expr) {
	Ast *op1 = expr->child;

	Value *rval = eval(op1);

	switch(rval->type) {
	case T_INT:
		value_set_int(rval, -1 * rval->as_int);
		break;
	case T_FLOAT:
		value_set_float(rval, -1 * rval->as_float);
		break;
	}

	return rval;
}
コード例 #5
0
ファイル: executor.c プロジェクト: Rela-X/rlang
static
Value *
_mod(const Ast *expr) {
	Ast *op1 = expr->child;
	Ast *op2 = expr->child->next;

	Value *v1 = eval(op1);
	Value *v2 = eval(op2);
	Value *rval = v1;

	switch(expr->eval_type) {
	case T_INT:
		value_set_int(rval, v1->as_int % v2->as_int);
		break;
	default:
		pty(expr->eval_type);
		assert(false);
	}
	value_free(v2);

	return rval;
}
コード例 #6
0
ファイル: virtualbbox.c プロジェクト: gfbipnet/amigoclient
static void
vbbox_read_row (VirtualBBoxCursorPtr cursor)
{
    /* trying to read a row from the BoundingBox real-table */
    struct splite_internal_cache *cache =
        (struct splite_internal_cache *) cursor->pVtab->p_cache;
    sqlite3_stmt *stmt;
    int ret;
    int ic;
    int icx;
    const char *text;
    const unsigned char *blob;
    int size;
    sqlite3_int64 pk;
    double minx;
    double miny;
    double maxx;
    double maxy;
    int srid;
    char ok_minx = 'N';
    char ok_miny = 'N';
    char ok_maxx = 'N';
    char ok_maxy = 'N';
    char ok_srid = 'N';
    stmt = cursor->stmt;
    sqlite3_bind_int64 (stmt, 1, cursor->current_row);
    ret = sqlite3_step (stmt);
    if (ret == SQLITE_ROW)
    {
        pk = sqlite3_column_int64 (stmt, 0);
        if (sqlite3_column_type (stmt, 1) == SQLITE_FLOAT)
        {
            minx = sqlite3_column_double (stmt, 1);
            ok_minx = 'Y';
        }
        if (sqlite3_column_type (stmt, 2) == SQLITE_FLOAT)
        {
            miny = sqlite3_column_double (stmt, 2);
            ok_miny = 'Y';
        }
        if (sqlite3_column_type (stmt, 3) == SQLITE_FLOAT)
        {
            maxx = sqlite3_column_double (stmt, 3);
            ok_maxx = 'Y';
        }
        if (sqlite3_column_type (stmt, 4) == SQLITE_FLOAT)
        {
            maxy = sqlite3_column_double (stmt, 4);
            ok_maxy = 'Y';
        }
        if (sqlite3_column_type (stmt, 5) == SQLITE_INTEGER)
        {
            srid = sqlite3_column_int (stmt, 5);
            ok_srid = 'Y';
        }
        if (cursor->pVtab->BBoxGeom)
            gaiaFreeGeomColl (cursor->pVtab->BBoxGeom);
        cursor->pVtab->BBoxGeom = NULL;
        if (ok_minx == 'Y' && ok_miny == 'Y' && ok_maxx == 'Y'
                && ok_maxy == 'Y')
        {
            gaiaGeomCollPtr geom = gaiaAllocGeomColl ();
            gaiaPolygonPtr pg = gaiaAddPolygonToGeomColl (geom, 5, 0);
            gaiaRingPtr rng = pg->Exterior;
            gaiaSetPoint (rng->Coords, 0, minx, miny);
            gaiaSetPoint (rng->Coords, 1, maxx, miny);
            gaiaSetPoint (rng->Coords, 2, maxx, maxy);
            gaiaSetPoint (rng->Coords, 3, minx, maxy);
            gaiaSetPoint (rng->Coords, 4, minx, miny);
            if (ok_srid == 'Y')
            {
                if (cursor->pVtab->ForceWGS84)
                {
                    /* converting to WGS84 long-lat */
                    gaiaGeomCollPtr geom2 = NULL;
                    char *proj_from = NULL;
                    char *proj_to = NULL;
                    geom->Srid = srid;
                    getProjParams (cursor->pVtab->db, srid, &proj_from);
                    getProjParams (cursor->pVtab->db, 4326, &proj_to);
                    if (proj_to == NULL || proj_from == NULL)
                        geom2 = NULL;
                    else
#ifndef OMIT_PROJ		/* including PROJ.4 */
                        if (cache != NULL)
                            geom2 =
                                gaiaTransform_r (cache, geom, proj_from,
                                                 proj_to);
                        else
                            geom2 =
                                gaiaTransform (geom, proj_from, proj_to);
#endif /* end including PROJ.4 */
                    geom2 = NULL;
                    if (geom2 != NULL)
                        geom2->Srid = 4326;
                    cursor->pVtab->BBoxGeom = geom2;
                    gaiaFreeGeomColl (geom);
                    if (proj_from)
                        free (proj_from);
                    if (proj_to)
                        free (proj_to);
                }
                else
                {
                    geom->Srid = srid;
                    cursor->pVtab->BBoxGeom = geom;
                }
            }
            else
            {
                geom->Srid = cursor->pVtab->Srid;
                cursor->pVtab->BBoxGeom = geom;
            }
        }
        icx = 5;
        for (ic = 0; ic < cursor->pVtab->nColumns; ic++)
        {
            if (*(cursor->pVtab->Visible + ic) != 'Y')
                continue;
            icx++;
            switch (sqlite3_column_type (stmt, icx))
            {
            case SQLITE_INTEGER:
                value_set_int (*(cursor->pVtab->Value + ic),
                               sqlite3_column_int64 (stmt, icx));
                break;
            case SQLITE_FLOAT:
                value_set_double (*(cursor->pVtab->Value + ic),
                                  sqlite3_column_double (stmt, icx));
                break;
            case SQLITE_TEXT:
                text = (char *) sqlite3_column_text (stmt, icx);
                size = sqlite3_column_bytes (stmt, icx);
                value_set_text (*(cursor->pVtab->Value + ic), text, size);
                break;
            case SQLITE_BLOB:
                blob = sqlite3_column_blob (stmt, icx);
                size = sqlite3_column_bytes (stmt, icx);
                value_set_blob (*(cursor->pVtab->Value + ic), blob, size);
                break;
            case SQLITE_NULL:
            default:
                value_set_null (*(cursor->pVtab->Value + ic));
                break;
            };
        }
    }
    else
    {
        /* an error occurred */
        cursor->eof = 1;
        return;
    }
    cursor->eof = 0;
    cursor->current_row = pk;
}