[Gnucash-changes] Revert Linas' broken changes to qof.

Derek Atkins warlord at cvs.gnucash.org
Sun Apr 18 16:04:09 EDT 2004


Log Message:
-----------
Revert Linas' broken changes to qof.

	* src/engine/Transaction.c: fix a comment to better explain why
	  we have no-op functions for some parameters.
	* src/engine/qof*:  Revert Linas' patch from last night which
	  is broken is way too many ways to count.  First, the code didn't
	  compile.  Second it was calling functions that took one argument
	  with two due to broken casting.  Third, it had repurcusions in
	  other sections of the code that Linas needs to take into account.

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/engine:
        Transaction.c
        qofclass.h
        qofquery.c
        qofquerycore-p.h
        qofquerycore.c
        qofquerycore.h

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1802
retrieving revision 1.1803
diff -LChangeLog -LChangeLog -u -r1.1802 -r1.1803
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,13 @@
+2004-04-18  Derek Atkins  <derek at ihtfp.com>
+
+	* src/engine/Transaction.c: fix a comment to better explain why
+	  we have no-op functions for some parameters.
+	* src/engine/qof*:  Revert Linas' patch from last night which
+	  is broken is way too many ways to count.  First, the code didn't
+	  compile.  Second it was calling functions that took one argument
+	  with two due to broken casting.  Third, it had repurcusions in
+	  other sections of the code that Linas needs to take into account.
+
 2004-05-16  Derek Atkins  <derek at ihtfp.com>
 
 	* src/macros/autogen.sh: Add MORE warnings around gettext because
Index: qofquery.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofquery.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lsrc/engine/qofquery.c -Lsrc/engine/qofquery.c -u -r1.20 -r1.21
--- src/engine/qofquery.c
+++ src/engine/qofquery.c
@@ -72,9 +72,9 @@
    * convert types.
    */
   gboolean            use_default;
-  GSList *            param_fcns;     /* Chain of paramters to walk */
+  GSList *            param_fcns;
   QofSortFunc         obj_cmp;        /* In case you are comparing objects */
-  QofCompareFunc      comp_fcn;       /* When you are comparing core types */
+  QofCompareFunc      comp_fcn;        /* When you are comparing core types */
 };
 
 /* The QUERY structure */
@@ -280,9 +280,9 @@
 static int cmp_func (QofQuerySort *sort, QofSortFunc default_sort,
                      gconstpointer a, gconstpointer b)
 {
-  QofParam *param = NULL;
   GSList *node;
   gpointer conva, convb;
+  QofAccessFunc get_fcn = NULL;        /* to appease the compiler */
 
   g_return_val_if_fail (sort, 0);
 
@@ -304,7 +304,7 @@
   convb = (gpointer)b;
   for (node = sort->param_fcns; node; node = node->next) 
   {
-    param = node->data;
+    get_fcn = node->data;
 
     /* The last term is really the "parameter getter",
      * unless we're comparing objects ;) */
@@ -312,14 +312,13 @@
       break;
 
     /* Do the converstions */
-    conva = (param->param_getfcn) (conva, param);
-    convb = (param->param_getfcn) (convb, param);
+    conva = get_fcn (conva);
+    convb = get_fcn (convb);
   }
-
   /* And now return the (appropriate) compare */
   if (sort->comp_fcn)
   {
-    int rc = sort->comp_fcn (conva, convb, sort->options, param);
+    int rc = sort->comp_fcn (conva, convb, sort->options, get_fcn);
     return rc;
   }
 
@@ -382,21 +381,21 @@
       if (qt->param_fcns && qt->pred_fcn) 
       {
         GSList *node;
-        QofParam *param = NULL;
+        QofAccessFunc get_fcn;
         gpointer conv_obj = object;
 
         /* iterate through the conversions */
-        for (node = qt->param_fcns; node; node = node->next) 
-        {
-          param = node->data;
+        for (node = qt->param_fcns; node; node = node->next) {
+          get_fcn = node->data;
 
           /* The last term is the actual parameter getter */
-          if (!node->next) break;
+          if (!node->next)
+            break;
 
-          conv_obj = param->param_getfcn (conv_obj, param);
+          conv_obj = get_fcn (conv_obj);
         }
 
-        if (((qt->pred_fcn)(conv_obj, param, qt->pdata)) == qt->invert) 
+        if (((qt->pred_fcn)(conv_obj, get_fcn, qt->pdata)) == qt->invert) 
         {
           and_terms_ok = 0;
           break;
@@ -429,9 +428,8 @@
  *
  * returns NULL if the first parameter is bad (and final is unchanged).
  */
-static GSList * 
-compile_params (GSList *param_list, QofIdType start_obj, 
-                QofParam const **final)
+static GSList * compile_params (GSList *param_list, QofIdType start_obj,
+                                QofParam const **final)
 {
   const QofParam *objDef = NULL;
   GSList *fcns = NULL;
@@ -449,8 +447,8 @@
     /* If it doesn't exist, then we've reached the end */
     if (!objDef) break;
 
-    /* Save off this parameter */
-    fcns = g_slist_prepend (fcns, (gpointer) objDef);
+    /* Save off this function */
+    fcns = g_slist_prepend (fcns, objDef->param_getfcn);
 
     /* Save this off, just in case */
     *final = objDef;
Index: Transaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/Transaction.c,v
retrieving revision 1.303
retrieving revision 1.304
diff -Lsrc/engine/Transaction.c -Lsrc/engine/Transaction.c -u -r1.303 -r1.304
--- src/engine/Transaction.c
+++ src/engine/Transaction.c
@@ -3251,7 +3251,8 @@
     { SPLIT_TRANS, GNC_ID_TRANS, (QofAccessFunc)xaccSplitGetParent, NULL },
     { SPLIT_ACCOUNT, GNC_ID_ACCOUNT, (QofAccessFunc)xaccSplitGetAccount, NULL },
     { SPLIT_ACCOUNT_GUID, QOF_TYPE_GUID, split_account_guid_getter, NULL },
-/* XXX why are these no-ops ?? ahh, to register sort func only ?? */
+/*  these are no-ops to register the parameter names (for sorting) but
+    they return an allocated object which getters cannot do.  */
     { SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op, NULL },
     { SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op, NULL },
     { SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op, NULL },
Index: qofclass.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofclass.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lsrc/engine/qofclass.h -Lsrc/engine/qofclass.h -u -r1.2 -r1.3
--- src/engine/qofclass.h
+++ src/engine/qofclass.h
@@ -56,19 +56,14 @@
 /** Type of Paramters (String, Date, Numeric, GUID, etc.) */
 typedef const char * QofType;
 
-typedef struct _QofParam QofParam;
-
 /** The QofAccessFunc defines an arbitrary function pointer
  *  for access functions.  This is needed because C doesn't have
  *  templates, so we just cast a lot.  Real functions must be of
  *  the form:
  *
  * param_type getter_func (object_type *self);
- *
- * XXX document the additional two args, and how/why they are 
- * optional.
  */
-typedef gpointer (*QofAccessFunc)(gpointer object, QofParam *param);
+typedef gpointer (*QofAccessFunc)(gpointer);
 
 /** The QofSetterFunc defines an function pointer for parameter
  *  setters. Real functions must be of the form:
@@ -87,13 +82,13 @@
  *
  * Either the getter or the setter may be NULL.
  */
-struct _QofParam 
+typedef struct _QofParam 
 {
   const char       * param_name;
   QofType            param_type;
   QofAccessFunc      param_getfcn;
   QofSetterFunc      param_setfcn;
-};
+} QofParam;
 
 /** This function is the default sort function for a particular object type */
 typedef int (*QofSortFunc)(gpointer, gpointer);
Index: qofquerycore.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofquerycore.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lsrc/engine/qofquerycore.h -Lsrc/engine/qofquerycore.h -u -r1.10 -r1.11
--- src/engine/qofquerycore.h
+++ src/engine/qofquerycore.h
@@ -146,6 +146,7 @@
 /** Return a printable string for a core data object.  Caller needs
  *  to g_free() the returned string.
  */
-char * qof_query_core_to_string (QofType, gpointer object, QofParam *getter);
+char * qof_query_core_to_string (char const *type, gpointer object,
+			     QofAccessFunc fcn);
 
 #endif /* QOF_QUERYCORE_H */
Index: qofquerycore.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofquerycore.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lsrc/engine/qofquerycore.c -Lsrc/engine/qofquerycore.c -u -r1.11 -r1.12
--- src/engine/qofquerycore.c
+++ src/engine/qofquerycore.c
@@ -39,51 +39,69 @@
 /* A function to copy a query's predicate data */
 typedef QofQueryPredData *(*QueryPredicateCopyFunc) (QofQueryPredData *pdata);
 
-/* A function to take the object, apply the getter->param_getfcn, 
- * and return a printable string.  Note that this QofParam->getfnc
- * function should be returning a type equal to this core object type.
+/* A function to take the object, apply the get_fcn, and return
+ * a printable string.  Note that this QofAccessFunc function should
+ * be returning a type equal to this core object type.
  *
  * Note that this string MUST be freed by the caller.
  */
-typedef char * (*QueryToString) (gpointer object, QofParam *getter);
+typedef char * (*QueryToString) (gpointer object, QofAccessFunc get_fcn);
 
 /* A function to test for equality of predicate data */
 typedef gboolean (*QueryPredicateEqual) (QofQueryPredData *p1, 
                                          QofQueryPredData *p2);
 
-static QueryPredicateCopyFunc qof_query_copy_predicate (QofType type);
-static QueryPredDataFree qof_query_predicate_free (QofType type);
+/* This function registers a new Core Object with the QofQuery
+ * subsystem.  It maps the "core_name" object to the given
+ * query_predicate, predicate_copy, and predicate_data_free functions.
+ */
+static void qof_query_register_core_object (char const *type_name,
+                                 QofQueryPredicateFunc pred,
+                                 QofCompareFunc comp,
+                                 QueryPredicateCopyFunc copy,
+                                 QueryPredDataFree pd_free,
+                                 QueryToString to_string,
+                                 QueryPredicateEqual pred_equal);
+/* An example:
+ *
+ * qof_query_register_core_object (QOF_TYPE_STRING, string_match_predicate,
+ *                               string_compare_fcn, string_free_pdata,
+ *                               string_print_fcn, pred_equal_fcn);
+ */
+
+static QueryPredicateCopyFunc gncQueryCoreGetCopy (char const *type);
+static QueryPredDataFree gncQueryCoreGetPredFree (char const *type);
 
 /* Core Type Predicate helpers */
-typedef const char * (*query_string_getter) (gpointer, QofParam *);
+typedef const char * (*query_string_getter) (gpointer);
 static const char * query_string_type = QOF_TYPE_STRING;
 
-typedef Timespec (*query_date_getter) (gpointer, QofParam *);
+typedef Timespec (*query_date_getter) (gpointer);
 static const char * query_date_type = QOF_TYPE_DATE;
 
-typedef gnc_numeric (*query_numeric_getter) (gpointer, QofParam *);
+typedef gnc_numeric (*query_numeric_getter) (gpointer);
 static const char * query_numeric_type = QOF_TYPE_NUMERIC;
 
-typedef GList * (*query_glist_getter) (gpointer, QofParam *);
-typedef const GUID * (*query_guid_getter) (gpointer, QofParam *);
+typedef GList * (*query_glist_getter) (gpointer);
+typedef const GUID * (*query_guid_getter) (gpointer);
 static const char * query_guid_type = QOF_TYPE_GUID;
 
-typedef gint32 (*query_int32_getter) (gpointer, QofParam *);
+typedef gint32 (*query_int32_getter) (gpointer);
 static const char * query_int32_type = QOF_TYPE_INT32;
 
-typedef gint64 (*query_int64_getter) (gpointer, QofParam *);
+typedef gint64 (*query_int64_getter) (gpointer);
 static const char * query_int64_type = QOF_TYPE_INT64;
 
-typedef double (*query_double_getter) (gpointer, QofParam *);
+typedef double (*query_double_getter) (gpointer);
 static const char * query_double_type = QOF_TYPE_DOUBLE;
 
-typedef gboolean (*query_boolean_getter) (gpointer, QofParam *);
+typedef gboolean (*query_boolean_getter) (gpointer);
 static const char * query_boolean_type = QOF_TYPE_BOOLEAN;
 
-typedef char (*query_char_getter) (gpointer, QofParam *);
+typedef char (*query_char_getter) (gpointer);
 static const char * query_char_type = QOF_TYPE_CHAR;
 
-typedef KvpFrame * (*query_kvp_getter) (gpointer, QofParam *);
+typedef KvpFrame * (*query_kvp_getter) (gpointer);
 static const char * query_kvp_type = QOF_TYPE_KVP;
 
 /* Tables for predicate storage and lookup */
@@ -110,8 +128,7 @@
                                 NULL); \
 }
 #define VERIFY_PREDICATE(str) { \
-        g_return_val_if_fail (getter != NULL, PREDICATE_ERROR); \
-        g_return_val_if_fail (getter->param_getfcn != NULL, PREDICATE_ERROR); \
+        g_return_val_if_fail (get_fcn != NULL, PREDICATE_ERROR); \
         g_return_val_if_fail (pd != NULL, PREDICATE_ERROR); \
         g_return_val_if_fail (pd->type_name == str || \
                                 !safe_strcmp (str, pd->type_name), \
@@ -123,10 +140,8 @@
 
 /* QOF_TYPE_STRING */
 
-static int 
-string_match_predicate (gpointer object, 
-                        QofParam *getter,
-                        QofQueryPredData *pd)
+static int string_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                   QofQueryPredData *pd)
 {
   query_string_t pdata = (query_string_t) pd;
   const char *s;
@@ -134,7 +149,7 @@
 
   VERIFY_PREDICATE (query_string_type);
 
-  s = ((query_string_getter)getter->param_getfcn) (object, getter);
+  s = ((query_string_getter)get_fcn) (object);
 
   if (!s) s = "";
 
@@ -163,15 +178,14 @@
   }
 }
 
-static int 
-string_compare_func (gpointer a, gpointer b, gint options,
-                     QofParam *getter)
+static int string_compare_func (gpointer a, gpointer b, gint options,
+                                QofAccessFunc get_fcn)
 {
   const char *s1, *s2;
-  g_return_val_if_fail (a && b && getter &&getter->param_getfcn, COMPARE_ERROR);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
 
-  s1 = ((query_string_getter)getter->param_getfcn) (a, getter);
-  s2 = ((query_string_getter)getter->param_getfcn) (b, getter);
+  s1 = ((query_string_getter)get_fcn) (a);
+  s2 = ((query_string_getter)get_fcn) (b);
 
   if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
     return safe_strcasecmp (s1, s2);
@@ -179,8 +193,7 @@
   return safe_strcmp (s1, s2);
 }
 
-static void 
-string_free_pdata (QofQueryPredData *pd)
+static void string_free_pdata (QofQueryPredData *pd)
 {
   query_string_t pdata = (query_string_t) pd;
 
@@ -194,20 +207,18 @@
   g_free (pdata);
 }
 
-static QofQueryPredData *
-string_copy_predicate (QofQueryPredData *pd)
+static QofQueryPredData *string_copy_predicate (QofQueryPredData *pd)
 {
   query_string_t pdata = (query_string_t) pd;
 
   VERIFY_PDATA_R (query_string_type);
 
-  return qof_query_string_predicate (pd->how, pdata->matchstring, 
-                                     pdata->options,
-                                     pdata->is_regex);
+  return qof_query_string_predicate (pd->how, pdata->matchstring, pdata->options,
+                                  pdata->is_regex);
 }
 
-static gboolean 
-string_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
+static gboolean string_predicate_equal (QofQueryPredData *p1,
+QofQueryPredData *p2)
 {
   query_string_t pd1 = (query_string_t) p1;
   query_string_t pd2 = (query_string_t) p2;
@@ -217,10 +228,9 @@
   return (safe_strcmp (pd1->matchstring, pd2->matchstring) == 0);
 }
 
-QofQueryPredData *
-qof_query_string_predicate (QofQueryCompare how,
-                            char *str, QofStringMatch options,
-                            gboolean is_regex)
+QofQueryPredData *qof_query_string_predicate (QofQueryCompare how,
+                                         char *str, QofStringMatch options,
+                                         gboolean is_regex)
 {
   query_string_t pdata;
 
@@ -246,20 +256,17 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-string_to_string (gpointer object, QofParam *getter)
+static char * string_to_string (gpointer object, QofAccessFunc get)
 {
-  const char *res;
-  res = ((query_string_getter)getter->param_getfcn)(object, getter);
+  const char *res = ((query_string_getter)get)(object);
   if (res)
     return g_strdup (res);
   return NULL;
 }
 
-/* QOF_TYPE_DATE =================================================== */
+/* QOF_TYPE_DATE */
 
-static int 
-date_compare (Timespec ta, Timespec tb, QofDateMatch options)
+static int date_compare (Timespec ta, Timespec tb, QofDateMatch options)
 {
   if (options == QOF_DATE_MATCH_ROUNDED) {
     ta = timespecCanonicalDayTime (ta);
@@ -279,8 +286,7 @@
   return 0;
 }
 
-static int 
-date_match_predicate (gpointer object, QofParam *getter,
+static int date_match_predicate (gpointer object, QofAccessFunc get_fcn,
                                  QofQueryPredData *pd)
 {
   query_date_t pdata = (query_date_t)pd;
@@ -289,7 +295,7 @@
 
   VERIFY_PREDICATE (query_date_type);
 
-  objtime = ((query_date_getter)getter->param_getfcn) (object, getter);
+  objtime = ((query_date_getter)get_fcn) (object);
   compare = date_compare (objtime, pdata->date, pdata->options);
 
   switch (pd->how) {
@@ -311,21 +317,20 @@
   }
 }
 
-static int 
-date_compare_func (gpointer a, gpointer b, gint options, QofParam *getter)
+static int date_compare_func (gpointer a, gpointer b, gint options,
+                              QofAccessFunc get_fcn)
 {
   Timespec ta, tb;
 
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
 
-  ta = ((query_date_getter)getter->param_getfcn) (a, getter);
-  tb = ((query_date_getter)getter->param_getfcn) (b, getter);
+  ta = ((query_date_getter)get_fcn) (a);
+  tb = ((query_date_getter)get_fcn) (b);
 
   return date_compare (ta, tb, options);
 }
 
-static void 
-date_free_pdata (QofQueryPredData *pd)
+static void date_free_pdata (QofQueryPredData *pd)
 {
   query_date_t pdata = (query_date_t)pd;
 
@@ -344,8 +349,7 @@
   return qof_query_date_predicate (pd->how, pdata->options, pdata->date);
 }
 
-static gboolean 
-date_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
+static gboolean date_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
 {
   query_date_t pd1 = (query_date_t) p1;
   query_date_t pd2 = (query_date_t) p2;
@@ -356,7 +360,7 @@
 
 QofQueryPredData *
 qof_query_date_predicate (QofQueryCompare how,
-                          QofDateMatch options, Timespec date)
+                                       QofDateMatch options, Timespec date)
 {
   query_date_t pdata;
 
@@ -368,10 +372,9 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-date_to_string (gpointer object, QofParam *getter)
+static char * date_to_string (gpointer object, QofAccessFunc get)
 {
-  Timespec ts = ((query_date_getter)getter->param_getfcn)(object, getter);
+  Timespec ts = ((query_date_getter)get)(object);
 
   if (ts.tv_sec || ts.tv_nsec)
     return g_strdup (gnc_print_date (ts));
@@ -379,11 +382,10 @@
   return NULL;
 }
 
-/* QOF_TYPE_NUMERIC ================================================= */
+/* QOF_TYPE_NUMERIC */
 
-static int 
-numeric_match_predicate (gpointer object, QofParam *getter,
-                         QofQueryPredData* pd)
+static int numeric_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                    QofQueryPredData* pd)
 {
   query_numeric_t pdata = (query_numeric_t)pd;
   gnc_numeric obj_val;
@@ -391,7 +393,7 @@
 
   VERIFY_PREDICATE (query_numeric_type);
 
-  obj_val = ((query_numeric_getter)getter->param_getfcn) (object, getter);
+  obj_val = ((query_numeric_getter)get_fcn) (object);
 
   switch (pdata->options) {
   case QOF_NUMERIC_MATCH_CREDIT:
@@ -434,21 +436,20 @@
   }
 }
 
-static int 
-numeric_compare_func (gpointer a, gpointer b, gint options, QofParam *getter)
+static int numeric_compare_func (gpointer a, gpointer b, gint options,
+                                 QofAccessFunc get_fcn)
 {
   gnc_numeric va, vb;
 
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
 
-  va = ((query_numeric_getter)getter->param_getfcn) (a, getter);
-  vb = ((query_numeric_getter)getter->param_getfcn) (b, getter);
+  va = ((query_numeric_getter)get_fcn) (a);
+  vb = ((query_numeric_getter)get_fcn) (b);
 
   return gnc_numeric_compare (va, vb);  
 }
 
-static void 
-numeric_free_pdata (QofQueryPredData* pd)
+static void numeric_free_pdata (QofQueryPredData* pd)
 {
   query_numeric_t pdata = (query_numeric_t)pd;
   VERIFY_PDATA (query_numeric_type);
@@ -475,8 +476,8 @@
 
 QofQueryPredData *
 qof_query_numeric_predicate (QofQueryCompare how,
-                             QofNumericMatch options,
-                             gnc_numeric value)
+                                          QofNumericMatch options,
+                                          gnc_numeric value)
 {
   query_numeric_t pdata;
   pdata = g_new0 (query_numeric_def, 1);
@@ -487,29 +488,24 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-numeric_to_string (gpointer object, QofParam *getter)
+static char * numeric_to_string (gpointer object, QofAccessFunc get)
 {
-  gnc_numeric num;
-  num = ((query_numeric_getter)getter->param_getfcn)(object, getter);
+  gnc_numeric num = ((query_numeric_getter)get)(object);
 
   return g_strdup (gnc_numeric_to_string (num));
 }
 
-static char * 
-debcred_to_string (gpointer object, QofParam *getter)
+static char * debcred_to_string (gpointer object, QofAccessFunc get)
 {
-  gnc_numeric num;
-  num = ((query_numeric_getter)getter->param_getfcn)(object, getter);
+  gnc_numeric num = ((query_numeric_getter)get)(object);
 
   return g_strdup (gnc_numeric_to_string (num));
 }
 
-/* QOF_TYPE_GUID =================================================== */
+/* QOF_TYPE_GUID */
 
-static int 
-guid_match_predicate (gpointer object, QofParam *getter,
-                      QofQueryPredData *pd)
+static int guid_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                 QofQueryPredData *pd)
 {
   query_guid_t pdata = (query_guid_t)pd;
   GList *node, *o_list;
@@ -520,18 +516,17 @@
   switch (pdata->options) {
 
   case QOF_GUID_MATCH_ALL:
-    /* object is a GList of objects; param_getfcn must be called on each one.
+    /* object is a GList of objects; get_fcn must be called on each one.
      * See if every guid in the predicate is accounted-for in the
      * object list
      */
 
-    for (node = pdata->guids; node; node = node->next) 
-    {
+    for (node = pdata->guids; node; node = node->next) {
+
       /* See if this GUID matches the object's guid */
-      for (o_list = object; o_list; o_list = o_list->next) 
-      {
-        guid = ((query_guid_getter)getter->param_getfcn) (o_list->data, getter);
-        if (guid_equal (node->data, guid)) 
+      for (o_list = object; o_list; o_list = o_list->next) {
+        guid = ((query_guid_getter)get_fcn) (o_list->data);
+        if (guid_equal (node->data, guid))
           break;
       }
 
@@ -554,19 +549,17 @@
   case QOF_GUID_MATCH_LIST_ANY:
     /* object is a single object, getter returns a GList* of GUID*
      *
-     * See if any GUID* in the returned list matches any guid in the
-     * predicate match list.
+     * see if any GUID* in the returned list matches any guid in the
+     * predicate match list
      */
 
-    o_list = ((query_glist_getter)getter->param_getfcn) (object, getter);
+    o_list = ((query_glist_getter)get_fcn) (object);
 
-    for (node = o_list; node; node = node->next) 
-    {
+    for (node = o_list; node; node = node->next) {
       GList *node2;
 
       /* Search the predicate data for a match */
-      for (node2 = pdata->guids; node2; node2 = node2->next) 
-      {
+      for (node2 = pdata->guids; node2; node2 = node2->next) {
         if (guid_equal (node->data, node2->data))
           break;
       }
@@ -590,9 +583,8 @@
      * See if the guid is in the list
      */
 
-    guid = ((query_guid_getter)getter->param_getfcn) (object, getter);
-    for (node = pdata->guids; node; node = node->next) 
-    {
+    guid = ((query_guid_getter)get_fcn) (object);
+    for (node = pdata->guids; node; node = node->next) {
       if (guid_equal (node->data, guid))
         break;
     }
@@ -616,16 +608,13 @@
   }
 }
 
-static void 
-guid_free_pdata (QofQueryPredData *pd)
+static void guid_free_pdata (QofQueryPredData *pd)
 {
   query_guid_t pdata = (query_guid_t)pd;
   GList *node;
   VERIFY_PDATA (query_guid_type);
   for (node = pdata->guids; node; node = node->next)
-  {
     guid_free (node->data);
-  }
   g_list_free (pdata->guids);
   g_free (pdata);
 }
@@ -648,10 +637,8 @@
   if (pd1->options != pd2->options) return FALSE;
   if (g_list_length (l1) != g_list_length (l2)) return FALSE;
   for ( ; l1 ; l1 = l1->next, l2 = l2->next) 
-  {
     if (!guid_equal (l1->data, l2->data))
       return FALSE;
-  }
   return TRUE;
 }
 
@@ -666,8 +653,7 @@
   pdata->pd.type_name = query_guid_type;
   pdata->options = options;
   pdata->guids = g_list_copy (guids);
-  for (node = pdata->guids; node; node = node->next) 
-  {
+  for (node = pdata->guids; node; node = node->next) {
     GUID *guid = guid_malloc ();
     *guid = *((GUID *)node->data);
     node->data = guid;
@@ -678,16 +664,15 @@
 /* ================================================================ */
 /* QOF_TYPE_INT32 */
 
-static int 
-int32_match_predicate (gpointer object, QofParam *getter,
-                       QofQueryPredData *pd)
+static int int32_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                 QofQueryPredData *pd)
 {
   gint32 val;
   query_int32_t pdata = (query_int32_t)pd;
 
   VERIFY_PREDICATE (query_int32_type);
 
-  val = ((query_int32_getter)getter->param_getfcn) (object, getter);
+  val = ((query_int32_getter)get_fcn) (object);
 
   switch (pd->how) {
   case QOF_COMPARE_LT:
@@ -708,23 +693,21 @@
   }
 }
 
-static int 
-int32_compare_func (gpointer a, gpointer b, gint options,
-                    QofParam *getter)
+static int int32_compare_func (gpointer a, gpointer b, gint options,
+                              QofAccessFunc get_fcn)
 {
   gint32 v1, v2;
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
 
-  v1 = ((query_int32_getter)getter->param_getfcn)(a, getter);
-  v2 = ((query_int32_getter)getter->param_getfcn)(b, getter);
+  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 (QofQueryPredData *pd)
+static void int32_free_pdata (QofQueryPredData *pd)
 {
   query_int32_t pdata = (query_int32_t)pd;
   VERIFY_PDATA (query_int32_type);
@@ -758,10 +741,9 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-int32_to_string (gpointer object, QofParam *getter)
+static char * int32_to_string (gpointer object, QofAccessFunc get)
 {
-  gint32 num = ((query_int32_getter)getter->param_getfcn)(object, getter);
+  gint32 num = ((query_int32_getter)get)(object);
 
   return g_strdup_printf ("%d", num);
 }
@@ -769,16 +751,15 @@
 /* ================================================================ */
 /* QOF_TYPE_INT64 */
 
-static int 
-int64_match_predicate (gpointer object, QofParam *getter,
-                       QofQueryPredData *pd)
+static int int64_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                 QofQueryPredData *pd)
 {
   gint64 val;
   query_int64_t pdata = (query_int64_t)pd;
 
   VERIFY_PREDICATE (query_int64_type);
 
-  val = ((query_int64_getter)getter->param_getfcn) (object, getter);
+  val = ((query_int64_getter)get_fcn) (object);
 
   switch (pd->how) {
   case QOF_COMPARE_LT:
@@ -799,23 +780,21 @@
   }
 }
 
-static int 
-int64_compare_func (gpointer a, gpointer b, gint options,
-                              QofParam *getter)
+static int int64_compare_func (gpointer a, gpointer b, gint options,
+                              QofAccessFunc get_fcn)
 {
   gint64 v1, v2;
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
 
-  v1 = ((query_int64_getter)getter->param_getfcn)(a, getter);
-  v2 = ((query_int64_getter)getter->param_getfcn)(b, getter);
+  v1 = ((query_int64_getter)get_fcn)(a);
+  v2 = ((query_int64_getter)get_fcn)(b);
 
   if (v1 < v2) return -1;
   if (v1 > v2) return 1;
   return 0;
 }
 
-static void 
-int64_free_pdata (QofQueryPredData *pd)
+static void int64_free_pdata (QofQueryPredData *pd)
 {
   query_int64_t pdata = (query_int64_t)pd;
   VERIFY_PDATA (query_int64_type);
@@ -849,10 +828,9 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-int64_to_string (gpointer object, QofParam *getter)
+static char * int64_to_string (gpointer object, QofAccessFunc get)
 {
-  gint64 num = ((query_int64_getter)getter->param_getfcn)(object, getter);
+  gint64 num = ((query_int64_getter)get)(object);
 
   return g_strdup_printf (GNC_SCANF_LLD, num);
 }
@@ -860,16 +838,15 @@
 /* ================================================================ */
 /* QOF_TYPE_DOUBLE */
 
-static int 
-double_match_predicate (gpointer object, QofParam *getter,
-                        QofQueryPredData *pd)
+static int double_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                 QofQueryPredData *pd)
 {
   double val;
   query_double_t pdata = (query_double_t)pd;
 
   VERIFY_PREDICATE (query_double_type);
 
-  val = ((query_double_getter)getter->param_getfcn) (object, getter);
+  val = ((query_double_getter)get_fcn) (object);
 
   switch (pd->how) {
   case QOF_COMPARE_LT:
@@ -890,23 +867,21 @@
   }
 }
 
-static int 
-double_compare_func (gpointer a, gpointer b, gint options,
-                     QofParam *getter)
+static int double_compare_func (gpointer a, gpointer b, gint options,
+                              QofAccessFunc get_fcn)
 {
   double v1, v2;
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
 
-  v1 = ((query_double_getter)getter->param_getfcn) (a, getter);
-  v2 = ((query_double_getter)getter->param_getfcn) (b, getter);
+  v1 = ((query_double_getter)get_fcn) (a);
+  v2 = ((query_double_getter)get_fcn) (b);
 
   if (v1 < v2) return -1;
   if (v1 > v2) return 1;
   return 0;
 }
 
-static void 
-double_free_pdata (QofQueryPredData *pd)
+static void double_free_pdata (QofQueryPredData *pd)
 {
   query_double_t pdata = (query_double_t)pd;
   VERIFY_PDATA (query_double_type);
@@ -940,26 +915,24 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-double_to_string (gpointer object, QofParam *getter)
+static char * double_to_string (gpointer object, QofAccessFunc get)
 {
-  double num = ((query_double_getter)getter->param_getfcn)(object, getter);
+  double num = ((query_double_getter)get)(object);
 
   return g_strdup_printf ("%f", num);
 }
 
-/* QOF_TYPE_BOOLEAN =================================================== */
+/* QOF_TYPE_BOOLEAN */
 
-static int 
-boolean_match_predicate (gpointer object, QofParam *getter,
-                         QofQueryPredData *pd)
+static int boolean_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                 QofQueryPredData *pd)
 {
   gboolean val;
   query_boolean_t pdata = (query_boolean_t)pd;
 
   VERIFY_PREDICATE (query_boolean_type);
 
-  val = ((query_boolean_getter)getter->param_getfcn) (object, getter);
+  val = ((query_boolean_getter)get_fcn) (object);
 
   switch (pd->how) {
   case QOF_COMPARE_EQUAL:
@@ -972,21 +945,19 @@
   }
 }
 
-static int 
-boolean_compare_func (gpointer a, gpointer b, gint options,
-                      QofParam *getter)
+static int boolean_compare_func (gpointer a, gpointer b, gint options,
+                                 QofAccessFunc get_fcn)
 {
   gboolean va, vb;
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
-  va = ((query_boolean_getter)getter->param_getfcn) (a, getter);
-  vb = ((query_boolean_getter)getter->param_getfcn) (b, getter);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
+  va = ((query_boolean_getter)get_fcn) (a);
+  vb = ((query_boolean_getter)get_fcn) (b);
   if (!va && vb) return -1;
   if (va && !vb) return 1;
   return 0;
 }
 
-static void 
-boolean_free_pdata (QofQueryPredData *pd)
+static void boolean_free_pdata (QofQueryPredData *pd)
 {
   query_boolean_t pdata = (query_boolean_t)pd;
   VERIFY_PDATA (query_boolean_type);
@@ -1023,18 +994,16 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-boolean_to_string (gpointer object, QofParam *getter)
+static char * boolean_to_string (gpointer object, QofAccessFunc get)
 {
-  gboolean num = ((query_boolean_getter)getter->param_getfcn)(object, getter);
+  gboolean num = ((query_boolean_getter)get)(object);
 
   return g_strdup_printf ("%s", (num ? "X" : ""));
 }
 
-/* QOF_TYPE_CHAR =================================================== */
+/* QOF_TYPE_CHAR */
 
-static int 
-char_match_predicate (gpointer object, QofParam *getter,
+static int char_match_predicate (gpointer object, QofAccessFunc get_fcn,
                                  QofQueryPredData *pd)
 {
   char c;
@@ -1042,7 +1011,7 @@
 
   VERIFY_PREDICATE (query_char_type);
 
-  c = ((query_char_getter)getter->param_getfcn) (object, getter);
+  c = ((query_char_getter)get_fcn) (object);
 
   switch (pdata->options) {
   case QOF_CHAR_MATCH_ANY:
@@ -1057,18 +1026,17 @@
   }
 }
 
-static int 
-char_compare_func (gpointer a, gpointer b, gint options, QofParam *getter)
+static int char_compare_func (gpointer a, gpointer b, gint options,
+                              QofAccessFunc get_fcn)
 {
   char va, vb;
-  g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
-  va = ((query_char_getter)getter->param_getfcn)(a, getter);
-  vb = ((query_char_getter)getter->param_getfcn)(b, getter);
+  g_return_val_if_fail (a && b && get_fcn, COMPARE_ERROR);
+  va = ((query_char_getter)get_fcn)(a);
+  vb = ((query_char_getter)get_fcn)(b);
   return (va-vb);
 }
 
-static void 
-char_free_pdata (QofQueryPredData *pd)
+static void char_free_pdata (QofQueryPredData *pd)
 {
   query_char_t pdata = (query_char_t)pd;
   VERIFY_PDATA (query_char_type);
@@ -1107,19 +1075,17 @@
   return ((QofQueryPredData*)pdata);
 }
 
-static char * 
-char_to_string (gpointer object, QofParam *getter)
+static char * char_to_string (gpointer object, QofAccessFunc get)
 {
-  char num = ((query_char_getter)getter->param_getfcn)(object, getter);
+  char num = ((query_char_getter)get)(object);
 
   return g_strdup_printf ("%c", num);
 }
 
-/* QOF_TYPE_KVP ================================================ */
+/* QOF_TYPE_KVP */
 
-static int 
-kvp_match_predicate (gpointer object, QofParam *getter,
-                     QofQueryPredData *pd)
+static int kvp_match_predicate (gpointer object, QofAccessFunc get_fcn,
+                                QofQueryPredData *pd)
 {
   int compare;
   KvpFrame *kvp;
@@ -1128,7 +1094,7 @@
 
   VERIFY_PREDICATE (query_kvp_type);
 
-  kvp = ((query_kvp_getter)getter->param_getfcn) (object, getter);
+  kvp = ((query_kvp_getter)get_fcn) (object);
   if (!kvp)
     return 0;
 
@@ -1161,16 +1127,14 @@
   }
 }
 
-static void 
-kvp_free_pdata (QofQueryPredData *pd)
+static void kvp_free_pdata (QofQueryPredData *pd)
 {
   query_kvp_t pdata = (query_kvp_t)pd;
   GSList *node;
 
   VERIFY_PDATA (query_kvp_type);
   kvp_value_delete (pdata->value);
-  for (node = pdata->path; node; node = node->next) 
-  {
+  for (node = pdata->path; node; node = node->next) {
     g_free (node->data);
     node->data = NULL;
   }
@@ -1197,10 +1161,8 @@
   n2 = pd2->path;
 
   for ( ; n1 && n2; n1 = n1->next, n2 = n2->next)
-  {
     if (safe_strcmp (n1->data, n2->data) != 0)
       return FALSE;
-  }
 
   if (n1 || n2)
     return FALSE;
@@ -1210,7 +1172,7 @@
 
 QofQueryPredData *
 qof_query_kvp_predicate (QofQueryCompare how,
-                         GSList *path, const KvpValue *value)
+                                      GSList *path, const KvpValue *value)
 {
   query_kvp_t pdata;
   GSList *node;
@@ -1228,63 +1190,20 @@
   return ((QofQueryPredData*)pdata);
 }
 
-/* initialization ================================================== */
-/** This function registers a new Core Object with the QofQuery
- * subsystem.  It maps the "core_name" object to the given
- * query_predicate, predicate_copy, and predicate_data_free functions.
- *
- * An example:
- * qof_query_register_core_object (QOF_TYPE_STRING, string_match_predicate,
- *                               string_compare_fcn, string_free_pdata,
- *                               string_print_fcn, pred_equal_fcn);
- */
-
-
-static void 
-qof_query_register_core_object (QofType core_name,
-                                QofQueryPredicateFunc pred,
-                                QofCompareFunc comp,
-                                QueryPredicateCopyFunc copy,
-                                QueryPredDataFree pd_free,
-                                QueryToString toString,
-                                QueryPredicateEqual pred_equal)
-{
-  g_return_if_fail (core_name);
-  g_return_if_fail (*core_name != '\0');
-
-  if (pred)
-    g_hash_table_insert (predTable, (char *)core_name, pred);
-
-  if (comp)
-    g_hash_table_insert (cmpTable, (char *)core_name, comp);
-
-  if (copy)
-    g_hash_table_insert (copyTable, (char *)core_name, copy);
-
-  if (pd_free)
-    g_hash_table_insert (freeTable, (char *)core_name, pd_free);
-
-  if (toString)
-    g_hash_table_insert (toStringTable, (char *)core_name, toString);
-
-  if (pred_equal)
-    g_hash_table_insert (predEqualTable, (char *)core_name, pred_equal);
-}
+/* initialization */
 
 static void init_tables (void)
 {
   unsigned int i;
-  struct 
-  {
-    QofType                name;
-    QofQueryPredicateFunc  pred;
-    QofCompareFunc         comp;
+  struct {
+    char const *name;
+    QofQueryPredicateFunc pred;
+    QofCompareFunc comp;
     QueryPredicateCopyFunc copy;
-    QueryPredDataFree      pd_free;
-    QueryToString          toString;
-    QueryPredicateEqual    pred_equal;
-  } knownTypes[] = 
-  {
+    QueryPredDataFree pd_free;
+    QueryToString toString;
+    QueryPredicateEqual pred_equal;
+  } knownTypes[] = {
     { QOF_TYPE_STRING, string_match_predicate, string_compare_func,
       string_copy_predicate, string_free_pdata, string_to_string, 
       string_predicate_equal },
@@ -1320,8 +1239,7 @@
   };
 
   /* Register the known data types */
-  for (i = 0; i < (sizeof(knownTypes)/sizeof(*knownTypes)); i++) 
-  {
+  for (i = 0; i < (sizeof(knownTypes)/sizeof(*knownTypes)); i++) {
     qof_query_register_core_object (knownTypes[i].name,
                                 knownTypes[i].pred,
                                 knownTypes[i].comp,
@@ -1332,8 +1250,7 @@
   }
 }
 
-static QueryPredicateCopyFunc 
-qof_query_copy_predicate (QofType type)
+static QueryPredicateCopyFunc gncQueryCoreGetCopy (char const *type)
 {
   QueryPredicateCopyFunc rc;
   g_return_val_if_fail (type, NULL);
@@ -1341,13 +1258,43 @@
   return rc;
 }
 
-static QueryPredDataFree 
-qof_query_predicate_free (QofType type)
+static QueryPredDataFree gncQueryCoreGetPredFree (char const *type)
 {
   g_return_val_if_fail (type, NULL);
   return g_hash_table_lookup (freeTable, type);
 }
 
+static void 
+qof_query_register_core_object (char const *core_name,
+                                QofQueryPredicateFunc pred,
+                                QofCompareFunc comp,
+                                QueryPredicateCopyFunc copy,
+                                QueryPredDataFree pd_free,
+                                QueryToString toString,
+                                QueryPredicateEqual pred_equal)
+{
+  g_return_if_fail (core_name);
+  g_return_if_fail (*core_name != '\0');
+
+  if (pred)
+    g_hash_table_insert (predTable, (char *)core_name, pred);
+
+  if (comp)
+    g_hash_table_insert (cmpTable, (char *)core_name, comp);
+
+  if (copy)
+    g_hash_table_insert (copyTable, (char *)core_name, copy);
+
+  if (pd_free)
+    g_hash_table_insert (freeTable, (char *)core_name, pd_free);
+
+  if (toString)
+    g_hash_table_insert (toStringTable, (char *)core_name, toString);
+
+  if (pred_equal)
+    g_hash_table_insert (predEqualTable, (char *)core_name, pred_equal);
+}
+
 /********************************************************************/
 /* PUBLISHED API FUNCTIONS */
 
@@ -1382,14 +1329,14 @@
 }
 
 QofQueryPredicateFunc
-qof_query_core_get_predicate (QofType type)
+qof_query_core_get_predicate (char const *type)
 {
   g_return_val_if_fail (type, NULL);
   return g_hash_table_lookup (predTable, type);
 }
 
 QofCompareFunc
-qof_query_core_get_compare (QofType type)
+qof_query_core_get_compare (char const *type)
 {
   g_return_val_if_fail (type, NULL);
   return g_hash_table_lookup (cmpTable, type);
@@ -1403,7 +1350,7 @@
   g_return_if_fail (pdata);
   g_return_if_fail (pdata->type_name);
 
-  free_fcn = qof_query_predicate_free (pdata->type_name);
+  free_fcn = gncQueryCoreGetPredFree (pdata->type_name);
   free_fcn (pdata);
 }
 
@@ -1415,24 +1362,24 @@
   g_return_val_if_fail (pdata, NULL);
   g_return_val_if_fail (pdata->type_name, NULL);
 
-  copy = qof_query_copy_predicate (pdata->type_name);
+  copy = gncQueryCoreGetCopy (pdata->type_name);
   return (copy (pdata));
 }
 
 char * 
-qof_query_core_to_string (QofType type, gpointer object,
-                          QofParam *getter)
+qof_query_core_to_string (char const *type, gpointer object,
+                          QofAccessFunc get)
 {
   QueryToString toString;
 
   g_return_val_if_fail (type, NULL);
   g_return_val_if_fail (object, NULL);
-  g_return_val_if_fail (getter, NULL);
+  g_return_val_if_fail (get, NULL);
 
   toString = g_hash_table_lookup (toStringTable, type);
   g_return_val_if_fail (toString, NULL);
 
-  return toString (object, getter);
+  return toString (object, get);
 }
 
 gboolean 
Index: qofquerycore-p.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofquerycore-p.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -Lsrc/engine/qofquerycore-p.h -Lsrc/engine/qofquerycore-p.h -u -r1.5 -r1.6
--- src/engine/qofquerycore-p.h
+++ src/engine/qofquerycore-p.h
@@ -37,22 +37,22 @@
 void qof_query_core_shutdown (void);
 
 /* 
- * An arbitrary Query Predicate.  Given the object and the
+ * An arbitrary Query Predicate.  Given the gnucash object and the
  * particular parameter get-function (obtained from the registry by
  * the Query internals), compare the object's parameter to the
- * predicate data.
+ * predicate data
  */
 typedef int (*QofQueryPredicateFunc) (gpointer object,
-			       QofParam *getter,
+			       QofAccessFunc get_fcn,
 			       QofQueryPredData *pdata);
 
 /* A callback for how to compare two (same-type) objects based on a
- * common getter (parameter member), using the provided comparison
+ * common get_fcn (parameter member), using the provided comparrison
  * options (which are the type-specific options).
  */
 typedef int (*QofCompareFunc) (gpointer a, gpointer b,
                               gint compare_options,
-                              QofParam *getter);
+                              QofAccessFunc get_fcn);
 
 /* Lookup functions */
 QofQueryPredicateFunc qof_query_core_get_predicate (char const *type);


More information about the Gnucash-changes mailing list