static int vendor_get_count (QofBook* book) { int count = 0; qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; }
static void test_qof_object_foreach( Fixture *fixture, gconstpointer pData ) { gint user_data; QofBook *book = NULL; QofCollection *col = NULL; /* setup */ book = qof_book_new(); g_assert( book ); g_assert_cmpint( g_list_length( get_object_modules() ), == , 0 ); qof_object_register( fixture->qofobject ); g_assert_cmpint( g_list_length( get_object_modules() ), == , 1 ); col = qof_book_get_collection( book, fixture->qofobject->e_type ); /* make col already exist */ g_assert( col ); g_test_message( "Test foreach and data" ); foreach_cb_struct.user_data = ( gpointer ) &user_data; foreach_cb_struct.is_called = FALSE; foreach_cb_struct.col = col; foreach_cb_struct.cb = mock_instance_foreach_cb; fixture->qofobject->foreach = mock_foreach; qof_object_foreach( fixture->qofobject->e_type, book, mock_instance_foreach_cb, ( gpointer ) &user_data ); g_assert( foreach_cb_struct.is_called == TRUE ); qof_book_destroy( book ); }
static void test_recursion (QofSession *original, guint counter) { QofSession *copy; QofCollection *grand_coll; struct tally c; QofBook *book; guint d, e, f; c.nulls = 0; c.total = 0; c.collect = 0; c.book = NULL; book = qof_session_get_book(original); grand_coll = qof_book_get_collection(book, GRAND_MODULE_NAME); copy = qof_session_new(); if (debug) { /* FIXME XML backend can't handle STDOUT * qof_session_begin(copy, QOF_STDOUT, TRUE, FALSE); */ } /* TODO: implement QOF_TYPE_CHOICE testing. */ qof_instance_copy_coll_r(copy, grand_coll); /* test the original */ qof_object_foreach(GRAND_MODULE_NAME, book, check_cb, &c); book = qof_session_get_book(copy); /* test the copy */ d = c.nulls; e = c.total; f = c.collect; c.nulls = 0; c.total = 0; c.collect = 0; c.book = book; qof_object_foreach(GRAND_MODULE_NAME, book, check_cb, &c); do_test((d == c.nulls), "Null parents do not match"); do_test((e == c.total), "Total parents do not match"); do_test((f == c.collect), "Number of children in descendents does not match"); if (counter == 4 && debug == TRUE) { /* FIXME XML backend can't handle STDOUT * qof_session_save(copy, NULL); qof_session_save(original, NULL); */ } qof_session_end(copy); copy = NULL; }
bool GncSqlBillTermBackend::write (GncSqlBackend* sql_be) { g_return_val_if_fail (sql_be != NULL, FALSE); write_objects_t data {sql_be, true, this}; qof_object_foreach (GNC_ID_BILLTERM, sql_be->book(), do_save_billterm, &data); return data.is_ok; }
bool GncSqlVendorBackend::write (GncSqlBackend* sql_be) { g_return_val_if_fail (sql_be != NULL, FALSE); write_objects_t data{sql_be, true, this}; qof_object_foreach (GNC_ID_VENDOR, sql_be->book(), write_single_vendor, &data); return data.is_ok; }
bool GncSqlInvoiceBackend::write (GncSqlBackend* be) { g_return_val_if_fail (be != NULL, FALSE); write_objects_t data{be, true, this}; qof_object_foreach (GNC_ID_INVOICE, be->book(), write_single_invoice, &data); return data.is_ok; }
bool GncSqlTaxTableBackend::write (GncSqlBackend* sql_be) { g_return_val_if_fail (sql_be != NULL, FALSE); write_objects_t data{sql_be, true, this}; qof_object_foreach (GNC_ID_TAXTABLE, sql_be->book(), save_next_taxtable, &data); return data.is_ok; }
bool GncSqlOrderBackend::write (GncSqlBackend* be) { g_return_val_if_fail (be != NULL, FALSE); write_objects_t data{be, true, this}; qof_object_foreach (GNC_ID_ORDER, be->book(), write_single_order, &data); return data.is_ok; }
static gboolean write_billterms (GncSqlBackend* be) { write_billterms_t data; g_return_val_if_fail (be != NULL, FALSE); data.be = be; data.is_ok = TRUE; qof_object_foreach (GNC_ID_BILLTERM, be->book, do_save_billterm, &data); return data.is_ok; }
static gboolean write_customers( GncSqlBackend* be ) { write_customers_t data; g_return_val_if_fail( be != NULL, FALSE ); data.be = be; data.is_ok = TRUE; qof_object_foreach( GNC_ID_CUSTOMER, be->book, write_single_customer, (gpointer)&data ); return data.is_ok; }
static gboolean write_employees (GncSqlBackend* be) { write_objects_t data; g_return_val_if_fail (be != NULL, FALSE); data.be = be; data.is_ok = TRUE; qof_object_foreach (GNC_ID_EMPLOYEE, be->book, write_single_employee, &data); return data.is_ok; }
static gboolean write_taxtables( GncSqlBackend* be ) { write_objects_t data; g_return_val_if_fail( be != NULL, FALSE ); data.be = be; data.is_ok = TRUE; qof_object_foreach( GNC_ID_TAXTABLE, be->primary_book, save_next_taxtable, &data ); return data.is_ok; }
static void billterm_scrub (QofBook *book) { GList *list = NULL; GList *node; GncBillTerm *parent, *term; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); DEBUG("scrubbing billterms..."); qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht); qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht); qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht); qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list); /* destroy the list of "grandchildren" bill terms */ for (node = list; node; node = node->next) { gchar termstr[GUID_ENCODING_LENGTH+1]; term = node->data; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)), termstr); PWARN ("deleting grandchild billterm: %s\n", termstr); /* Make sure the parent has no children */ parent = gncBillTermGetParent(term); gncBillTermSetChild(parent, NULL); /* Destroy this bill term */ gncBillTermBeginEdit(term); gncBillTermDestroy(term); } /* reset the refcounts as necessary */ g_hash_table_foreach(ht, billterm_reset_refcount, NULL); g_list_free(list); g_hash_table_destroy(ht); }
bool GncSqlEmployeeBackend::write (GncSqlBackend* sql_be) { write_objects_t data; g_return_val_if_fail (sql_be != NULL, FALSE); data.be = sql_be; data.is_ok = TRUE; data.obe = this; qof_object_foreach (GNC_ID_EMPLOYEE, sql_be->book(), write_single_employee, &data); return data.is_ok; }
static void taxtable_scrub (QofBook *book) { GList *list = NULL; GList *node; GncTaxTable *parent, *table; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht); qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht); qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht); qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list); /* destroy the list of "grandchildren" tax tables */ for (node = list; node; node = node->next) { gchar guidstr[GUID_ENCODING_LENGTH+1]; table = static_cast<decltype(table)>(node->data); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr); PINFO ("deleting grandchild taxtable: %s\n", guidstr); /* Make sure the parent has no children */ parent = gncTaxTableGetParent(table); gncTaxTableSetChild(parent, NULL); /* Destroy this tax table */ gncTaxTableBeginEdit(table); gncTaxTableDestroy(table); } /* reset the refcounts as necessary */ g_hash_table_foreach(ht, taxtable_reset_refcount, NULL); g_list_free(list); g_hash_table_destroy(ht); }
GList * gncBusinessGetOwnerList (QofBook *book, const char *type_name, gboolean all_including_inactive) { struct _get_list_userdata data; data.result = NULL; data.is_active_accessor_func = NULL; if (!all_including_inactive) { data.is_active_accessor_func = qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE); } qof_object_foreach(type_name, book, &get_ownerlist_cb, &data); return data.result; }
void qof_object_foreach_sorted (QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, void * user_data) { GList *list = NULL; GList *iter; qof_object_foreach(type_name, book, do_prepend, &list); list = g_list_sort(list, qof_instance_guid_compare); for (iter = list; iter; iter = iter->next) { cb(iter->data, user_data); } g_list_free(list); // FIXME: Apparently this is a memory leak, as this g_list_free doesn't // free all of the allocated memory of g_list_append in do_append(). Why?!? // Does g_list_sort have special side-effects on the memory of the list? // Subsequently, I've changed the g_list_append into g_list_prepend, but // solely for performance reasons. To my surprise, this also makes the // dubious memory leak go away. But again why?!? }
static gboolean job_write (FILE *out, QofBook *book) { qof_object_foreach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out); return ferror(out) == 0; }