mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add int32 predicate type
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8633 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
5d919e431b
commit
c8b10ef11c
@ -84,6 +84,9 @@ typedef GList * (*query_glist_getter) (gpointer);
|
|||||||
typedef const GUID * (*query_guid_getter) (gpointer);
|
typedef const GUID * (*query_guid_getter) (gpointer);
|
||||||
static const char * query_guid_type = QUERYCORE_GUID;
|
static const char * query_guid_type = QUERYCORE_GUID;
|
||||||
|
|
||||||
|
typedef gint32 (*query_int32_getter) (gpointer);
|
||||||
|
static const char * query_int32_type = QUERYCORE_INT32;
|
||||||
|
|
||||||
typedef gint64 (*query_int64_getter) (gpointer);
|
typedef gint64 (*query_int64_getter) (gpointer);
|
||||||
static const char * query_int64_type = QUERYCORE_INT64;
|
static const char * query_int64_type = QUERYCORE_INT64;
|
||||||
|
|
||||||
@ -646,6 +649,91 @@ QueryPredData_t gncQueryGUIDPredicate (guid_match_t options, GList *guids)
|
|||||||
return ((QueryPredData_t)pdata);
|
return ((QueryPredData_t)pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================================ */
|
||||||
|
/* QUERYCORE_INT32 */
|
||||||
|
|
||||||
|
static int int32_match_predicate (gpointer object, QueryAccess get_fcn,
|
||||||
|
QueryPredData_t pd)
|
||||||
|
{
|
||||||
|
gint32 val;
|
||||||
|
query_int32_t pdata = (query_int32_t)pd;
|
||||||
|
|
||||||
|
VERIFY_PREDICATE (query_int32_type);
|
||||||
|
|
||||||
|
val = ((query_int32_getter)get_fcn) (object);
|
||||||
|
|
||||||
|
switch (pd->how) {
|
||||||
|
case COMPARE_LT:
|
||||||
|
return (val < pdata->val);
|
||||||
|
case COMPARE_LTE:
|
||||||
|
return (val <= pdata->val);
|
||||||
|
case COMPARE_EQUAL:
|
||||||
|
return (val == pdata->val);
|
||||||
|
case COMPARE_GT:
|
||||||
|
return (val > pdata->val);
|
||||||
|
case COMPARE_GTE:
|
||||||
|
return (val >= pdata->val);
|
||||||
|
case COMPARE_NEQ:
|
||||||
|
return (val != pdata->val);
|
||||||
|
default:
|
||||||
|
PWARN ("bad match type: %d", pd->how);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int int32_compare_func (gpointer a, gpointer b, gint options,
|
||||||
|
QueryAccess get_fcn)
|
||||||
|
{
|
||||||
|
gint32 v1, v2;
|
||||||
|
g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
|
||||||
|
|
||||||
|
v1 = ((query_int32_getter)get_fcn)(a);
|
||||||
|
v2 = ((query_int32_getter)get_fcn)(b);
|
||||||
|
|
||||||
|
if (v1 < v2) return -1;
|
||||||
|
if (v1 > v2) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int32_free_pdata (QueryPredData_t pd)
|
||||||
|
{
|
||||||
|
query_int32_t pdata = (query_int32_t)pd;
|
||||||
|
VERIFY_PDATA (query_int32_type);
|
||||||
|
g_free (pdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
static QueryPredData_t int32_copy_predicate (QueryPredData_t pd)
|
||||||
|
{
|
||||||
|
query_int32_t pdata = (query_int32_t)pd;
|
||||||
|
VERIFY_PDATA_R (query_int32_type);
|
||||||
|
return gncQueryInt32Predicate (pd->how, pdata->val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean int32_predicate_equal (QueryPredData_t p1, QueryPredData_t p2)
|
||||||
|
{
|
||||||
|
query_int32_t pd1 = (query_int32_t) p1;
|
||||||
|
query_int32_t pd2 = (query_int32_t) p2;
|
||||||
|
|
||||||
|
return (pd1->val == pd2->val);
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryPredData_t gncQueryInt32Predicate (query_compare_t how, gint32 val)
|
||||||
|
{
|
||||||
|
query_int32_t pdata = g_new0 (query_int32_def, 1);
|
||||||
|
pdata->pd.type_name = query_int32_type;
|
||||||
|
pdata->pd.how = how;
|
||||||
|
pdata->val = val;
|
||||||
|
return ((QueryPredData_t)pdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char * int32_to_string (gpointer object, QueryAccess get)
|
||||||
|
{
|
||||||
|
gint32 num = ((query_int32_getter)get)(object);
|
||||||
|
|
||||||
|
return g_strdup_printf ("%ld", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================================ */
|
||||||
/* QUERYCORE_INT64 */
|
/* QUERYCORE_INT64 */
|
||||||
|
|
||||||
static int int64_match_predicate (gpointer object, QueryAccess get_fcn,
|
static int int64_match_predicate (gpointer object, QueryAccess get_fcn,
|
||||||
@ -729,6 +817,7 @@ static char * int64_to_string (gpointer object, QueryAccess get)
|
|||||||
return g_strdup_printf (GNC_SCANF_LLD, num);
|
return g_strdup_printf (GNC_SCANF_LLD, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================================ */
|
||||||
/* QUERYCORE_DOUBLE */
|
/* QUERYCORE_DOUBLE */
|
||||||
|
|
||||||
static int double_match_predicate (gpointer object, QueryAccess get_fcn,
|
static int double_match_predicate (gpointer object, QueryAccess get_fcn,
|
||||||
@ -1100,6 +1189,9 @@ static void init_tables (void)
|
|||||||
{ QUERYCORE_GUID, guid_match_predicate, NULL,
|
{ QUERYCORE_GUID, guid_match_predicate, NULL,
|
||||||
guid_copy_predicate, guid_free_pdata, NULL,
|
guid_copy_predicate, guid_free_pdata, NULL,
|
||||||
guid_predicate_equal },
|
guid_predicate_equal },
|
||||||
|
{ QUERYCORE_INT32, int32_match_predicate, int32_compare_func,
|
||||||
|
int32_copy_predicate, int32_free_pdata, int32_to_string,
|
||||||
|
int32_predicate_equal },
|
||||||
{ QUERYCORE_INT64, int64_match_predicate, int64_compare_func,
|
{ QUERYCORE_INT64, int64_match_predicate, int64_compare_func,
|
||||||
int64_copy_predicate, int64_free_pdata, int64_to_string,
|
int64_copy_predicate, int64_free_pdata, int64_to_string,
|
||||||
int64_predicate_equal },
|
int64_predicate_equal },
|
||||||
@ -1130,8 +1222,10 @@ static void init_tables (void)
|
|||||||
|
|
||||||
static QueryPredicateCopy gncQueryCoreGetCopy (char const *type)
|
static QueryPredicateCopy gncQueryCoreGetCopy (char const *type)
|
||||||
{
|
{
|
||||||
|
QueryPredicateCopy rc;
|
||||||
g_return_val_if_fail (type, NULL);
|
g_return_val_if_fail (type, NULL);
|
||||||
return g_hash_table_lookup (copyTable, type);
|
rc = g_hash_table_lookup (copyTable, type);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QueryPredDataFree gncQueryCoreGetPredFree (char const *type)
|
static QueryPredDataFree gncQueryCoreGetPredFree (char const *type)
|
||||||
|
@ -98,6 +98,7 @@ typedef enum {
|
|||||||
GUID_MATCH_LIST_ANY,
|
GUID_MATCH_LIST_ANY,
|
||||||
} guid_match_t;
|
} guid_match_t;
|
||||||
|
|
||||||
|
#define QUERYCORE_INT32 "gint32"
|
||||||
#define QUERYCORE_INT64 "gint64"
|
#define QUERYCORE_INT64 "gint64"
|
||||||
#define QUERYCORE_DOUBLE "double"
|
#define QUERYCORE_DOUBLE "double"
|
||||||
#define QUERYCORE_BOOLEAN "boolean"
|
#define QUERYCORE_BOOLEAN "boolean"
|
||||||
@ -126,6 +127,7 @@ QueryPredData_t gncQueryNumericPredicate (query_compare_t how,
|
|||||||
numeric_match_t options,
|
numeric_match_t options,
|
||||||
gnc_numeric value);
|
gnc_numeric value);
|
||||||
QueryPredData_t gncQueryGUIDPredicate (guid_match_t options, GList *guids);
|
QueryPredData_t gncQueryGUIDPredicate (guid_match_t options, GList *guids);
|
||||||
|
QueryPredData_t gncQueryInt32Predicate (query_compare_t how, gint32 val);
|
||||||
QueryPredData_t gncQueryInt64Predicate (query_compare_t how, gint64 val);
|
QueryPredData_t gncQueryInt64Predicate (query_compare_t how, gint64 val);
|
||||||
QueryPredData_t gncQueryDoublePredicate (query_compare_t how, double val);
|
QueryPredData_t gncQueryDoublePredicate (query_compare_t how, double val);
|
||||||
QueryPredData_t gncQueryBooleanPredicate (query_compare_t how, gboolean val);
|
QueryPredData_t gncQueryBooleanPredicate (query_compare_t how, gboolean val);
|
||||||
|
@ -97,6 +97,11 @@ typedef struct {
|
|||||||
GList * guids;
|
GList * guids;
|
||||||
} query_guid_def, *query_guid_t;
|
} query_guid_def, *query_guid_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
QueryPredDataDef pd;
|
||||||
|
gint32 val;
|
||||||
|
} query_int32_def, *query_int32_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
QueryPredDataDef pd;
|
QueryPredDataDef pd;
|
||||||
gint64 val;
|
gint64 val;
|
||||||
|
@ -185,8 +185,8 @@ static QueryNewTerm * copy_query_term (QueryNewTerm *qt)
|
|||||||
|
|
||||||
new_qt = g_new0 (QueryNewTerm, 1);
|
new_qt = g_new0 (QueryNewTerm, 1);
|
||||||
memcpy (new_qt, qt, sizeof(QueryNewTerm));
|
memcpy (new_qt, qt, sizeof(QueryNewTerm));
|
||||||
new_qt->param_list = g_slist_copy (new_qt->param_list);
|
new_qt->param_list = g_slist_copy (qt->param_list);
|
||||||
new_qt->param_fcns = g_slist_copy (new_qt->param_fcns);
|
new_qt->param_fcns = g_slist_copy (qt->param_fcns);
|
||||||
new_qt->pdata = gncQueryCorePredicateCopy (qt->pdata);
|
new_qt->pdata = gncQueryCorePredicateCopy (qt->pdata);
|
||||||
return new_qt;
|
return new_qt;
|
||||||
}
|
}
|
||||||
@ -607,7 +607,6 @@ void gncQueryAddTerm (QueryNew *q, GSList *param_list,
|
|||||||
qt = g_new0 (QueryNewTerm, 1);
|
qt = g_new0 (QueryNewTerm, 1);
|
||||||
qt->param_list = param_list;
|
qt->param_list = param_list;
|
||||||
qt->pdata = pred_data;
|
qt->pdata = pred_data;
|
||||||
|
|
||||||
qs = gncQueryCreate ();
|
qs = gncQueryCreate ();
|
||||||
query_init (qs, qt);
|
query_init (qs, qt);
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ typedef struct querynew_s QueryNew;
|
|||||||
|
|
||||||
/** Query Term Operators, for combining Query Terms */
|
/** Query Term Operators, for combining Query Terms */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
QUERY_FIRST_TERM=1, /* First/only term is same as 'and' */
|
||||||
QUERY_AND=1,
|
QUERY_AND=1,
|
||||||
QUERY_OR,
|
QUERY_OR,
|
||||||
QUERY_NAND,
|
QUERY_NAND,
|
||||||
|
Loading…
Reference in New Issue
Block a user