/* Copyright (C) 2012 - Juan Ferrer Toribio This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #ifndef DB_CALC_H #define DB_CALC_H #include #include #include "db-model.h" #define DB_CALC_LOG_DOMAIN (g_quark_from_string ("DbCalc")) #define DB_TYPE_CALC (db_calc_get_type ()) #define DB_CALC(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, DB_TYPE_CALC, DbCalc)) #define DB_IS_CALC(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, DB_TYPE_CALC)) #define DB_CALC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((obj), DB_TYPE_CALC, DbCalcClass)) #define DB_IS_CALC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DB_TYPE_CLASS)) #define DB_CALC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DB_TYPE_CALC, DbCalcClass)) typedef struct _DbCalc DbCalc; typedef struct _DbCalcClass DbCalcClass; /** * DbCalcFunc: * @obj: a #DbCalc * @iter: a #DbIter pointing to a row of the model * @out: the return position for the resulting value * @user_data: (closure): the data passed to the function * * The prototype of the functions used by the #DbCalc to perform operations * on more than one column or to perform additional operations to a column, * previously to add them to the calculations performed by the @DbCalc itself. **/ typedef void (*DbCalcFunc) (DbCalc * obj, DbIter * iter, GValue * out, gpointer user_data); /** * DbCalcOperationType: * @DB_CALC_SUM: sumatory of the values * @DB_CALC_AVG: average of the values * * Defines which type of operation will be performed over the column values. **/ typedef enum { DB_CALC_SUM, DB_CALC_AVG } DbCalcOperationType; struct _DbCalc { GvnParam parent; DbModel * model; DbCalcOperationType type; DbCalcFunc func; gpointer data; guint col; guint count; }; struct _DbCalcClass { /* */ GvnParamClass klass; }; GType db_calc_get_type (); DbCalc * db_calc_new (DbModel * model ,DbCalcOperationType type ,gint col); DbCalc * db_calc_new_with_func (DbModel * model ,DbCalcOperationType type ,DbCalcFunc func ,gpointer data); #endif