From ff07762f612d16f7d7e366d1d4170f2276f03b54 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 27 Jun 2015 15:39:54 -0700 Subject: [PATCH] Move the KVP_TYPE enum to kvp-value.hpp. This had some extraordinary knock-on effects because C++11 treats enums very differently from C, so any C code that directly accessed the enum had to be converted to C++. That included test-engine-stuff, and because it quite sensibly builds as a ranlib archive instead of a shared library everything that uses it must at least link as C++. Fortunately automake takes care of doing this when the default extension for check_PROGRAMS is cpp, even if the source file is C. --- src/app-utils/test/Makefile.am | 4 +- src/app-utils/test/test-option-util.cpp | 4 +- ...e-amount.c => test-print-parse-amount.cpp} | 14 ++- src/app-utils/test/test-scm-query-string.c | 3 - src/backend/sql/gnc-slots-sql.cpp | 58 ++++----- src/backend/xml/sixtp-dom-generators.cpp | 24 ++-- src/backend/xml/test/test-kvp-frames.cpp | 2 +- src/engine/kvp-scm.cpp | 24 ++-- src/engine/test-core/test-engine-stuff.cpp | 62 ++++------ src/engine/test-core/test-engine-stuff.h | 5 +- src/engine/test/Makefile.am | 3 + .../test/{test-guid.c => test-guid.cpp} | 10 +- src/libqof/qof/gnc-aqbanking-templates.cpp | 2 +- src/libqof/qof/kvp-value.cpp | 93 ++++++++++---- src/libqof/qof/kvp-value.hpp | 22 +++- src/libqof/qof/kvp_frame.cpp | 116 +++--------------- src/libqof/qof/kvp_frame.h | 71 +---------- src/libqof/qof/qofinstance.cpp | 18 +-- src/libqof/qof/test/test-kvp-frame.cpp | 4 +- src/libqof/qof/test/test-kvp-value.cpp | 2 +- 20 files changed, 232 insertions(+), 309 deletions(-) rename src/app-utils/test/{test-print-parse-amount.c => test-print-parse-amount.cpp} (91%) rename src/engine/test/{test-guid.c => test-guid.cpp} (91%) diff --git a/src/app-utils/test/Makefile.am b/src/app-utils/test/Makefile.am index c0cf529317..5dbe1bb85f 100644 --- a/src/app-utils/test/Makefile.am +++ b/src/app-utils/test/Makefile.am @@ -8,6 +8,8 @@ check_PROGRAMS = \ test-sx \ test-app-utils +AM_DEFAULT_SOURCE_EXT = .cpp + TESTS = \ test-load-module \ ${check_PROGRAMS} @@ -16,7 +18,7 @@ test_exp_parser_SOURCES = \ test-exp-parser.c test_print_parse_amount_SOURCES = \ - test-print-parse-amount.c + test-print-parse-amount.cpp GNC_TEST_DEPS = --gnc-module-dir ${top_builddir}/src/engine \ --gnc-module-dir ${top_builddir}/src/app-utils \ diff --git a/src/app-utils/test/test-option-util.cpp b/src/app-utils/test/test-option-util.cpp index 16f0f35247..7bc7b9bcf7 100644 --- a/src/app-utils/test/test-option-util.cpp +++ b/src/app-utils/test/test-option-util.cpp @@ -228,8 +228,8 @@ test_option_save_book_currency (Fixture *fixture, gconstpointer pData) scm_cons (scm_from_utf8_string("GTQ"), scm_cons (scm_from_locale_symbol("fifo"), SCM_EOL))))); qof_book_save_options (book, gnc_option_db_save, odb, TRUE); - g_assert_cmpstr (kvp_frame_get_string(slots, "options/Accounts/Book Currency"), == , "GTQ"); - g_assert_cmpstr (kvp_frame_get_string(slots, "options/Accounts/Default Gains Policy"), == , "fifo"); + g_assert_cmpstr (slots->get_slot("options/Accounts/Book Currency")->get(), == , "GTQ"); + g_assert_cmpstr (slots->get_slot("options/Accounts/Default Gains Policy")->get(), == , "fifo"); gnc_option_db_destroy (odb); } diff --git a/src/app-utils/test/test-print-parse-amount.c b/src/app-utils/test/test-print-parse-amount.cpp similarity index 91% rename from src/app-utils/test/test-print-parse-amount.c rename to src/app-utils/test/test-print-parse-amount.cpp index 5f7a4e69df..83ac43c3b4 100644 --- a/src/app-utils/test/test-print-parse-amount.c +++ b/src/app-utils/test/test-print-parse-amount.cpp @@ -1,3 +1,5 @@ +extern "C" +{ #include "config.h" #include #include @@ -8,6 +10,7 @@ #include "test-engine-stuff.h" #include "test-stuff.h" #include +} static void test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line) @@ -16,13 +19,13 @@ test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line) const char *s; gboolean ok, print_ok; - gchar *msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW."; - gchar *log_domain = "gnc.gui"; - guint loglevel = G_LOG_LEVEL_WARNING, hdlr; - TestErrorStruct check = { loglevel, log_domain, msg }; + auto msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW."; + auto log_domain = "gnc.gui"; + auto loglevel = static_cast(G_LOG_LEVEL_WARNING); + auto check = test_error_struct_new (log_domain, loglevel, msg); /* Throws overflows during rounding step in xaccPrintAmount when the "fraction" is high. See bug 665707. */ - hdlr = g_log_set_handler (log_domain, loglevel, + auto hdlr = g_log_set_handler (log_domain, loglevel, (GLogFunc)test_checked_handler, &check); s = xaccPrintAmount (n, print_info); print_ok = (s && s[0] != '\0'); @@ -41,6 +44,7 @@ test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line) "start: %s, string %s, finish: %s (line %d)", gnc_numeric_to_string (n), s, gnc_numeric_to_string (n_parsed), line); + test_error_struct_free (check); } diff --git a/src/app-utils/test/test-scm-query-string.c b/src/app-utils/test/test-scm-query-string.c index c3bb1a59b5..e2831e8b09 100644 --- a/src/app-utils/test/test-scm-query-string.c +++ b/src/app-utils/test/test-scm-query-string.c @@ -96,9 +96,6 @@ main_helper (void *closure, int argc, char **argv) xaccLogDisable (); - /* double->string->double is not idempotent */ - kvp_exclude_type (KVP_TYPE_DOUBLE); - /* Initialize to a known RNG position */ srand(1); diff --git a/src/backend/sql/gnc-slots-sql.cpp b/src/backend/sql/gnc-slots-sql.cpp index 257d30fc7b..bbe299358b 100644 --- a/src/backend/sql/gnc-slots-sql.cpp +++ b/src/backend/sql/gnc-slots-sql.cpp @@ -64,7 +64,7 @@ typedef struct gboolean is_ok; /*@ dependent @*/ KvpFrame* pKvpFrame; - KvpValueType value_type; + KvpValue::Type value_type; GList *pList; context_t context; /*@ dependent @*/ @@ -77,7 +77,7 @@ static /*@ null @*/ gpointer get_obj_guid( gpointer pObject ); static void set_obj_guid( void ); static /*@ null @*/ gpointer get_path( gpointer pObject ); static void set_path( gpointer pObject, /*@ null @*/ gpointer pValue ); -static KvpValueType get_slot_type( gpointer pObject ); +static KvpValue::Type get_slot_type( gpointer pObject ); static void set_slot_type( gpointer pObject, /*@ null @*/ gpointer pValue ); static gint64 get_int64_val( gpointer pObject ); static void set_int64_val( gpointer pObject, gint64 pValue ); @@ -322,12 +322,12 @@ set_path( gpointer pObject, /*@ null @*/ gpointer pValue ) pInfo->path = g_string_new( (gchar*)pValue ); } -static KvpValueType +static KvpValue::Type get_slot_type( gpointer pObject ) { slot_info_t* pInfo = (slot_info_t*)pObject; - g_return_val_if_fail( pObject != NULL, KVP_TYPE_INVALID ); + g_return_val_if_fail( pObject != NULL, KvpValue::Type::INVALID ); // return (gpointer)kvp_value_get_type( pInfo->pKvpValue ); return pInfo->value_type; @@ -341,7 +341,7 @@ set_slot_type( gpointer pObject, /*@ null @*/ gpointer pValue ) g_return_if_fail( pObject != NULL ); g_return_if_fail( pValue != NULL ); - pInfo->value_type = static_cast(GPOINTER_TO_INT(pValue)); + pInfo->value_type = static_cast(GPOINTER_TO_INT(pValue)); } static gint64 @@ -351,7 +351,7 @@ get_int64_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, 0 ); - if ( pInfo->pKvpValue->get_type() == KVP_TYPE_GINT64 ) + if ( pInfo->pKvpValue->get_type() == KvpValue::Type::INT64 ) { return pInfo->pKvpValue->get(); } @@ -369,7 +369,7 @@ set_int64_val( gpointer pObject, gint64 value ) g_return_if_fail( pObject != NULL ); - if ( pInfo->value_type != KVP_TYPE_GINT64 ) return; + if ( pInfo->value_type != KvpValue::Type::INT64 ) return; pValue = new KvpValue{value}; set_slot_from_value( pInfo, pValue ); } @@ -381,7 +381,7 @@ get_string_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, NULL ); - if ( pInfo->pKvpValue->get_type() == KVP_TYPE_STRING ) + if ( pInfo->pKvpValue->get_type() == KvpValue::Type::STRING ) { return (gpointer)pInfo->pKvpValue->get(); } @@ -397,7 +397,7 @@ set_string_val( gpointer pObject, /*@ null @*/ gpointer pValue ) slot_info_t* pInfo = (slot_info_t*)pObject; g_return_if_fail( pObject != NULL ); - if (pInfo->value_type != KVP_TYPE_STRING || pValue == NULL) + if (pInfo->value_type != KvpValue::Type::STRING || pValue == NULL) return; auto string = g_strdup(static_cast(pValue)); auto value = new KvpValue{string}; @@ -412,7 +412,7 @@ get_double_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, NULL ); - if (pInfo->pKvpValue->get_type() == KVP_TYPE_DOUBLE) + if (pInfo->pKvpValue->get_type() == KvpValue::Type::DOUBLE) { d_val = pInfo->pKvpValue->get(); return (gpointer)&d_val; @@ -431,7 +431,7 @@ set_double_val( gpointer pObject, /*@ null @*/ gpointer pValue ) g_return_if_fail( pObject != NULL ); - if ( pInfo->value_type != KVP_TYPE_DOUBLE || pValue == NULL ) return; + if ( pInfo->value_type != KvpValue::Type::DOUBLE || pValue == NULL ) return; value = new KvpValue{*(static_cast(pValue))}; set_slot_from_value( pInfo, value ); } @@ -443,7 +443,7 @@ get_timespec_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, gnc_dmy2timespec( 1, 1, 1970 ) ); -//if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_TIMESPEC ) { +//if( kvp_value_get_type( pInfo->pKvpValue ) == KvpValue::Type::TIMESPEC ) { return pInfo->pKvpValue->get(); } @@ -455,7 +455,7 @@ set_timespec_val( gpointer pObject, Timespec ts ) g_return_if_fail( pObject != NULL ); - if ( pInfo->value_type != KVP_TYPE_TIMESPEC ) return; + if ( pInfo->value_type != KvpValue::Type::TIMESPEC ) return; value = new KvpValue{ts}; set_slot_from_value( pInfo, value ); } @@ -467,7 +467,7 @@ get_guid_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, NULL ); - if (pInfo->pKvpValue->get_type() == KVP_TYPE_GUID) + if (pInfo->pKvpValue->get_type() == KvpValue::Type::GUID) { return (gpointer)pInfo->pKvpValue->get(); } @@ -487,13 +487,13 @@ set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue ) switch ( pInfo->value_type) { - case KVP_TYPE_GUID: + case KvpValue::Type::GUID: { auto new_guid = guid_copy(static_cast(pValue)); set_slot_from_value(pInfo, new KvpValue{new_guid}); break; } - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: { slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue ); KvpValue *pValue = NULL; @@ -509,7 +509,7 @@ set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue ) g_free( key ); break; } - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: { slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue ) ; auto newFrame = new KvpFrame; @@ -554,7 +554,7 @@ get_numeric_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, gnc_numeric_zero() ); - if (pInfo->pKvpValue->get_type() == KVP_TYPE_NUMERIC) + if (pInfo->pKvpValue->get_type() == KvpValue::Type::NUMERIC) { return pInfo->pKvpValue->get(); } @@ -572,7 +572,7 @@ set_numeric_val( gpointer pObject, gnc_numeric value ) g_return_if_fail( pObject != NULL ); - if ( pInfo->value_type != KVP_TYPE_NUMERIC ) return; + if ( pInfo->value_type != KvpValue::Type::NUMERIC ) return; set_slot_from_value(pInfo, new KvpValue{value}); } @@ -584,7 +584,7 @@ get_gdate_val( gpointer pObject ) g_return_val_if_fail( pObject != NULL, NULL ); - if (pInfo->pKvpValue->get_type() == KVP_TYPE_GDATE) + if (pInfo->pKvpValue->get_type() == KvpValue::Type::GDATE) { date = pInfo->pKvpValue->get(); return &date; @@ -603,7 +603,7 @@ set_gdate_val( gpointer pObject, GDate* value ) g_return_if_fail( pObject != NULL ); - if ( pInfo->value_type != KVP_TYPE_GDATE ) return; + if ( pInfo->value_type != KvpValue::Type::GDATE ) return; set_slot_from_value(pInfo, new KvpValue{*value}); } @@ -653,7 +653,7 @@ save_slot( const gchar* key, KvpValue* value, gpointer data ) switch ( pSlot_info->value_type ) { - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: { auto pKvpFrame = value->get(); auto guid = guid_new(); @@ -672,7 +672,7 @@ save_slot( const gchar* key, KvpValue* value, gpointer data ) g_slice_free( slot_info_t, pNewInfo ); } break; - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: { GncGUID guid = guid_new_return(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); @@ -711,7 +711,7 @@ gboolean gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean is_infant, QofInstance *inst) { - slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KVP_TYPE_INVALID, NULL, FRAME, NULL, g_string_new(NULL) }; + slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) }; KvpFrame *pFrame = qof_instance_get_slots (inst); g_return_val_if_fail( be != NULL, FALSE ); @@ -739,7 +739,7 @@ gnc_sql_slots_delete( GncSqlBackend* be, const GncGUID* guid ) GncSqlResult* result; gchar guid_buf[GUID_ENCODING_LENGTH + 1]; GncSqlStatement* stmt; - slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KVP_TYPE_INVALID, NULL, FRAME, NULL, g_string_new(NULL) }; + slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) }; g_return_val_if_fail( be != NULL, FALSE ); g_return_val_if_fail( guid != NULL, FALSE ); @@ -747,7 +747,7 @@ gnc_sql_slots_delete( GncSqlBackend* be, const GncGUID* guid ) (void)guid_to_string_buff( guid, guid_buf ); buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s' and slot_type in ('%d', '%d') and not guid_val is null", - TABLE_NAME, guid_buf, KVP_TYPE_FRAME, KVP_TYPE_GLIST ); + TABLE_NAME, guid_buf, KvpValue::Type::FRAME, KvpValue::Type::GLIST ); stmt = gnc_sql_create_statement_from_sql( be, buf ); g_free( buf ); if ( stmt != NULL ) @@ -821,7 +821,7 @@ load_slot( slot_info_t *pInfo, GncSqlRow* row ) void gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst ) { - slot_info_t info = { NULL, NULL, TRUE, NULL, KVP_TYPE_INVALID, NULL, FRAME, NULL, g_string_new(NULL) }; + slot_info_t info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) }; g_return_if_fail( be != NULL ); g_return_if_fail( inst != NULL ); @@ -886,7 +886,7 @@ load_obj_guid( const GncSqlBackend* be, GncSqlRow* row ) static void load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll ) { - slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KVP_TYPE_INVALID, NULL, FRAME, NULL, NULL }; + slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, NULL }; const GncGUID* guid; QofInstance* inst; @@ -972,7 +972,7 @@ gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list ) static void load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn lookup_fn ) { - slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KVP_TYPE_INVALID, NULL, FRAME, NULL, NULL }; + slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, NULL }; const GncGUID* guid; QofInstance* inst; diff --git a/src/backend/xml/sixtp-dom-generators.cpp b/src/backend/xml/sixtp-dom-generators.cpp index 11ef34ae27..b0086c1ec5 100644 --- a/src/backend/xml/sixtp-dom-generators.cpp +++ b/src/backend/xml/sixtp-dom-generators.cpp @@ -260,7 +260,7 @@ add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val) switch (val->get_type()) { - case KVP_TYPE_STRING: + case KvpValue::Type::STRING: { auto newstr = g_strdup(val->get()); val_node = xmlNewTextChild(node, NULL, BAD_CAST tag, @@ -268,10 +268,10 @@ add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val) g_free (newstr); break; } - case KVP_TYPE_TIMESPEC: + case KvpValue::Type::TIMESPEC: val_node = NULL; break; - case KVP_TYPE_GDATE: + case KvpValue::Type::GDATE: { auto d = val->get(); val_node = gdate_to_dom_tree(tag, &d); @@ -285,30 +285,30 @@ add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val) switch (val->get_type()) { - case KVP_TYPE_GINT64: + case KvpValue::Type::INT64: add_text_to_node(val_node, "integer", g_strdup_printf("%" G_GINT64_FORMAT, val->get())); break; - case KVP_TYPE_DOUBLE: + case KvpValue::Type::DOUBLE: add_text_to_node(val_node, "double", double_to_string(val->get())); break; - case KVP_TYPE_NUMERIC: + case KvpValue::Type::NUMERIC: add_text_to_node(val_node, "numeric", gnc_numeric_to_string(val->get())); break; - case KVP_TYPE_STRING: + case KvpValue::Type::STRING: xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "string"); break; - case KVP_TYPE_GUID: + case KvpValue::Type::GUID: { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(val->get(), guidstr); add_text_to_node(val_node, "guid", guidstr); break; } - case KVP_TYPE_TIMESPEC: + case KvpValue::Type::TIMESPEC: { auto ts = val->get(); val_node = timespec_to_dom_tree (tag, &ts); @@ -316,10 +316,10 @@ add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val) xmlAddChild (node, val_node); break; } - case KVP_TYPE_GDATE: + case KvpValue::Type::GDATE: xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "gdate"); break; - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "list"); for (auto cursor = val->get(); cursor; cursor = cursor->next) { @@ -327,7 +327,7 @@ add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val) add_kvp_value_node(val_node, "slot:value", val); } break; - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: { xmlSetProp(val_node, BAD_CAST "type", BAD_CAST "frame"); diff --git a/src/backend/xml/test/test-kvp-frames.cpp b/src/backend/xml/test/test-kvp-frames.cpp index 7c13ca8d0c..5fd4c8f5e7 100644 --- a/src/backend/xml/test/test-kvp-frames.cpp +++ b/src/backend/xml/test/test-kvp-frames.cpp @@ -110,7 +110,7 @@ test_kvp_frames1(void) for (i = 0; i < 20; i++) { - auto test_val1 = get_random_kvp_value(i % KVP_TYPE_FRAME); + auto test_val1 = get_random_kvp_value(i % KvpValue::Type::FRAME); auto test_frame1 = new KvpFrame; auto test_key = get_random_string_without("/"); diff --git a/src/engine/kvp-scm.cpp b/src/engine/kvp-scm.cpp index 49e1174229..ca92cdcc4a 100644 --- a/src/engine/kvp-scm.cpp +++ b/src/engine/kvp-scm.cpp @@ -72,45 +72,47 @@ gnc_scm_to_kvp_value_ptr(SCM val) SCM gnc_kvp_value_ptr_to_scm(KvpValue* val) { - switch (kvp_value_get_type(val)) + if (val == nullptr) return SCM_BOOL_F; + + switch (val->get_type()) { - case KVP_TYPE_GINT64: + case KvpValue::Type::INT64: return scm_from_int64(val->get()); break; - case KVP_TYPE_DOUBLE: + case KvpValue::Type::DOUBLE: return scm_from_double (val->get()); break; - case KVP_TYPE_NUMERIC: + case KvpValue::Type::NUMERIC: return gnc_numeric_to_scm(val->get()); break; - case KVP_TYPE_STRING: + case KvpValue::Type::STRING: { auto string = val->get(); return string ? scm_from_utf8_string(string) : SCM_BOOL_F; break; } - case KVP_TYPE_GUID: + case KvpValue::Type::GUID: { - auto tempguid = kvp_value_get_guid(val); + auto tempguid = val->get(); return gnc_guid2scm(*tempguid); } break; - case KVP_TYPE_TIMESPEC: + case KvpValue::Type::TIMESPEC: return gnc_timespec2timepair(val->get()); break; - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: { auto frame = val->get(); if (frame != nullptr) return SWIG_NewPointerObj(frame, SWIG_TypeQuery("_p_KvpFrame"), 0); } break; - case KVP_TYPE_GDATE: + case KvpValue::Type::GDATE: return gnc_timespec2timepair(gdate_to_timespec(val->get())); /* FIXME: handle types below */ - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: default: break; } diff --git a/src/engine/test-core/test-engine-stuff.cpp b/src/engine/test-core/test-engine-stuff.cpp index 6955f7b808..3cae5df972 100644 --- a/src/engine/test-core/test-engine-stuff.cpp +++ b/src/engine/test-core/test-engine-stuff.cpp @@ -105,8 +105,8 @@ set_max_kvp_frame_elements (gint max_kvp_frame_elements) kvp_frame_max_elements = MAX (max_kvp_frame_elements, 1); } -void -kvp_exclude_type (KvpValueType kvp_type) +static void +kvp_exclude_type (KvpValue::Type kvp_type) { gint *key; @@ -120,7 +120,7 @@ kvp_exclude_type (KvpValueType kvp_type) } static gboolean -kvp_type_excluded (KvpValueType kvp_type) +kvp_type_excluded (KvpValue::Type kvp_type) { gint key = kvp_type; @@ -238,25 +238,25 @@ static KvpFrame* get_random_kvp_frame_depth (gint depth); static KvpValue* get_random_kvp_value_depth (int type, gint depth) { - KvpValueType datype; + KvpValue::Type datype; KvpValue *ret; if (type == -1) { - datype = static_cast(get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME)); + datype = static_cast(get_random_int_in_range(KvpValue::Type::INT64, KvpValue::Type::FRAME)); } else if (type == -2) { - datype = static_cast(get_random_int_in_range(KVP_TYPE_GINT64, KVP_TYPE_FRAME - 1)); + datype = static_cast(get_random_int_in_range(KvpValue::Type::INT64, KvpValue::Type::FRAME - 1)); } else - datype = static_cast(type); - - if (datype == KVP_TYPE_FRAME && depth >= kvp_max_depth) + datype = static_cast(type); + + if (datype == KvpValue::Type::FRAME && depth >= kvp_max_depth) return NULL; - if (datype == KVP_TYPE_GLIST && depth >= kvp_max_depth) + if (datype == KvpValue::Type::GLIST && depth >= kvp_max_depth) return NULL; if (kvp_type_excluded (datype)) @@ -264,57 +264,50 @@ get_random_kvp_value_depth (int type, gint depth) switch (datype) { - case KVP_TYPE_GINT64: - ret = kvp_value_new_gint64(get_random_gint64()); + case KvpValue::Type::INT64: + ret = new KvpValue(get_random_gint64()); break; - case KVP_TYPE_DOUBLE: + case KvpValue::Type::DOUBLE: ret = NULL; break; - case KVP_TYPE_NUMERIC: - ret = kvp_value_new_gnc_numeric(get_random_gnc_numeric(GNC_DENOM_AUTO)); + case KvpValue::Type::NUMERIC: + ret = new KvpValue(get_random_gnc_numeric(GNC_DENOM_AUTO)); break; - case KVP_TYPE_STRING: + case KvpValue::Type::STRING: { gchar *tmp_str; tmp_str = get_random_string(); if (!tmp_str) return NULL; - ret = kvp_value_new_string(tmp_str); - g_free(tmp_str); + ret = new KvpValue(tmp_str); } break; - case KVP_TYPE_GUID: + case KvpValue::Type::GUID: { - GncGUID *tmp_guid; - tmp_guid = get_random_guid(); - ret = kvp_value_new_guid(tmp_guid); - g_free(tmp_guid); + return new KvpValue(get_random_guid()); } break; - case KVP_TYPE_TIMESPEC: + case KvpValue::Type::TIMESPEC: { Timespec *ts = get_random_timespec(); - ret = kvp_value_new_timespec (*ts); + ret = new KvpValue(*ts); g_free(ts); } break; - case KVP_TYPE_GLIST: - ret = kvp_value_new_glist_nc(get_random_glist_depth (depth + 1)); + case KvpValue::Type::GLIST: + ret = new KvpValue(get_random_glist_depth (depth + 1)); break; - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: { - KvpFrame *tmp_frame; - tmp_frame = get_random_kvp_frame_depth(depth + 1); - ret = kvp_value_new_frame(tmp_frame); - kvp_frame_delete(tmp_frame); + return new KvpValue(get_random_kvp_frame_depth(depth + 1)); } break; @@ -328,14 +321,13 @@ get_random_kvp_value_depth (int type, gint depth) static KvpFrame* get_random_kvp_frame_depth (gint depth) { - KvpFrame *ret; int vals_to_add; gboolean val_added; if (depth >= kvp_max_depth) return NULL; - ret = kvp_frame_new(); + auto ret = new KvpFrame; vals_to_add = get_random_int_in_range(1, kvp_frame_max_elements); val_added = FALSE; @@ -367,7 +359,7 @@ get_random_kvp_frame_depth (gint depth) val_added = TRUE; - kvp_frame_set_slot_nc(ret, key, val); + ret->set_path(key, val); g_free(key); } diff --git a/src/engine/test-core/test-engine-stuff.h b/src/engine/test-core/test-engine-stuff.h index 73360b460e..f5ab980e45 100644 --- a/src/engine/test-core/test-engine-stuff.h +++ b/src/engine/test-core/test-engine-stuff.h @@ -13,11 +13,12 @@ extern "C" #include #include "qof.h" -#include #include "Query.h" #include "gnc-pricedb.h" #include "SchedXaction.h" +typedef struct KvpValueImpl KvpValue; +typedef struct KvpFrameImpl KvpFrame; Timespec* get_random_timespec(void); void random_timespec_zero_nsec (gboolean zero_nsec); void random_timespec_usec_resolution (gboolean usec_resolution); @@ -36,7 +37,7 @@ KvpFrame* get_random_kvp_frame(void); gnc_numeric get_random_gnc_numeric(int64_t); GncGUID* get_random_guid(void); -void kvp_exclude_type (KvpValueType kvp_type); +//void kvp_exclude_type (KvpValueType kvp_type); void set_max_kvp_depth (gint max_kvp_depth); void set_max_kvp_frame_elements (gint max_kvp_frame_elements); void set_max_account_tree_depth (gint max_tree_depth); diff --git a/src/engine/test/Makefile.am b/src/engine/test/Makefile.am index 7366d7561a..545a5efce3 100644 --- a/src/engine/test/Makefile.am +++ b/src/engine/test/Makefile.am @@ -23,6 +23,8 @@ LDADD = \ ${top_builddir}/src/core-utils/libgnc-core-utils.la \ ${GLIB_LIBS} +test_guid_SOURCES = test-guid.cpp + # these tests are ordered kind more or less in the order # that they should be executed, with more basic tests coming first. # @@ -73,6 +75,7 @@ TESTS_ENVIRONMENT = \ $(shell ${abs_top_srcdir}/src/gnc-test-env.pl --noexports ${GNC_TEST_DEPS}) check_PROGRAMS = ${TEST_GROUP_1} ${TEST_GROUP_2} +AM_DEFAULT_SOURCE_EXT = .cpp TESTS = ${TEST_GROUP_1} test-create-account ${TEST_GROUP_2} diff --git a/src/engine/test/test-guid.c b/src/engine/test/test-guid.cpp similarity index 91% rename from src/engine/test/test-guid.c rename to src/engine/test/test-guid.cpp index fdb2408eb3..923e59da89 100644 --- a/src/engine/test/test-guid.c +++ b/src/engine/test/test-guid.cpp @@ -25,7 +25,8 @@ * Try to create duplicate GncGUID's, which should never happen. * */ - +extern "C" +{ #include "config.h" #include #include @@ -33,7 +34,7 @@ #include "test-stuff.h" #include "test-engine-stuff.h" #include "qof.h" - +} #define NENT 50123 static void test_null_guid(void) @@ -70,9 +71,10 @@ run_test (void) for (i = 0; i < NENT; i++) { - ent = g_object_new(QOF_TYPE_INSTANCE, NULL); + ent = static_cast(g_object_new(QOF_TYPE_INSTANCE, NULL)); guid_replace(&guid); - ent = g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, NULL); + ent = static_cast(g_object_new(QOF_TYPE_INSTANCE, + "guid", &guid, NULL)); do_test ((NULL == qof_collection_lookup_entity (col, &guid)), "duplicate guid"); ent->e_type = type; diff --git a/src/libqof/qof/gnc-aqbanking-templates.cpp b/src/libqof/qof/gnc-aqbanking-templates.cpp index 21bd05760a..6c5c526d75 100644 --- a/src/libqof/qof/gnc-aqbanking-templates.cpp +++ b/src/libqof/qof/gnc-aqbanking-templates.cpp @@ -105,7 +105,7 @@ private: KvpFrame* _GncABTransTempl::make_kvp_frame() { - auto frame = kvp_frame_new(); + auto frame = new KvpFrame; 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())); diff --git a/src/libqof/qof/kvp-value.cpp b/src/libqof/qof/kvp-value.cpp index ce79dfc310..bd07419811 100644 --- a/src/libqof/qof/kvp-value.cpp +++ b/src/libqof/qof/kvp-value.cpp @@ -71,29 +71,29 @@ KvpValueImpl::add(KvpValueImpl * val) noexcept return new KvpValueImpl(list); } -KvpValueType +KvpValue::Type KvpValueImpl::get_type() const noexcept { if (datastore.type() == typeid(int64_t)) - return KvpValueType::KVP_TYPE_GINT64; + return KvpValue::Type::INT64; else if (datastore.type() == typeid(double)) - return KvpValueType::KVP_TYPE_DOUBLE; + return KvpValue::Type::DOUBLE; else if (datastore.type() == typeid(gnc_numeric)) - return KvpValueType::KVP_TYPE_NUMERIC; + return KvpValue::Type::NUMERIC; else if (datastore.type() == typeid(const gchar *)) - return KvpValueType::KVP_TYPE_STRING; + return KvpValue::Type::STRING; else if (datastore.type() == typeid(GncGUID *)) - return KvpValueType::KVP_TYPE_GUID; + return KvpValue::Type::GUID; else if (datastore.type() == typeid(Timespec)) - return KvpValueType::KVP_TYPE_TIMESPEC; + return KvpValue::Type::TIMESPEC; else if (datastore.type() == typeid(GList *)) - return KvpValueType::KVP_TYPE_GLIST; + return KvpValue::Type::GLIST; else if (datastore.type() == typeid(KvpFrameImpl *)) - return KvpValueType::KVP_TYPE_FRAME; + return KvpValue::Type::FRAME; else if (datastore.type() == typeid(GDate)) - return KvpValueType::KVP_TYPE_GDATE; + return KvpValue::Type::GDATE; - return KVP_TYPE_INVALID; + return KvpValue::Type::INVALID; } KvpFrame * @@ -129,14 +129,7 @@ struct to_string_visitor : boost::static_visitor void operator()(KvpFrame * val) { - auto tmp1 = kvp_frame_to_string(val); - output << "KVP_VALUE_FRAME("; - if (tmp1) - { - output << tmp1; - g_free(tmp1); - } - output << ")"; + output << "KVP_VALUE_FRAME(" << val->to_string() << ")"; } void operator()(GDate val) @@ -224,6 +217,55 @@ KvpValueImpl::to_string() const noexcept return g_strdup(ret.str().c_str()); } +static int +kvp_glist_compare(const GList * list1, const GList * list2) +{ + const GList *lp1; + const GList *lp2; + + if (list1 == list2) return 0; + + /* Nothing is always less than something */ + if (!list1 && list2) return -1; + if (list1 && !list2) return 1; + + lp1 = list1; + lp2 = list2; + while (lp1 && lp2) + { + KvpValue *v1 = (KvpValue *) lp1->data; + KvpValue *v2 = (KvpValue *) lp2->data; + gint vcmp = compare(v1, v2); + if (vcmp != 0) return vcmp; + lp1 = lp1->next; + lp2 = lp2->next; + } + if (!lp1 && lp2) return -1; + if (!lp2 && lp1) return 1; + return 0; +} + +static GList * +kvp_glist_copy(const GList * list) +{ + GList * retval = NULL; + GList * lptr; + + if (!list) return retval; + + /* Duplicate the backbone of the list (this duplicates the POINTERS + * to the values; we need to deep-copy the values separately) */ + retval = g_list_copy((GList *) list); + + /* This step deep-copies the values */ + for (lptr = retval; lptr; lptr = lptr->next) + { + lptr->data = new KvpValue(*static_cast(lptr->data)); + } + + return retval; +} + struct compare_visitor : boost::static_visitor { template @@ -269,7 +311,7 @@ template <> int compare_visitor::operator()(GList * const & one, GList * const & } template <> int compare_visitor::operator()(KvpFrame * const & one, KvpFrame * const & two) const { - return kvp_frame_compare(one, two); + return compare(one, two); } template <> int compare_visitor::operator()(double const & one, double const & two) const { @@ -307,10 +349,16 @@ struct delete_visitor : boost::static_visitor operator()(T &) { /*do nothing*/ } }; +static void +destroy_value(void* item) +{ + delete static_cast(item); +} + template <> void delete_visitor::operator()(GList * & value) { - kvp_glist_delete(value); + g_list_free_full(value, destroy_value); } template <> void delete_visitor::operator()(gchar * & value) @@ -344,7 +392,8 @@ KvpValueImpl::duplicate(const KvpValueImpl& other) noexcept else if (other.datastore.type() == typeid(GList*)) this->datastore = kvp_glist_copy(other.get()); else if (other.datastore.type() == typeid(KvpFrame*)) - this->datastore = kvp_frame_copy(other.get()); + this->datastore = new KvpFrame(*other.get()); else this->datastore = other.datastore; } + diff --git a/src/libqof/qof/kvp-value.hpp b/src/libqof/qof/kvp-value.hpp index c7a96e1f42..3b53167c54 100644 --- a/src/libqof/qof/kvp-value.hpp +++ b/src/libqof/qof/kvp-value.hpp @@ -34,11 +34,27 @@ extern "C" #include #endif #include -#include "kvp_frame.h" +//Must be a struct because it's exposed to C so that it can in turn be +//translated to/from Scheme. struct KvpValueImpl { public: + enum Type + { + INVALID = -1, + INT64 = 1, /**< QOF_TYPE_INT64 gint64 */ + DOUBLE, /**< QOF_TYPE_DOUBLE gdouble */ + NUMERIC, /**< QOF_TYPE_NUMERIC */ + STRING, /**< QOF_TYPE_STRING gchar* */ + GUID, /**< QOF_TYPE_GUID */ + TIMESPEC, /**< QOF_TYPE_DATE */ + PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */ + GLIST, /**< no QOF equivalent. */ + FRAME, /**< no QOF equivalent. */ + GDATE, /**< no QOF equivalent. */ + }; + /** * Performs a deep copy */ @@ -90,7 +106,7 @@ struct KvpValueImpl */ KvpValueImpl * add (KvpValueImpl *) noexcept; - KvpValueType get_type() const noexcept; + KvpValueImpl::Type get_type() const noexcept; char * to_string() const noexcept; @@ -137,5 +153,7 @@ KvpValueImpl::set(T val) noexcept { this->datastore = val; } +extern "C" GType gnc_value_list_get_type (void); +#define GNC_TYPE_VALUE_LIST (gnc_value_list_get_type ()) #endif diff --git a/src/libqof/qof/kvp_frame.cpp b/src/libqof/qof/kvp_frame.cpp index 475ae5a891..8a8cdafef5 100644 --- a/src/libqof/qof/kvp_frame.cpp +++ b/src/libqof/qof/kvp_frame.cpp @@ -30,6 +30,7 @@ extern "C" #include #include #include +#include "kvp_frame.h" } #include "kvp-value.hpp" @@ -39,6 +40,9 @@ extern "C" #include #include +/* This static indicates the debugging module that this .o belongs to. */ +static QofLogModule log_module = "qof.kvp"; + static const char delim = '/'; KvpFrameImpl::KvpFrameImpl(const KvpFrameImpl & rhs) noexcept @@ -99,7 +103,7 @@ walk_path_or_nullptr(const KvpFrameImpl* frame, Path& path) for(auto key:path) { auto slot = cur_frame->get_slot(key.c_str()); - if (slot == nullptr || slot->get_type() != KVP_TYPE_FRAME) + if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) return nullptr; cur_frame = slot->get(); } @@ -130,7 +134,7 @@ walk_path_and_create(KvpFrameImpl* frame, Path path) continue; } auto slot = frame->get_slot(key.c_str()); - if (slot == nullptr || slot->get_type() != KVP_TYPE_FRAME) + if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) { auto new_frame = new KvpFrame; delete frame->set(key.c_str(), new KvpValue{new_frame}); @@ -271,9 +275,6 @@ int compare(const KvpFrameImpl & one, const KvpFrameImpl & two) noexcept return 0; } -/* This static indicates the debugging module that this .o belongs to. */ -static QofLogModule log_module = QOF_MOD_KVP; - KvpFrame * kvp_frame_new(void) { @@ -940,78 +941,9 @@ kvp_frame_get_slot_path_gslist (KvpFrame *frame, return NULL; } -/* ******************************************************************* - * kvp glist functions - ********************************************************************/ - -void -kvp_glist_delete(GList * list) -{ - GList *node; - if (!list) return; - - /* Delete the data in the list */ - for (node = list; node; node = node->next) - { - KvpValue *val = static_cast(node->data); - kvp_value_delete(val); - } - - /* Free the backbone */ - g_list_free(list); -} - -GList * -kvp_glist_copy(const GList * list) -{ - GList * retval = NULL; - GList * lptr; - - if (!list) return retval; - - /* Duplicate the backbone of the list (this duplicates the POINTERS - * to the values; we need to deep-copy the values separately) */ - retval = g_list_copy((GList *) list); - - /* This step deep-copies the values */ - for (lptr = retval; lptr; lptr = lptr->next) - { - lptr->data = kvp_value_copy(static_cast(lptr->data)); - } - - return retval; -} - -gint -kvp_glist_compare(const GList * list1, const GList * list2) -{ - const GList *lp1; - const GList *lp2; - - if (list1 == list2) return 0; - - /* Nothing is always less than something */ - if (!list1 && list2) return -1; - if (list1 && !list2) return 1; - - lp1 = list1; - lp2 = list2; - while (lp1 && lp2) - { - KvpValue *v1 = (KvpValue *) lp1->data; - KvpValue *v2 = (KvpValue *) lp2->data; - gint vcmp = kvp_value_compare(v1, v2); - if (vcmp != 0) return vcmp; - lp1 = lp1->next; - lp2 = lp2->next; - } - if (!lp1 && lp2) return -1; - if (!lp2 && lp1) return 1; - return 0; -} /* ******************************************************************* - * KvpValue functions + * Kvpvalue functions ********************************************************************/ KvpValue * @@ -1069,7 +1001,7 @@ KvpValue * kvp_value_new_glist(const GList * value) { if (!value) return {}; - return new KvpValueImpl{kvp_glist_copy(value)}; + return nullptr; } KvpValue * @@ -1101,14 +1033,6 @@ kvp_value_delete(KvpValue * value) delete realvalue; } -KvpValueType -kvp_value_get_type(const KvpValue * oldval) -{ - if (!oldval) return KVP_TYPE_INVALID; - const KvpValueImpl * value {static_cast(oldval)}; - return value->get_type(); -} - int64_t kvp_value_get_gint64(const KvpValue * ovalue) { @@ -1318,44 +1242,40 @@ gvalue_from_kvp_value (const KvpValue *kval) if (kval == NULL) return NULL; val = g_slice_new0 (GValue); - switch (kvp_value_get_type(kval)) + switch (kval->get_type()) { - case KVP_TYPE_GINT64: + case KvpValue::Type::INT64: g_value_init (val, G_TYPE_INT64); g_value_set_int64 (val, kvp_value_get_gint64 (kval)); break; - case KVP_TYPE_DOUBLE: + case KvpValue::Type::DOUBLE: g_value_init (val, G_TYPE_DOUBLE); g_value_set_double (val, kvp_value_get_double (kval)); break; - case KVP_TYPE_BOOLEAN: - g_value_init (val, G_TYPE_BOOLEAN); - g_value_set_boolean (val, kvp_value_get_boolean (kval)); - break; - case KVP_TYPE_NUMERIC: + case KvpValue::Type::NUMERIC: g_value_init (val, GNC_TYPE_NUMERIC); num = kvp_value_get_numeric (kval); g_value_set_boxed (val, &num); break; - case KVP_TYPE_STRING: + case KvpValue::Type::STRING: g_value_init (val, G_TYPE_STRING); g_value_set_string (val, kvp_value_get_string (kval)); break; - case KVP_TYPE_GUID: + case KvpValue::Type::GUID: g_value_init (val, GNC_TYPE_GUID); g_value_set_boxed (val, kvp_value_get_guid (kval)); break; - case KVP_TYPE_TIMESPEC: + case KvpValue::Type::TIMESPEC: g_value_init (val, GNC_TYPE_TIMESPEC); tm = kvp_value_get_timespec (kval); g_value_set_boxed (val, &tm); break; - case KVP_TYPE_GDATE: + case KvpValue::Type::GDATE: g_value_init (val, G_TYPE_DATE); gdate = kvp_value_get_gdate (kval); g_value_set_boxed (val, &gdate); break; - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: { GList *gvalue_list = NULL; GList *kvp_list = kvp_value_get_glist (kval); @@ -1366,7 +1286,7 @@ gvalue_from_kvp_value (const KvpValue *kval) break; } /* No transfer of KVP frames outside of QofInstance-derived classes! */ - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: PWARN ("Error! Attempt to transfer KvpFrame!"); default: PWARN ("Error! Invalid KVP Transfer Request!"); diff --git a/src/libqof/qof/kvp_frame.h b/src/libqof/qof/kvp_frame.h index 190aa94a60..3b02e6701e 100644 --- a/src/libqof/qof/kvp_frame.h +++ b/src/libqof/qof/kvp_frame.h @@ -22,7 +22,7 @@ * A KvpFrame is a set of associations between character strings * (keys) and KvpValue structures. A KvpValue is a union with - * possible types enumerated in the KvpValueType enum, and includes, + * possible types enumerated in the KvpValue::Type enum, and includes, * among other things, ints, doubles, strings, guid's, lists, time * and numeric values. KvpValues may also be other frames, so * KVP is inherently hierarchical. @@ -75,44 +75,8 @@ extern "C" /** Opaque frame structure */ typedef struct KvpFrameImpl KvpFrame; -/** A KvpValue is a union with possible types enumerated in the - * KvpValueType enum. */ typedef struct KvpValueImpl KvpValue; -/** \brief possible types in the union KvpValue - * \todo : People have asked for boolean values, - * e.g. in xaccAccountSetAutoInterestXfer - * - * \todo In the long run, this should be synchronized with the - * core QOF types, which in turn should be synced to the g_types - * in GLib. Unfortunately, this requires writing a pile of code - * to handle all of the different cases. - * An alternative might be to make kvp values inherit from the - * core g_types (i.e. add new core g_types) ?? - */ -typedef enum -{ - KVP_TYPE_INVALID = -1, - KVP_TYPE_GINT64 = 1, /**< QOF_TYPE_INT64 gint64 */ - KVP_TYPE_DOUBLE, /**< QOF_TYPE_DOUBLE gdouble */ - KVP_TYPE_NUMERIC, /**< QOF_TYPE_NUMERIC */ - KVP_TYPE_STRING, /**< QOF_TYPE_STRING gchar* */ - KVP_TYPE_GUID, /**< QOF_TYPE_GUID */ - KVP_TYPE_TIMESPEC, /**< QOF_TYPE_DATE */ - KVP_TYPE_PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */ - KVP_TYPE_GLIST, /**< no QOF equivalent. */ - KVP_TYPE_FRAME, /**< no QOF equivalent. */ - KVP_TYPE_GDATE, /**< no QOF equivalent. */ - KVP_TYPE_BOOLEAN, /**< QOF_TYPE_BOOLEAN gboolean */ -} KvpValueType; - -/** \deprecated Deprecated backwards compat token - -do \b not use these in new code. - */ -/** \deprecated Deprecated backwards compat token */ -#define kvp_value_t KvpValueType - /** @name KvpFrame Constructors @{ */ @@ -420,31 +384,6 @@ gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb); gint double_compare(double v1, double v2); /** @} */ -/** @name KvpValue List Convenience Functions - - You probably shouldn't be using these low-level routines - - kvp_glist_compare() compares GLists of kvp_values (not to - be confused with GLists of something else): it iterates over - the list elements, performing a kvp_value_compare on each. - @{ -*/ -gint kvp_glist_compare(const GList * list1, const GList * list2); - -/** kvp_glist_copy() performs a deep copy of a GList of - * kvp_values (not to be confused with GLists of something - * else): same as mapping kvp_value_copy() over the elements and - * then copying the spine. - */ -GList * kvp_glist_copy(const GList * list); - -/** kvp_glist_delete() performs a deep delete of a GList of - * kvp_values (not to be confused with GLists of something - * else): same as mapping * kvp_value_delete() over the elements - * and then deleting the GList. - */ -void kvp_glist_delete(GList * list); -/** @} */ /** @name KvpValue Constructors @@ -509,9 +448,6 @@ GList * kvp_value_replace_glist_nc(KvpValue *value, GList *newlist); @{ */ -KvpValueType kvp_value_get_type(const KvpValue * value); - - /** Value accessors. Those for GncGUID, GList, KvpFrame and * string are non-copying -- the caller can modify the value * directly. Just don't free it, or you screw up everything. @@ -642,10 +578,7 @@ void kvp_frame_set_gvalue (KvpFrame *frame, const gchar *key, const GValue *valu */ void gnc_gvalue_free (GValue *value); -GType gnc_value_list_get_type (void); -#define GNC_TYPE_VALUE_LIST (gnc_value_list_get_type ()) - -/** @} */ + /** @} */ #ifdef __cplusplus } #endif diff --git a/src/libqof/qof/qofinstance.cpp b/src/libqof/qof/qofinstance.cpp index e04332c0c3..080ab25105 100644 --- a/src/libqof/qof/qofinstance.cpp +++ b/src/libqof/qof/qofinstance.cpp @@ -1134,11 +1134,11 @@ qof_instance_kvp_add_guid (const QofInstance *inst, const char* path, inline static gboolean kvp_match_guid (KvpValue *v, const char *key, const GncGUID *guid) { - if (v->get_type() != KVP_TYPE_FRAME) + if (v->get_type() != KvpValue::Type::FRAME) return FALSE; auto frame = v->get(); auto val = frame->get_slot(key); - if (val == nullptr || val->get_type() != KVP_TYPE_GUID) + if (val == nullptr || val->get_type() != KvpValue::Type::GUID) return FALSE; auto this_guid = val->get(); @@ -1157,10 +1157,10 @@ qof_instance_kvp_has_guid (const QofInstance *inst, const char *path, switch (v->get_type()) { - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: return kvp_match_guid (v, key, guid); break; - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: { auto list = v->get(); for (auto node = list; node != NULL; node = node->next) @@ -1192,14 +1192,14 @@ qof_instance_kvp_remove_guid (const QofInstance *inst, const char *path, switch (v->get_type()) { - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: if (kvp_match_guid (v, key, guid)) { delete inst->kvp_data->set_path({path}, nullptr); delete v; } break; - case KVP_TYPE_GLIST: + case KvpValue::Type::GLIST: { auto list = v->get(); for (auto node = list; node != nullptr; node = node->next) @@ -1236,14 +1236,14 @@ qof_instance_kvp_merge_guids (const QofInstance *target, auto target_val = target->kvp_data->get_slot(path); switch (v->get_type()) { - case KVP_TYPE_FRAME: + case KvpValue::Type::FRAME: 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: + case KvpValue::Type::GLIST: if (target_val) { auto list = target_val->get(); @@ -1305,7 +1305,7 @@ qof_instance_foreach_slot (const QofInstance *inst, const char* path, void* data) { auto slot = inst->kvp_data->get_slot(path); - if (slot == nullptr || slot->get_type() != KVP_TYPE_FRAME) + if (slot == nullptr || slot->get_type() != KvpValue::Type::FRAME) return; auto frame = slot->get(); wrap_param new_data {proc, data}; diff --git a/src/libqof/qof/test/test-kvp-frame.cpp b/src/libqof/qof/test/test-kvp-frame.cpp index 3082474235..4f30dd8f5e 100644 --- a/src/libqof/qof/test/test-kvp-frame.cpp +++ b/src/libqof/qof/test/test-kvp-frame.cpp @@ -144,7 +144,7 @@ TEST_F (KvpFrameTest, GetKeys) assert_contains (keys, k1); auto frameval = t_root.get_slot(k1); - ASSERT_EQ(frameval->get_type(), KVP_TYPE_FRAME); + ASSERT_EQ(frameval->get_type(), KvpValue::Type::FRAME); keys = frameval->get()->get_keys(); assert_contains (keys, k2); assert_contains (keys, k3); @@ -158,7 +158,7 @@ TEST_F (KvpFrameTest, GetLocalSlot) auto k4 = "top/first"; auto frameval = t_root.get_slot("top"); - ASSERT_EQ(frameval->get_type(), KVP_TYPE_FRAME); + ASSERT_EQ(frameval->get_type(), KvpValue::Type::FRAME); auto f1 = frameval->get(); EXPECT_EQ (t_int_val, f1->get_slot(k1)); EXPECT_EQ (t_str_val, f1->get_slot(k2)); diff --git a/src/libqof/qof/test/test-kvp-value.cpp b/src/libqof/qof/test/test-kvp-value.cpp index 537a6a0382..ef8bd93f74 100644 --- a/src/libqof/qof/test/test-kvp-value.cpp +++ b/src/libqof/qof/test/test-kvp-value.cpp @@ -65,7 +65,7 @@ TEST (KvpValueTest, Add) auto v4 = new KvpValueImpl {*v3}; auto new_one = v3->add (v4); EXPECT_NE (new_one, v3); - EXPECT_EQ (new_one->get_type (), KvpValueType::KVP_TYPE_GLIST); + EXPECT_EQ (new_one->get_type (), KvpValue::Type::GLIST); EXPECT_NE (new_one->get (), nullptr); /* also deletes v3 and v4 because they're "in" new_one */ delete new_one;