diff --git a/src/libqof/qof/kvp_frame.cpp b/src/libqof/qof/kvp_frame.cpp index b2b4683fb5..e56e22fe4d 100644 --- a/src/libqof/qof/kvp_frame.cpp +++ b/src/libqof/qof/kvp_frame.cpp @@ -1192,7 +1192,6 @@ kvp_frame_to_string(const KvpFrame *frame) return g_strdup(realframe->to_string().c_str()); } -static GValue *gvalue_from_kvp_value (KvpValue *); static KvpValue *kvp_value_from_gvalue (const GValue*); static void @@ -1216,8 +1215,8 @@ kvp_value_list_from_gvalue (GValue *gval, gpointer pList) *kvplist = g_list_prepend (*kvplist, kvp); } -static GValue* -gvalue_from_kvp_value (KvpValue *kval) +GValue* +gvalue_from_kvp_value (const KvpValue *kval) { GValue *val; gnc_numeric num; diff --git a/src/libqof/qof/kvp_frame.h b/src/libqof/qof/kvp_frame.h index 493098e964..8053539a62 100644 --- a/src/libqof/qof/kvp_frame.h +++ b/src/libqof/qof/kvp_frame.h @@ -580,6 +580,12 @@ void kvp_frame_for_each_slot(KvpFrame *f, /** Internal helper routines, you probably shouldn't be using these. */ gchar* kvp_frame_to_string(const KvpFrame *frame); +/** Convert a kvp_value into a GValue. Frames aren't converted. + * @param kval: A KvpValue. + * @return GValue*. Must be freed with g_free(). + */ +GValue* gvalue_from_kvp_value (const KvpValue *kval); + /** KvpItem: GValue Exchange * \brief Transfer of KVP to and from GValue, with the key * diff --git a/src/libqof/qof/qofinstance-p.h b/src/libqof/qof/qofinstance-p.h index 1914e1afb0..3ff5f72f46 100644 --- a/src/libqof/qof/qofinstance-p.h +++ b/src/libqof/qof/qofinstance-p.h @@ -129,7 +129,9 @@ gboolean qof_instance_has_slot (const QofInstance *inst, const char *path); void qof_instance_slot_delete (const QofInstance *inst, const char *path); void qof_instance_slot_delete_if_empty (const QofInstance *inst, const char *path); - +void qof_instance_foreach_slot (const QofInstance *inst, const char *path, + void(*proc)(const char*, const GValue*, void*), + void* data); #ifdef __cplusplus } #endif diff --git a/src/libqof/qof/qofinstance.cpp b/src/libqof/qof/qofinstance.cpp index ffea2ff8ca..a765cae060 100644 --- a/src/libqof/qof/qofinstance.cpp +++ b/src/libqof/qof/qofinstance.cpp @@ -1287,5 +1287,31 @@ qof_instance_slot_delete_if_empty (const QofInstance *inst, const char *path) kvp_frame_set_frame_nc (inst->kvp_data, path, NULL); } +struct wrap_param +{ + void (*proc)(const char*, const GValue*, void*); + void *user_data; +}; + +static void +wrap_gvalue_function (const char* key, KvpValue *val, gpointer data) +{ + auto param = static_cast(data); + GValue *gv = gvalue_from_kvp_value(val); + param->proc(key, gv, param->user_data); + g_slice_free (GValue, gv); +} + +void +qof_instance_foreach_slot (const QofInstance *inst, const char* path, + void (*proc)(const char*, const GValue*, void*), + void* data) +{ + KvpFrame* frame = kvp_frame_get_frame (inst->kvp_data, path); + if (!frame) return; + wrap_param new_data {proc, data}; + kvp_frame_for_each_slot(frame, wrap_gvalue_function, &new_data); +} + /* ========================== END OF FILE ======================= */