mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Convert libqof kvp calls to C++.
This commit is contained in:
parent
9e142124f4
commit
fd935d3b82
@ -270,10 +270,11 @@ set_slot_from_value( slot_info_t *pInfo, KvpValue *pValue)
|
||||
auto frame = pInfo->pKvpFrame;
|
||||
if ( path )
|
||||
{
|
||||
frame = frame->get_slot(path)->get<KvpFrame*>();
|
||||
frame->set_path({path, key}, pValue);
|
||||
g_free( path );
|
||||
}
|
||||
frame->set(key, pValue);
|
||||
else
|
||||
frame->set(key, pValue);
|
||||
g_free( key );
|
||||
break;
|
||||
}
|
||||
|
@ -30,10 +30,10 @@
|
||||
extern "C"
|
||||
{
|
||||
#include "gnc-aqbanking-templates.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "qofinstance-p.h"
|
||||
}
|
||||
|
||||
#include "kvp_frame.hpp"
|
||||
#include "gnc-rational.hpp"
|
||||
|
||||
namespace {
|
||||
@ -106,18 +106,13 @@ KvpFrame*
|
||||
_GncABTransTempl::make_kvp_frame()
|
||||
{
|
||||
auto frame = kvp_frame_new();
|
||||
kvp_frame_set_slot(frame, TT_NAME, kvp_value_new_string(m_name.c_str()));
|
||||
kvp_frame_set_slot(frame, TT_RNAME,
|
||||
kvp_value_new_string(m_recipient_name.c_str()));
|
||||
kvp_frame_set_slot(frame, TT_RACC,
|
||||
kvp_value_new_string(m_recipient_account.c_str()));
|
||||
kvp_frame_set_slot(frame, TT_RBCODE,
|
||||
kvp_value_new_string(m_recipient_bankcode.c_str()));
|
||||
kvp_frame_set_slot(frame, TT_AMOUNT, kvp_value_new_gnc_numeric(m_amount));
|
||||
kvp_frame_set_slot(frame, TT_PURPOS,
|
||||
kvp_value_new_string(m_purpose.c_str()));
|
||||
kvp_frame_set_slot(frame, TT_PURPOSCT,
|
||||
kvp_value_new_string(m_purpose_continuation.c_str()));
|
||||
frame->set(TT_NAME, new KvpValue(m_name.c_str()));
|
||||
frame->set(TT_RNAME, new KvpValue(m_recipient_name.c_str()));
|
||||
frame->set(TT_RACC, new KvpValue(m_recipient_account.c_str()));
|
||||
frame->set(TT_RBCODE, new KvpValue(m_recipient_bankcode.c_str()));
|
||||
frame->set(TT_AMOUNT, new KvpValue(m_amount));
|
||||
frame->set(TT_PURPOS, new KvpValue(m_purpose.c_str()));
|
||||
frame->set(TT_PURPOSCT, new KvpValue(m_purpose_continuation.c_str()));
|
||||
return frame;
|
||||
}
|
||||
|
||||
@ -141,19 +136,25 @@ GList*
|
||||
gnc_ab_trans_templ_list_new_from_book(QofBook *b)
|
||||
{
|
||||
GList *retval = NULL;
|
||||
KvpFrame *toplevel = qof_instance_get_slots (QOF_INSTANCE (b));
|
||||
KvpFrame *hbci = kvp_frame_get_frame (toplevel, "hbci");
|
||||
KvpValue *listval = kvp_frame_get_slot (hbci, "template-list");
|
||||
GList *list = kvp_value_get_glist (listval);
|
||||
auto toplevel = qof_instance_get_slots (QOF_INSTANCE (b));
|
||||
auto slot = toplevel->get_slot({"hbci", "template-list"});
|
||||
if (slot == nullptr)
|
||||
return retval;
|
||||
auto list = slot->get<GList*>();
|
||||
for (auto node = list; node != NULL; node = g_list_next (node))
|
||||
{
|
||||
KvpFrame *frame = kvp_value_get_frame (static_cast<KvpValue*>(node->data));
|
||||
auto func = [frame](const char* key)
|
||||
{return kvp_value_get_string(kvp_frame_get_slot(frame, key));};
|
||||
auto templ = new _GncABTransTempl (func(TT_NAME), func(TT_RNAME),
|
||||
func(TT_RACC), func(TT_RBCODE),
|
||||
kvp_value_get_numeric(kvp_frame_get_slot(frame, TT_AMOUNT)),
|
||||
func(TT_PURPOS), func(TT_PURPOSCT));
|
||||
KvpFrame *frame = static_cast<KvpValue*>(node->data)->get<KvpFrame*>();
|
||||
auto c_func = [frame](const char* key)
|
||||
{ auto slot = frame->get_slot(key);
|
||||
return slot == nullptr ? std::string("") : std::string(slot->get<const char*>());};
|
||||
auto n_func = [frame](const char* key)
|
||||
{ auto slot = frame->get_slot(key);
|
||||
return slot == nullptr ? gnc_numeric_zero() : slot->get<gnc_numeric>();};
|
||||
auto amt_slot = frame->get_slot(TT_AMOUNT);
|
||||
auto templ = new _GncABTransTempl (c_func(TT_NAME), c_func(TT_RNAME),
|
||||
c_func(TT_RACC), c_func(TT_RBCODE),
|
||||
n_func(TT_AMOUNT), c_func(TT_PURPOS),
|
||||
c_func(TT_PURPOSCT));
|
||||
retval = g_list_prepend (retval, templ);
|
||||
}
|
||||
retval = g_list_reverse (retval);
|
||||
@ -172,6 +173,12 @@ gnc_ab_trans_templ_list_free (GList *l)
|
||||
for(GList *node = l; node != NULL; node = g_list_next(node))
|
||||
delete static_cast<_GncABTransTempl*>(node->data);
|
||||
}
|
||||
static void*
|
||||
copy_list_value(const void* pvalue, void* pdata)
|
||||
{
|
||||
auto new_value = new KvpValue(*static_cast<const KvpValue*>(pvalue));
|
||||
return new_value;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ab_set_book_template_list (QofBook *b, GList *template_list)
|
||||
@ -179,14 +186,15 @@ gnc_ab_set_book_template_list (QofBook *b, GList *template_list)
|
||||
GList *kvp_list = NULL;
|
||||
for (auto node = template_list; node != NULL; node = g_list_next (node))
|
||||
{
|
||||
auto value = kvp_value_new_frame_nc (static_cast<_GncABTransTempl*>(node->data)->make_kvp_frame());
|
||||
auto templ = static_cast<_GncABTransTempl*>(node->data);
|
||||
auto value = new KvpValue(templ->make_kvp_frame());
|
||||
kvp_list = g_list_prepend (kvp_list, value);
|
||||
}
|
||||
kvp_list = g_list_reverse (kvp_list);
|
||||
auto value = kvp_value_new_glist_nc(kvp_list);
|
||||
auto value = new KvpValue(g_list_copy_deep(kvp_list, copy_list_value,
|
||||
nullptr));
|
||||
KvpFrame *toplevel = qof_instance_get_slots (QOF_INSTANCE (b));
|
||||
KvpFrame *hbci = kvp_frame_get_frame (toplevel, "hbci");
|
||||
kvp_frame_set_slot_nc (hbci, "template-list", value);
|
||||
delete toplevel->set_path({"hbci", "template-list"}, value);
|
||||
qof_instance_set_dirty_flag (QOF_INSTANCE (b), TRUE);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,11 @@ extern "C"
|
||||
{
|
||||
#ifndef __STDC_LIMIT_MACROS
|
||||
#define __STDC_LIMIT_MACROS 1
|
||||
#endif
|
||||
#ifndef __STDC_CONSTANT_MACROS
|
||||
#define __STDC_CONSTANT_MACROS 1
|
||||
#endif
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS 1
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
|
@ -28,13 +28,13 @@ extern "C"
|
||||
{
|
||||
#include "config.h"
|
||||
#include "qof.h"
|
||||
#include "kvp_frame.h"
|
||||
}
|
||||
#include <boost/version.hpp>
|
||||
#if BOOST_VERSION == 105600
|
||||
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
|
||||
#endif
|
||||
#include <boost/variant.hpp>
|
||||
#include "kvp_frame.h"
|
||||
|
||||
struct KvpValueImpl
|
||||
{
|
||||
|
@ -1280,8 +1280,6 @@ kvp_frame_to_string(const KvpFrame *frame)
|
||||
return g_strdup(realframe->to_string().c_str());
|
||||
}
|
||||
|
||||
static KvpValue *kvp_value_from_gvalue (const GValue*);
|
||||
|
||||
static void
|
||||
gvalue_list_from_kvp_value (KvpValue *kval, gpointer pList)
|
||||
{
|
||||
|
@ -586,6 +586,12 @@ gchar* kvp_frame_to_string(const KvpFrame *frame);
|
||||
*/
|
||||
GValue* gvalue_from_kvp_value (const KvpValue *kval);
|
||||
|
||||
/** Convert a gvalue into a kvpvalue.
|
||||
* @param gval: A GValue of a type KvpValue can digest.
|
||||
* @return KvpValue created from the GValue's contents.
|
||||
*/
|
||||
KvpValue* kvp_value_from_gvalue (const GValue *gval);
|
||||
|
||||
/** KvpItem: GValue Exchange
|
||||
* \brief Transfer of KVP to and from GValue, with the key
|
||||
*
|
||||
|
@ -36,13 +36,11 @@
|
||||
#ifndef QOF_BOOK_P_H
|
||||
#define QOF_BOOK_P_H
|
||||
|
||||
#include "kvp_frame.h"
|
||||
#include "qofbackend.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofinstance-p.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ extern "C"
|
||||
#include "qofid-p.h"
|
||||
#include "qofobject-p.h"
|
||||
#include "qofbookslots.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "kvp_frame.hpp"
|
||||
|
||||
static QofLogModule log_module = QOF_MOD_ENGINE;
|
||||
#define AB_KEY "hbci"
|
||||
@ -649,11 +649,11 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = kvp_frame_get_slot_path (kvp, "counters", counter_name, NULL);
|
||||
value = kvp->get_slot({"counters", counter_name});
|
||||
if (value)
|
||||
{
|
||||
/* found it */
|
||||
return kvp_value_get_gint64 (value);
|
||||
return value->get<int64_t>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -703,9 +703,8 @@ qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
|
||||
|
||||
/* Save off the new counter */
|
||||
qof_book_begin_edit(book);
|
||||
value = kvp_value_new_gint64 (counter);
|
||||
kvp_frame_set_slot_path (kvp, value, "counters", counter_name, NULL);
|
||||
kvp_value_delete (value);
|
||||
value = new KvpValue(counter);
|
||||
delete kvp->set_path({"counters", counter_name}, value);
|
||||
qof_instance_set_dirty (QOF_INSTANCE (book));
|
||||
qof_book_commit_edit(book);
|
||||
|
||||
@ -753,10 +752,10 @@ qof_book_get_counter_format(const QofBook *book, const char *counter_name)
|
||||
format = NULL;
|
||||
|
||||
/* Get the format string */
|
||||
value = kvp_frame_get_slot_path (kvp, "counter_formats", counter_name, NULL);
|
||||
value = kvp->get_slot({"counter_formats", counter_name});
|
||||
if (value)
|
||||
{
|
||||
format = kvp_value_get_string (value);
|
||||
format = value->get<const char*>();
|
||||
error = qof_book_validate_counter_format(format);
|
||||
if (error != NULL)
|
||||
{
|
||||
@ -915,19 +914,13 @@ qof_book_get_book_currency (QofBook *book)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* See if there is a book currency */
|
||||
value = kvp_frame_get_slot_path (kvp,
|
||||
KVP_OPTION_PATH,
|
||||
OPTION_SECTION_ACCOUNTS,
|
||||
OPTION_NAME_BOOK_CURRENCY,
|
||||
NULL);
|
||||
if (!value)
|
||||
/* No book-currency */
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/* See if there is a book currency. */
|
||||
value = kvp->get_slot({KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS,
|
||||
OPTION_NAME_BOOK_CURRENCY});
|
||||
if (!value) /* No book-currency */
|
||||
return nullptr;
|
||||
|
||||
return kvp_value_get_string (value);
|
||||
return value->get<const char*>();
|
||||
}
|
||||
|
||||
/** Returns pointer to default gain/loss policy for book, if one exists in the
|
||||
@ -957,19 +950,14 @@ qof_book_get_default_gains_policy (QofBook *book)
|
||||
}
|
||||
|
||||
/* See if there is a default gain/loss policy */
|
||||
value = kvp_frame_get_slot_path (kvp,
|
||||
KVP_OPTION_PATH,
|
||||
OPTION_SECTION_ACCOUNTS,
|
||||
OPTION_NAME_DEFAULT_GAINS_POLICY,
|
||||
NULL);
|
||||
value = kvp->get_slot({KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS,
|
||||
OPTION_NAME_DEFAULT_GAINS_POLICY});
|
||||
if (!value)
|
||||
/* No default gain/loss policy, therefore not valid book-currency
|
||||
accounting method */
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
return kvp_value_get_string (value);
|
||||
return g_strdup(value->get<const char*>());
|
||||
}
|
||||
|
||||
|
||||
@ -1009,11 +997,8 @@ gboolean qof_book_uses_autoreadonly (const QofBook *book)
|
||||
|
||||
gint qof_book_get_num_days_autoreadonly (const QofBook *book)
|
||||
{
|
||||
KvpValue *kvp_val;
|
||||
double tmp = 0;
|
||||
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
||||
|
||||
g_assert(book);
|
||||
double tmp;
|
||||
qof_instance_get (QOF_INSTANCE (book),
|
||||
"autoreadonly-days", &tmp,
|
||||
NULL);
|
||||
@ -1038,16 +1023,18 @@ GDate* qof_book_get_autoreadonly_gdate (const QofBook *book)
|
||||
const char*
|
||||
qof_book_get_string_option(const QofBook* book, const char* opt_name)
|
||||
{
|
||||
return kvp_frame_get_string(qof_instance_get_slots(QOF_INSTANCE (book)),
|
||||
opt_name);
|
||||
auto slot = qof_instance_get_slots(QOF_INSTANCE (book))->get_slot(opt_name);
|
||||
if (slot == nullptr)
|
||||
return nullptr;
|
||||
return slot->get<const char*>();
|
||||
}
|
||||
|
||||
void
|
||||
qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val)
|
||||
{
|
||||
qof_book_begin_edit(book);
|
||||
kvp_frame_set_string(qof_instance_get_slots(QOF_INSTANCE (book)),
|
||||
opt_name, opt_val);
|
||||
auto frame = qof_instance_get_slots(QOF_INSTANCE(book));
|
||||
delete frame->set(opt_name, new KvpValue(opt_val));
|
||||
qof_instance_set_dirty (QOF_INSTANCE (book));
|
||||
qof_book_commit_edit(book);
|
||||
}
|
||||
@ -1068,7 +1055,7 @@ static void commit_err (G_GNUC_UNUSED QofInstance *inst, QofBackendError errcode
|
||||
static void
|
||||
add_feature_to_hash (const gchar *key, KvpValue *value, gpointer user_data)
|
||||
{
|
||||
gchar *descr = g_strdup(kvp_value_get_string (value));
|
||||
gchar *descr = g_strdup(value->get<const char*>());
|
||||
g_hash_table_insert (*(GHashTable**)user_data, (gchar*)key, descr);
|
||||
}
|
||||
|
||||
@ -1079,8 +1066,8 @@ qof_book_get_features (QofBook *book)
|
||||
GHashTable *features = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
NULL, g_free);
|
||||
|
||||
frame = kvp_frame_get_frame (frame, GNC_FEATURES);
|
||||
kvp_frame_for_each_slot (frame, &add_feature_to_hash, &features);
|
||||
frame = frame->get_slot(GNC_FEATURES)->get<KvpFrame*>();
|
||||
frame->for_each_slot(&add_feature_to_hash, &features);
|
||||
return features;
|
||||
}
|
||||
|
||||
@ -1088,9 +1075,8 @@ void
|
||||
qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
|
||||
{
|
||||
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
||||
gchar *path = g_strconcat (GNC_FEATURES, key, NULL);
|
||||
qof_book_begin_edit (book);
|
||||
kvp_frame_set_string (frame, path, descr);
|
||||
delete frame->set_path({GNC_FEATURES, key}, new KvpValue(descr));
|
||||
qof_instance_set_dirty (QOF_INSTANCE (book));
|
||||
qof_book_commit_edit (book);
|
||||
}
|
||||
@ -1127,9 +1113,11 @@ void
|
||||
qof_book_set_option (QofBook *book, KvpValue *value, GSList *path)
|
||||
{
|
||||
KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE (book));
|
||||
KvpFrame *options = kvp_frame_get_frame_slash (root, KVP_OPTION_PATH);
|
||||
Path path_v {KVP_OPTION_PATH};
|
||||
for (auto item = path; item != nullptr; item = g_slist_next(item))
|
||||
path_v.push_back(static_cast<const char*>(item->data));
|
||||
qof_book_begin_edit (book);
|
||||
kvp_frame_set_slot_path_gslist (options, value, path);
|
||||
delete root->set_path(path_v, value);
|
||||
qof_instance_set_dirty (QOF_INSTANCE (book));
|
||||
qof_book_commit_edit (book);
|
||||
}
|
||||
@ -1138,15 +1126,19 @@ KvpValue*
|
||||
qof_book_get_option (QofBook *book, GSList *path)
|
||||
{
|
||||
KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
|
||||
KvpFrame *options = kvp_frame_get_frame(root, KVP_OPTION_PATH);
|
||||
return kvp_frame_get_slot_path_gslist(options, path);
|
||||
Path path_v {KVP_OPTION_PATH};
|
||||
for (auto item = path; item != nullptr; item = g_slist_next(item))
|
||||
path_v.push_back(static_cast<const char*>(item->data));
|
||||
return root->get_slot(path_v);
|
||||
}
|
||||
|
||||
void
|
||||
qof_book_options_delete (QofBook *book)
|
||||
{
|
||||
KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
|
||||
kvp_frame_delete (kvp_frame_get_frame(root, KVP_OPTION_PATH));
|
||||
auto option = root->get_slot(KVP_OPTION_PATH);
|
||||
if (option != nullptr)
|
||||
delete option->get<KvpFrame*>();
|
||||
}
|
||||
|
||||
/* QofObject function implementation and registration */
|
||||
|
@ -115,6 +115,7 @@ void qof_instance_get_kvp (const QofInstance *inst, const gchar *key, GValue *va
|
||||
void qof_instance_copy_kvp (QofInstance *to, const QofInstance *from);
|
||||
void qof_instance_swap_kvp (QofInstance *a, QofInstance *b);
|
||||
int qof_instance_compare_kvp (const QofInstance *a, const QofInstance *b);
|
||||
/** Returns a g_strdup'd string which must be g_freed. */
|
||||
char* qof_instance_kvp_as_string (const QofInstance *inst);
|
||||
void qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
|
||||
const Timespec time, const char* key,
|
||||
|
@ -39,6 +39,7 @@ extern "C"
|
||||
#include "qofbook-p.h"
|
||||
#include "qofid-p.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "kvp_frame.hpp"
|
||||
#include "qofinstance-p.h"
|
||||
|
||||
static QofLogModule log_module = QOF_MOD_ENGINE;
|
||||
@ -260,7 +261,7 @@ qof_instance_init (QofInstance *inst)
|
||||
|
||||
priv = GET_PRIVATE(inst);
|
||||
priv->book = NULL;
|
||||
inst->kvp_data = kvp_frame_new();
|
||||
inst->kvp_data = new KvpFrame;
|
||||
priv->last_update.tv_sec = 0;
|
||||
priv->last_update.tv_nsec = -1;
|
||||
priv->editlevel = 0;
|
||||
@ -335,8 +336,8 @@ qof_instance_finalize_real (GObject *instp)
|
||||
QofInstancePrivate *priv;
|
||||
QofInstance* inst = QOF_INSTANCE(instp);
|
||||
|
||||
kvp_frame_delete (inst->kvp_data);
|
||||
inst->kvp_data = NULL;
|
||||
delete inst->kvp_data;
|
||||
inst->kvp_data = nullptr;
|
||||
|
||||
priv = GET_PRIVATE(inst);
|
||||
priv->editlevel = 0;
|
||||
@ -587,7 +588,7 @@ qof_instance_set_slots (QofInstance *inst, KvpFrame *frm)
|
||||
priv = GET_PRIVATE(inst);
|
||||
if (inst->kvp_data && (inst->kvp_data != frm))
|
||||
{
|
||||
kvp_frame_delete(inst->kvp_data);
|
||||
delete inst->kvp_data;
|
||||
}
|
||||
|
||||
priv->dirty = TRUE;
|
||||
@ -665,7 +666,6 @@ qof_instance_get_dirty_flag (gconstpointer ptr)
|
||||
return GET_PRIVATE(ptr)->dirty;
|
||||
}
|
||||
|
||||
/* Watch out: This function is still used (as a "friend") in src/import-export/aqb/gnc-ab-kvp.c */
|
||||
void
|
||||
qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag)
|
||||
{
|
||||
@ -1069,19 +1069,19 @@ qof_commit_edit_part2(QofInstance *inst,
|
||||
gboolean
|
||||
qof_instance_has_kvp (QofInstance *inst)
|
||||
{
|
||||
return (inst->kvp_data != NULL && !kvp_frame_is_empty (inst->kvp_data));
|
||||
return (inst->kvp_data != NULL && !inst->kvp_data->empty());
|
||||
}
|
||||
|
||||
void
|
||||
qof_instance_set_kvp (QofInstance *inst, const gchar *key, const GValue *value)
|
||||
{
|
||||
kvp_frame_set_gvalue (inst->kvp_data, key, value);
|
||||
delete inst->kvp_data->set_path({key}, kvp_value_from_gvalue(value));
|
||||
}
|
||||
|
||||
void
|
||||
qof_instance_get_kvp (const QofInstance *inst, const gchar *key, GValue *value)
|
||||
{
|
||||
GValue *temp = kvp_frame_get_gvalue (inst->kvp_data, key);
|
||||
auto temp = gvalue_from_kvp_value (inst->kvp_data->get_slot(key));
|
||||
if (G_IS_VALUE (temp))
|
||||
{
|
||||
if (G_IS_VALUE (value))
|
||||
@ -1095,7 +1095,8 @@ qof_instance_get_kvp (const QofInstance *inst, const gchar *key, GValue *value)
|
||||
void
|
||||
qof_instance_copy_kvp (QofInstance *to, const QofInstance *from)
|
||||
{
|
||||
to->kvp_data = kvp_frame_copy(from->kvp_data);
|
||||
delete to->kvp_data;
|
||||
to->kvp_data = new KvpFrame(*from->kvp_data);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1107,40 +1108,39 @@ qof_instance_swap_kvp (QofInstance *a, QofInstance *b)
|
||||
int
|
||||
qof_instance_compare_kvp (const QofInstance *a, const QofInstance *b)
|
||||
{
|
||||
return kvp_frame_compare (a->kvp_data, b->kvp_data);
|
||||
return compare(a->kvp_data, b->kvp_data);
|
||||
}
|
||||
|
||||
char*
|
||||
qof_instance_kvp_as_string (const QofInstance *inst)
|
||||
{
|
||||
return kvp_frame_to_string (inst->kvp_data);
|
||||
//The std::string is a local temporary and doesn't survive this function.
|
||||
return g_strdup(inst->kvp_data->to_string().c_str());
|
||||
}
|
||||
|
||||
void
|
||||
qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
|
||||
const Timespec time, const char *key,
|
||||
const GncGUID *guid)
|
||||
const Timespec time, const char *key,
|
||||
const GncGUID *guid)
|
||||
{
|
||||
KvpFrame *slot = NULL, *container = NULL;
|
||||
/* We're in the process of being destroyed */
|
||||
g_return_if_fail (inst->kvp_data != NULL);
|
||||
|
||||
container = kvp_frame_new();
|
||||
kvp_frame_set_guid (container, key, guid);
|
||||
kvp_frame_set_timespec (container, "date", time);
|
||||
kvp_frame_add_frame_nc (inst->kvp_data, path, container);
|
||||
auto container = new KvpFrame;
|
||||
container->set(key, new KvpValue(const_cast<GncGUID*>(guid)));
|
||||
container->set("date", new KvpValue(time));
|
||||
delete inst->kvp_data->set_path({path}, new KvpValue(container));
|
||||
}
|
||||
|
||||
inline static gboolean
|
||||
kvp_match_guid (KvpValue *v, const char *key, const GncGUID *guid)
|
||||
{
|
||||
GncGUID *this_guid = NULL;
|
||||
KvpFrame *frame = kvp_value_get_frame (v);
|
||||
if (frame == NULL)
|
||||
if (v->get_type() != KVP_TYPE_FRAME)
|
||||
return FALSE;
|
||||
this_guid = kvp_frame_get_guid (frame, key);
|
||||
if (this_guid == NULL)
|
||||
auto frame = v->get<KvpFrame*>();
|
||||
auto val = frame->get_slot(key);
|
||||
if (val == nullptr || val->get_type() != KVP_TYPE_GUID)
|
||||
return FALSE;
|
||||
auto this_guid = val->get<GncGUID*>();
|
||||
|
||||
return guid_equal (this_guid, guid);
|
||||
}
|
||||
@ -1149,24 +1149,23 @@ gboolean
|
||||
qof_instance_kvp_has_guid (const QofInstance *inst, const char *path,
|
||||
const char* key, const GncGUID *guid)
|
||||
{
|
||||
KvpValue *v = NULL;
|
||||
g_return_val_if_fail (inst->kvp_data != NULL, FALSE);
|
||||
g_return_val_if_fail (guid != NULL, FALSE);
|
||||
|
||||
v = kvp_frame_get_value (inst->kvp_data, path);
|
||||
if (v == NULL) return FALSE;
|
||||
|
||||
switch (kvp_value_get_type (v))
|
||||
auto v = inst->kvp_data->get_slot(path);
|
||||
if (v == nullptr) return FALSE;
|
||||
|
||||
switch (v->get_type())
|
||||
{
|
||||
case KVP_TYPE_FRAME:
|
||||
return kvp_match_guid (v, key, guid);
|
||||
break;
|
||||
case KVP_TYPE_GLIST:
|
||||
{
|
||||
GList *list = kvp_value_get_glist (v), *node = NULL;
|
||||
for (node = list; node != NULL; node = node->next)
|
||||
auto list = v->get<GList*>();
|
||||
for (auto node = list; node != NULL; node = node->next)
|
||||
{
|
||||
KvpValue *val = static_cast<KvpValue*>(node->data);
|
||||
auto val = static_cast<KvpValue*>(node->data);
|
||||
if (kvp_match_guid (val, key, guid))
|
||||
{
|
||||
return TRUE;
|
||||
@ -1185,35 +1184,32 @@ void
|
||||
qof_instance_kvp_remove_guid (const QofInstance *inst, const char *path,
|
||||
const char *key, const GncGUID *guid)
|
||||
{
|
||||
KvpValue *v = NULL;
|
||||
g_return_if_fail (inst->kvp_data != NULL);
|
||||
g_return_if_fail (guid != NULL);
|
||||
|
||||
v = kvp_frame_get_value (inst->kvp_data, path);
|
||||
auto v = inst->kvp_data->get_slot(path);
|
||||
if (v == NULL) return;
|
||||
|
||||
switch (kvp_value_get_type (v))
|
||||
switch (v->get_type())
|
||||
{
|
||||
case KVP_TYPE_FRAME:
|
||||
if (kvp_match_guid (v, key, guid))
|
||||
{
|
||||
kvp_frame_replace_value_nc (inst->kvp_data, path, NULL);
|
||||
kvp_value_replace_frame_nc (v, NULL);
|
||||
kvp_value_delete (v);
|
||||
delete inst->kvp_data->set_path({path}, nullptr);
|
||||
delete v;
|
||||
}
|
||||
break;
|
||||
case KVP_TYPE_GLIST:
|
||||
{
|
||||
GList *list = kvp_value_get_glist (v), *node = NULL;
|
||||
for (node = list; node != NULL; node = node->next)
|
||||
auto list = v->get<GList*>();
|
||||
for (auto node = list; node != nullptr; node = node->next)
|
||||
{
|
||||
KvpValue *val = static_cast<KvpValue*>(node->data);
|
||||
auto val = static_cast<KvpValue*>(node->data);
|
||||
if (kvp_match_guid (val, key, guid))
|
||||
{
|
||||
kvp_value_replace_frame_nc (val, NULL);
|
||||
list = g_list_delete_link (list, node);
|
||||
kvp_value_replace_glist_nc (v, list);
|
||||
kvp_value_delete (val);
|
||||
v->set(list);
|
||||
delete val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1230,38 +1226,34 @@ void
|
||||
qof_instance_kvp_merge_guids (const QofInstance *target,
|
||||
const QofInstance *donor, const char *path)
|
||||
{
|
||||
KvpValue *v = NULL;
|
||||
g_return_if_fail (target != NULL);
|
||||
g_return_if_fail (donor != NULL);
|
||||
|
||||
if (! qof_instance_has_slot (donor, path)) return;
|
||||
v = kvp_frame_get_value (donor->kvp_data, path);
|
||||
auto v = donor->kvp_data->get_slot(path);
|
||||
if (v == NULL) return;
|
||||
|
||||
switch (kvp_value_get_type (v))
|
||||
auto target_val = target->kvp_data->get_slot(path);
|
||||
switch (v->get_type())
|
||||
{
|
||||
case KVP_TYPE_FRAME:
|
||||
kvp_frame_add_frame_nc (target->kvp_data, path,
|
||||
kvp_value_get_frame (v));
|
||||
kvp_value_replace_frame_nc (v, NULL);
|
||||
kvp_value_delete (v);
|
||||
if (target_val)
|
||||
target_val->add(v);
|
||||
else
|
||||
target->kvp_data->set_path({path}, v);
|
||||
donor->kvp_data->set(path, nullptr); //Contents moved, Don't delete!
|
||||
break;
|
||||
case KVP_TYPE_GLIST:
|
||||
{
|
||||
GList *list = kvp_value_get_glist (v), *node = NULL;
|
||||
while (list)
|
||||
if (target_val)
|
||||
{
|
||||
KvpValue *val = static_cast<KvpValue*>(list->data);
|
||||
kvp_frame_add_frame_nc (target->kvp_data, path,
|
||||
kvp_value_get_frame (val));
|
||||
kvp_value_replace_frame_nc (val, NULL);
|
||||
list = g_list_remove_link (list, list);
|
||||
kvp_value_delete (val);
|
||||
auto list = target_val->get<GList*>();
|
||||
list = g_list_concat(list, v->get<GList*>());
|
||||
target_val->set(list);
|
||||
}
|
||||
kvp_value_replace_glist_nc (v, list);
|
||||
kvp_value_delete (v);
|
||||
else
|
||||
target->kvp_data->set(path, v);
|
||||
donor->kvp_data->set(path, nullptr); //Contents moved, Don't delete!
|
||||
break;
|
||||
}
|
||||
default:
|
||||
PWARN ("Instance KVP on path %s contains the wrong type.", path);
|
||||
break;
|
||||
@ -1271,29 +1263,33 @@ qof_instance_kvp_merge_guids (const QofInstance *target,
|
||||
gboolean
|
||||
qof_instance_has_slot (const QofInstance *inst, const char *path)
|
||||
{
|
||||
return kvp_frame_get_value (inst->kvp_data, path) != NULL;
|
||||
return inst->kvp_data->get_slot(path) != NULL;
|
||||
}
|
||||
|
||||
void
|
||||
qof_instance_slot_delete (const QofInstance *inst, const char *path)
|
||||
{
|
||||
kvp_frame_set_frame_nc (inst->kvp_data, path, NULL);
|
||||
inst->kvp_data->set(path, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
qof_instance_slot_delete_if_empty (const QofInstance *inst, const char *path)
|
||||
{
|
||||
KvpFrame *frame = kvp_frame_get_frame (inst->kvp_data, path);
|
||||
if (frame && kvp_frame_is_empty (frame))
|
||||
kvp_frame_set_frame_nc (inst->kvp_data, path, NULL);
|
||||
auto slot = inst->kvp_data->get_slot(path);
|
||||
if (slot)
|
||||
{
|
||||
auto frame = slot->get<KvpFrame*>();
|
||||
if (frame && frame->empty())
|
||||
inst->kvp_data->set(path, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
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)
|
||||
{
|
||||
@ -1308,10 +1304,12 @@ 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;
|
||||
auto slot = inst->kvp_data->get_slot(path);
|
||||
if (slot == nullptr || slot->get_type() != KVP_TYPE_FRAME)
|
||||
return;
|
||||
auto frame = slot->get<KvpFrame*>();
|
||||
wrap_param new_data {proc, data};
|
||||
kvp_frame_for_each_slot(frame, wrap_gvalue_function, &new_data);
|
||||
frame->for_each_slot(wrap_gvalue_function, &new_data);
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ======================= */
|
||||
|
Loading…
Reference in New Issue
Block a user