[Gnucash-changes] add a parameter for-each function per request from Niel Williams

Linas Vepstas linas at cvs.gnucash.org
Sun Jun 20 11:48:40 EDT 2004


Log Message:
-----------
add a parameter for-each function per request from Niel Williams

Modified Files:
--------------
    gnucash/src/engine:
        qofclass.c
        qofclass.h

Revision Data
-------------
Index: qofclass.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofclass.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lsrc/engine/qofclass.h -Lsrc/engine/qofclass.h -u -r1.8 -r1.9
--- src/engine/qofclass.h
+++ src/engine/qofclass.h
@@ -116,9 +116,9 @@
  *    object (QofIdType) or it can be a core data type (QofType).
  * -- param_getfcn is the function to actually obtain the parameter
  * -- param_setfcn is the function to actually set the parameter
- * -- param_userdata is a place where the user can place any desiered
- *    user-defined data (and thus can be used by the user-defined
- *    setter/getter).
+ * -- param_userdata is a place where the object author can place any 
+ *    desired object-author-defined data (and thus can be used by the 
+ *    author-defined setter/getter).
  *
  * Either the getter or the setter may be NULL.
  *
@@ -195,6 +195,15 @@
 QofSetterFunc qof_class_get_parameter_setter (QofIdTypeConst obj_name,
                                               const char *parameter);
 
+/** Type definition for the paramter callback function. */
+typedef void (*QofParamForeachCB) (QofParam *, gpointer user_data);
+
+/** Call the callback once for each parameter on the indicated 
+ *  object class.  The 'user_data' is passed back to teh callback.
+ */
+void qof_class_param_foreach (QofIdTypeConst obj_name,
+                              QofParamForeachCB, gpointer user_data);
+
 
 #endif /* QOF_CLASS_H */
 /* @} */
Index: qofclass.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofclass.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lsrc/engine/qofclass.c -Lsrc/engine/qofclass.c -u -r1.3 -r1.4
--- src/engine/qofclass.c
+++ src/engine/qofclass.c
@@ -186,4 +186,38 @@
   return g_hash_table_lookup (sortTable, obj_name);
 }
 
+/* ================================================================ */
+
+struct _iterate {
+  QofParamForeachCB   fcn;
+  gpointer                data;
+};
+                                                                                
+static void 
+foreach_cb (gpointer key, gpointer item, gpointer arg)
+{
+  struct _iterate *iter = arg;
+  QofParam *parm = item;
+                                                                                
+  iter->fcn (parm, iter->data);
+}
+
+
+void
+qof_class_param_foreach (QofIdTypeConst obj_name,
+                         QofParamForeachCB cb, gpointer user_data)
+{
+  struct _iterate iter;
+  GHashTable *param_ht;
+
+  if (!obj_name || !cb) return;
+  param_ht = g_hash_table_lookup (paramTable, obj_name);
+  if (!param_ht) return;
+
+  iter.fcn = cb;
+  iter.data = user_data;
+
+  g_hash_table_foreach (param_ht, foreach_cb, &iter);
+}
+
 /* ============================= END OF FILE ======================== */


More information about the gnucash-changes mailing list