mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Implement qof_instance_for_each_slot().
Wraps kvp_frame_for_each_slot().
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ======================= */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user