/* Create/Destroy Functions */ GncEntry *gncEntryCreate (QofBook *book) { GncEntry *entry; gnc_numeric zero = gnc_numeric_zero (); if (!book) return NULL; entry = g_object_new (GNC_TYPE_ENTRY, NULL); qof_instance_init_data (&entry->inst, _GNC_MOD_NAME, book); entry->desc = CACHE_INSERT (""); entry->action = CACHE_INSERT (""); entry->notes = CACHE_INSERT (""); entry->quantity = zero; entry->i_price = zero; entry->i_taxable = TRUE; entry->i_discount = zero; entry->i_disc_type = GNC_AMT_TYPE_PERCENT; entry->i_disc_how = GNC_DISC_PRETAX; entry->b_price = zero; entry->b_taxable = TRUE; entry->billto.type = GNC_OWNER_CUSTOMER; entry->b_payment = GNC_PAYMENT_CASH; entry->values_dirty = TRUE; qof_event_gen (&entry->inst, QOF_EVENT_CREATE, NULL); return entry; }
/* Create/Destroy Functions */ GncCustomer *gncCustomerCreate (QofBook *book) { GncCustomer *cust; if (!book) return NULL; cust = g_object_new (GNC_TYPE_CUSTOMER, NULL); qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book); cust->id = CACHE_INSERT (""); cust->name = CACHE_INSERT (""); cust->notes = CACHE_INSERT (""); cust->addr = gncAddressCreate (book, &cust->inst); cust->taxincluded = GNC_TAXINCLUDED_USEGLOBAL; cust->active = TRUE; cust->jobs = NULL; cust->discount = gnc_numeric_zero(); cust->credit = gnc_numeric_zero(); cust->shipaddr = gncAddressCreate (book, &cust->inst); if (gs_address_event_handler_id == 0) { gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL); } qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL); return cust; }
int main(){ struct cache_manager *lru_manager; int i; lru_init(&lru_manager,"LRU", 500, 500, 1, 0); for(i =0;i < 1000000;i++){ struct lru_node *ln = NULL; unsigned int blkno = RND(10000); ln = CACHE_SEARCH(lru_manager, blkno); if(!ln){ ln = CACHE_REPLACE(lru_manager, 0, FCL_REPLACE_ANY); ln = CACHE_ALLOC(lru_manager, ln, blkno); CACHE_INSERT(lru_manager, ln); }else{ ln = CACHE_REMOVE(lru_manager, ln); CACHE_INSERT(lru_manager, ln); } } CACHE_PRINT(lru_manager, stdout); CACHE_CLOSE(lru_manager); return 0; }
/* Create/Destroy Functions */ GncEmployee *gncEmployeeCreate (QofBook *book) { GncEmployee *employee; if (!book) return NULL; employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL); qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book); employee->id = CACHE_INSERT (""); employee->username = CACHE_INSERT (""); employee->language = CACHE_INSERT (""); employee->acl = CACHE_INSERT (""); employee->addr = gncAddressCreate (book, &employee->inst); employee->workday = gnc_numeric_zero(); employee->rate = gnc_numeric_zero(); employee->active = TRUE; if (gs_address_event_handler_id == 0) { gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL); } qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL); return employee; }
GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *book) { GncEmployee *employee; if (!book || !from) return NULL; employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL); qof_instance_init_data(&employee->inst, _GNC_MOD_NAME, book); qof_instance_gemini (&employee->inst, &from->inst); employee->id = CACHE_INSERT (from->id); employee->username = CACHE_INSERT (from->username); employee->language = CACHE_INSERT (from->language); employee->acl = CACHE_INSERT (from->acl); employee->addr = gncCloneAddress (from->addr, &employee->inst, book); employee->workday = from->workday; employee->rate = from->rate; employee->active = from->active; employee->currency = gnc_commodity_obtain_twin(from->currency, book); employee->ccard_acc = GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book)); qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL); return employee; }
/* Create/Destroy Functions */ GncBillTerm * gncBillTermCreate (QofBook *book) { GncBillTerm *term; if (!book) return NULL; term = g_object_new (GNC_TYPE_BILLTERM, NULL); qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book); term->name = CACHE_INSERT (""); term->desc = CACHE_INSERT (""); term->discount = gnc_numeric_zero (); addObj (term); qof_event_gen (&term->inst, QOF_EVENT_CREATE, NULL); return term; }
GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *book) { GList *node; GncBillTerm *term; if (!book || !from) return NULL; term = g_object_new (GNC_TYPE_BILLTERM, NULL); qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book); qof_instance_gemini (&term->inst, &from->inst); term->name = CACHE_INSERT (from->name); term->desc = CACHE_INSERT (from->desc); term->type = from->type; term->due_days = from->due_days; term->disc_days = from->disc_days; term->discount = from->discount; term->cutoff = from->cutoff; term->invisible = from->invisible; term->refcount = 0; /* Make copies of parents and children. Note that this can be * a recursive copy ... treat as doubly-linked list. */ if (from->child) { term->child = gncBillTermObtainTwin (from->child, book); term->child->parent = term; } if (from->parent) { term->parent = gncBillTermObtainTwin (from->parent, book); term->parent->child = term; } for (node = g_list_last(from->children); node; node = node->next) { GncBillTerm *btrm = node->data; btrm = gncBillTermObtainTwin (btrm, book); btrm->parent = term; term->children = g_list_prepend(term->children, btrm); } addObj (term); qof_event_gen (&term->inst, QOF_EVENT_CREATE, NULL); return term; }
/* Create/Destroy Functions */ GncJob *gncJobCreate (QofBook *book) { GncJob *job; if (!book) return NULL; job = g_object_new (GNC_TYPE_JOB, NULL); qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book); job->id = CACHE_INSERT (""); job->name = CACHE_INSERT (""); job->desc = CACHE_INSERT (""); job->active = TRUE; /* GncOwner not initialized */ qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL); return job; }
/** Create a copy of a customer, placing the copy into a new book. */ GncCustomer * gncCloneCustomer (GncCustomer *from, QofBook *book) { GList *node; GncCustomer *cust; cust = g_object_new (GNC_TYPE_CUSTOMER, NULL); qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book); qof_instance_gemini (&cust->inst, &from->inst); cust->id = CACHE_INSERT (from->id); cust->name = CACHE_INSERT (from->name); cust->notes = CACHE_INSERT (from->notes); cust->discount = from->discount; cust->credit = from->credit; cust->taxincluded = from->taxincluded; cust->active = from->active; cust->taxtable_override = from->taxtable_override; cust->addr = gncCloneAddress (from->addr, &cust->inst, book); cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst, book); /* Find the matching currency in the new book, assumes * currency has already been copied into new book. */ cust->currency = gnc_commodity_obtain_twin (from->currency, book); /* Find the matching bill term, tax table in the new book */ cust->terms = gncBillTermObtainTwin(from->terms, book); cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book); for (node = g_list_last(cust->jobs); node; node = node->next) { GncJob *job = node->data; job = gncJobObtainTwin (job, book); cust->jobs = g_list_prepend(cust->jobs, job); } qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL); return cust; }
/* Create/Destroy Functions */ GncTaxTable * gncTaxTableCreate (QofBook *book) { GncTaxTable *table; if (!book) return NULL; table = g_object_new (GNC_TYPE_TAXTABLE, NULL); qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book); table->name = CACHE_INSERT (""); addObj (table); qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL); return table; }
void qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book) { QofInstancePrivate *priv; QofCollection *col; QofIdType col_type; g_return_if_fail(QOF_IS_INSTANCE(inst)); priv = GET_PRIVATE(inst); g_return_if_fail(!priv->book); priv->book = book; col = qof_book_get_collection (book, type); g_return_if_fail(col != NULL); /* XXX We passed redundant info to this routine ... but I think that's * OK, it might eliminate programming errors. */ col_type = qof_collection_get_type(col); if (safe_strcmp(col_type, type)) { PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type); return; } priv = GET_PRIVATE(inst); inst->e_type = CACHE_INSERT (type); do { guid_new(&priv->guid); if (NULL == qof_collection_lookup_entity (col, &priv->guid)) break; PWARN("duplicate id created, trying again"); } while (1); priv->collection = col; qof_collection_insert_entity (col, inst); }
GncAddress * gncAddressCreate (QofBook *book, QofInstance *prnt) { GncAddress *addr; if (!book) return NULL; addr = g_object_new (GNC_TYPE_ADDRESS, NULL); qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book); addr->book = book; addr->dirty = FALSE; addr->parent = prnt; addr->name = CACHE_INSERT (""); addr->addr1 = CACHE_INSERT (""); addr->addr2 = CACHE_INSERT (""); addr->addr3 = CACHE_INSERT (""); addr->addr4 = CACHE_INSERT (""); addr->phone = CACHE_INSERT (""); addr->fax = CACHE_INSERT (""); addr->email = CACHE_INSERT (""); return addr; }
static void gnc_quickfill_remove_recursive (QuickFill *qf, const gchar *text, gint depth, QuickFillSort sort) { QuickFill *match_qf; gchar *child_text; gint child_len; child_text = NULL; child_len = 0; if (depth < g_utf8_strlen (text, -1)) { /* process next letter */ gchar *key_char; gunichar key_char_uc; guint key; key_char = g_utf8_offset_to_pointer (text, depth); key_char_uc = g_utf8_get_char (key_char); key = g_unichar_toupper (key_char_uc); match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key)); if (match_qf) { /* remove text from child qf */ gnc_quickfill_remove_recursive (match_qf, text, depth + 1, sort); if (match_qf->text == NULL) { /* text was the only word with a prefix up to match_qf */ g_hash_table_remove (qf->matches, GUINT_TO_POINTER (key)); gnc_quickfill_destroy (match_qf); } else { /* remember remaining best child string */ child_text = match_qf->text; child_len = match_qf->len; } } } if (qf->text == NULL) return; if (strcmp (text, qf->text) == 0) { /* the currently best text is about to be removed */ gchar *best_text = NULL; gint best_len = 0; if (child_text != NULL) { /* other children are pretty good as well */ best_text = child_text; best_len = child_len; } else { if (g_hash_table_size (qf->matches) != 0) { /* otherwise search for another good text */ struct _BestText bts; bts.text = NULL; bts.sort = sort; g_hash_table_foreach (qf->matches, (GHFunc) best_text_helper, &bts); best_text = bts.text; best_len = (best_text == NULL) ? 0 : g_utf8_strlen (best_text, -1); } } /* now replace or clear text */ CACHE_REMOVE(qf->text); if (best_text != NULL) { qf->text = CACHE_INSERT((gpointer) best_text); qf->len = best_len; } else { qf->text = NULL; qf->len = 0; } } }
static void quickfill_insert_recursive (QuickFill *qf, const char *text, int depth, QuickFillSort sort) { guint key; char *old_text; QuickFill *match_qf; int len; char *key_char; gunichar key_char_uc; if (qf == NULL) return; if ((text == NULL) || (g_utf8_strlen (text, -1) <= depth)) return; key_char = g_utf8_offset_to_pointer (text, depth); key_char_uc = g_utf8_get_char (key_char); key = g_unichar_toupper (key_char_uc); match_qf = g_hash_table_lookup (qf->matches, GUINT_TO_POINTER (key)); if (match_qf == NULL) { match_qf = gnc_quickfill_new (); g_hash_table_insert (qf->matches, GUINT_TO_POINTER (key), match_qf); } old_text = match_qf->text; switch (sort) { case QUICKFILL_ALPHA: if (old_text && (g_utf8_collate (text, old_text) >= 0)) break; /* fall through */ case QUICKFILL_LIFO: default: len = g_utf8_strlen (text, -1); /* If there's no string there already, just put the new one in. */ if (old_text == NULL) { match_qf->text = CACHE_INSERT((gpointer) text); match_qf->len = len; break; } /* Leave prefixes in place */ if ((len > match_qf->len) && (strncmp(text, old_text, strlen(old_text)) == 0)) break; CACHE_REMOVE(old_text); match_qf->text = CACHE_INSERT((gpointer) text); match_qf->len = len; break; } quickfill_insert_recursive (match_qf, text, ++depth, sort); }