void *hfind(htable_t *ht, void *key, int key_len) { uint32_t index; hash_entry_t *hen; null_if_null(ht); index = h_index(ht, key, key_len); hen = h_entry(ht, index, key, key_len); return hen ? hen->data : NULL; }
void * hinsert(htable_t *ht, void *key, int key_len, void *data, hcallback_func_t *destructor, hcallback_func_t *can_replace, hcallback_func_t *do_delete, int *did_delete) { uint32_t index; hash_entry_t *hen; hash_entry_t *hen_old; void *data_old = NULL; null_if_null(ht); index = h_index(ht, key, key_len); hen = h_entry(ht, index, key, key_len); hen_old = hen; data_old = hen ? hen->data : NULL; if (did_delete) { *did_delete = 0; } if(can_replace != NULL && !can_replace(key, key_len, data_old, data)) { return data; } if (NULL == (hen = h_alloc_hen(key_len))) { return data; } if (hen_old) { /* * entry already exists - we are about to replace it. * * If not for the iterators, we'd be all fine and dandy. * * But there can be iterators referencing this item * (hence, can't wipe out key/data). */ h_try_delete(ht, hen_old, do_delete, did_delete); } else { if (did_delete) { *did_delete = 0; } } /* * fill in the new hen */ memcpy(hen->key, key, key_len); hen->data = data; hen->destructor = destructor; LIST_INSERT_HEAD(&ht->buckets[index], hen, entries); // inserting in the head of all entries ensures we don't have // to mess with the iterators LIST_INSERT_HEAD(&ht->all_entries, hen, all_entries); // successfully inserted ht->total_items++; return data_old; }
std::list<std::string> OptionParser::Parse(int argc, char **argv) { Glib::OptionContext ctx(arguments); if (!summary.empty()) ctx.set_summary(summary); if (!description.empty()) ctx.set_description(description); ctx.set_translation_domain(PACKAGE); Glib::OptionGroup grp("main", "Main Group"); grp.set_translation_domain(PACKAGE); bool h_value = false; BoolOption h_entry('h', "help", "Show help options", "", h_value); h_entry.AddEntry(grp); for (std::list<OptionBase*>::iterator it = options.begin(); it != options.end(); it++) (*it)->AddEntry(grp); ctx.set_main_group(grp); try { ctx.parse(argc, argv); } catch (Glib::OptionError& err) { std::cout << err.what() << std::endl; exit(1); } if(h_value) { #ifdef HAVE_GLIBMM_OPTIONCONTEXT_GET_HELP std::cout << ctx.get_help() << std::endl; #else std::cout << IString("Use -? to get usage description") << std::endl; #endif exit(0); } for (std::list<OptionBase*>::iterator it = options.begin(); it != options.end(); it++) (*it)->Result(); std::list<std::string> params; for (int i = 1; i < argc; i++) params.push_back(argv[i]); return params; }