Implement qof_instance_for_each_slot().

Wraps kvp_frame_for_each_slot().
This commit is contained in:
John Ralls
2015-06-09 14:42:39 -07:00
parent dcc9bfec36
commit ccd74059a2
4 changed files with 37 additions and 4 deletions

View File

@@ -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;

View File

@@ -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
*

View File

@@ -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

View File

@@ -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<wrap_param*>(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 ======================= */