static Eina_Bool _db_fill_class(Eolian_Class *cl) { if (!_db_fill_implements(cl)) return EINA_FALSE; eina_hash_set(_classes, cl->full_name, cl); eina_hash_set(_classesf, cl->base.file, cl); return EINA_TRUE; }
Eina_Bool eo_parser_database_fill(const char *filename, Eina_Bool eot) { Eolian_Constructor *ctor; Eolian_Implement *impl; Eina_Iterator *itr; Eolian_Class *cl; Eo_Lexer *ls; const char *dep; if (eina_hash_find(_parsedeos, filename)) return EINA_TRUE; eina_hash_set(_parsingeos, filename, (void *)EINA_TRUE); ls = eo_lexer_new(filename); if (!ls) { fprintf(stderr, "eolian: unable to create lexer for file '%s'\n", filename); goto error; } /* read first token */ eo_lexer_get(ls); if (!eo_parser_walk(ls, eot)) goto error; if (eot) goto done; if (!(cl = ls->tmp.kls)) { fprintf(stderr, "eolian: no class for file '%s'\n", filename); goto error; } ls->tmp.kls = NULL; if (!_db_fill_class(cl)) goto error; itr = eolian_class_implements_get(cl); EINA_ITERATOR_FOREACH(itr, impl) { Eolian_Function_Type impl_type = EOLIAN_UNRESOLVED; const Eolian_Function *impl_func = eolian_implement_function_get(impl, &impl_type); if (!impl_func) { fprintf(stderr, "eolian: unable to find function '%s'\n", eolian_implement_full_name_get(impl)); eina_iterator_free(itr); goto error; } else if (eolian_function_is_constructor(impl->foo_id, impl->klass)) database_function_constructor_add((Eolian_Function*)impl->foo_id, cl); }
EM_INTERN void em_gui_server_add(const char *server, Emote_Protocol *p) { Em_Gui_Server *s; s = _em_gui_server_create(server, p); if (s) { eina_hash_set(gui->servers, server, s); _em_gui_switch(server, NULL); } }
static Eina_Bool _page_populate(void *data) { Page *page = data; const Page_Class *cls = page->cls; unsigned int count; page->od_to_list_item = eina_hash_pointer_new(NULL); for (count = 0; count < cls->populate_iteration_count; count++) { Elm_Genlist_Item *it; char letter; void *id, *od; const char **letter_str; if (!eina_iterator_next(page->iterator, &id)) goto end; // TODO: evaluate if we should keep a full copy or just store // fields of interest such as id, title, artist and album od = cls->data_from_itr(id); if (!od) goto end; it = elm_genlist_item_append (page->list, cls->item_cls, od, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); letter_str = (const char **)(((char *)od) + cls->data_letter_offset); letter = toupper((*letter_str)[0]); if ((page->index) && (isalpha(letter) && (page->last_index_letter[0] != letter))) { if ((page->first) && (!page->last_index_letter[0])) elm_index_item_append(page->index, "Special", page->first); page->last_index_letter[0] = letter; elm_index_item_append(page->index, page->last_index_letter, it); } if (!page->first) page->first = it; eina_hash_set(page->od_to_list_item, od, it); page->num_elements++; } return EINA_TRUE; end: if (cls->after_populate) cls->after_populate(page); page->populate = NULL; return EINA_FALSE; }
/** * @brief Remove a method from a module * * This function removes a callable rpc method from module @p def. After * removal, @p method will no longer be callable. * @note This does not free the method object. * @param def The module definition (NOT NULL) * @param method The method to remove (NOT NULL) * @return EINA_TRUE on success, else EINA_FALSE */ Eina_Bool azy_server_module_def_method_del(Azy_Server_Module_Def *def, Azy_Server_Module_Method *method) { if (!AZY_MAGIC_CHECK(def, AZY_MAGIC_SERVER_MODULE_DEF)) { AZY_MAGIC_FAIL(def, AZY_MAGIC_SERVER_MODULE_DEF); return EINA_FALSE; } if (!AZY_MAGIC_CHECK(method, AZY_MAGIC_SERVER_MODULE_METHOD)) { AZY_MAGIC_FAIL(method, AZY_MAGIC_SERVER_MODULE_METHOD); return EINA_FALSE; } return !!eina_hash_set(def->methods, method->name, NULL); }
EAPI E_Config_DD * e_config_descriptor_new(const char *name, int size) { Eet_Data_Descriptor_Class eddc; E_Config_DD *edd; if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), name, size)) return NULL; /* FIXME: We can directly map string inside an Eet_File and reuse it. But this need a break in all user of config every where in E. */ edd = (E_Config_DD *)eet_data_descriptor_stream_new(&eddc); if (!config_hash) config_hash = eina_hash_string_superfast_new(NULL); eina_hash_set(config_hash, name, edd); return edd; }
/** * @brief Add a method to a module * * This function adds a callable rpc method to module @p def. After adding, * @p method should be considered as belonging to @p def until the module is unloaded. * @param def The module definition (NOT NULL) * @param method The method to add (NOT NULL) */ void azy_server_module_def_method_add(Azy_Server_Module_Def *def, Azy_Server_Module_Method *method) { Azy_Server_Module_Method *old; if (!AZY_MAGIC_CHECK(def, AZY_MAGIC_SERVER_MODULE_DEF)) { AZY_MAGIC_FAIL(def, AZY_MAGIC_SERVER_MODULE_DEF); return; } if (!AZY_MAGIC_CHECK(method, AZY_MAGIC_SERVER_MODULE_METHOD)) { AZY_MAGIC_FAIL(method, AZY_MAGIC_SERVER_MODULE_METHOD); return; } if (!def->methods) def->methods = eina_hash_string_superfast_new((Eina_Free_Cb)azy_server_module_method_free); old = eina_hash_set(def->methods, method->name, method); if (old) azy_server_module_method_free(old); }
/** * @brief Set a param to a module * * This function sets a method call param named @p name to a module. It is used by the parser. * @param module The module (NOT NULL) * @param name The param name (NOT NULL) * @param value The param value * @param free_func The function to free @p value * @return EINA_TRUE on success, else EINA_FALSE */ Eina_Bool azy_server_module_param_set(Azy_Server_Module *module, const char *name, const void *value, Eina_Free_Cb free_func) { Azy_Server_Module_Param *param, *old; if (!AZY_MAGIC_CHECK(module, AZY_MAGIC_SERVER_MODULE)) { AZY_MAGIC_FAIL(module, AZY_MAGIC_SERVER_MODULE); return EINA_FALSE; } EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE); EINA_SAFETY_ON_TRUE_RETURN_VAL(!name[0], EINA_FALSE); if (!module->params) module->params = eina_hash_string_djb2_new((Eina_Free_Cb)azy_server_module_param_free_); param = calloc(1, sizeof(Azy_Server_Module_Param)); EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE); param->data = value; param->free_func = free_func; old = eina_hash_set(module->params, name, param); if (old) azy_server_module_param_free_(old); return EINA_TRUE; }
void Config::SaveValueIO(std::string id, std::string value, bool save) { if (eina_hash_find(cache_states, id.c_str())) { ConfigStateValue *v = new ConfigStateValue; v->id = strdup(id.c_str()); v->value = strdup(value.c_str()); void *old_data = eina_hash_set(cache_states, id.c_str(), v); delete (ConfigStateValue *)old_data; } else { ConfigStateValue *v = new ConfigStateValue; v->id = strdup(id.c_str()); v->value = strdup(value.c_str()); eina_hash_add(cache_states, id.c_str(), v); } if (save) saveStateCache(); }
static bool ewk_js_property_set(NPObject* npObject, NPIdentifier name, const NPVariant* npValue) { Ewk_JS_Object* object = reinterpret_cast<Ewk_JS_Object*>(npObject); Ewk_JS_Variant* value; Ewk_JS_Property* prop; bool fail = false; EINA_SAFETY_ON_NULL_RETURN_VAL(npObject, false); EINA_MAGIC_CHECK_OR_RETURN(object, false); if (!_NPN_IdentifierIsString(name)) { ERR("int NPIdentifier is not supported."); return fail; } value = static_cast<Ewk_JS_Variant*>(malloc(sizeof(Ewk_JS_Variant))); if (!value) { ERR("Could not allocate memory for ewk_js_variant"); return false; } ewk_js_npvariant_to_variant(value, npValue); char* prop_name = _NPN_UTF8FromIdentifier(name); prop = static_cast<Ewk_JS_Property*>(eina_hash_find(object->cls->properties, prop_name)); if (prop && prop->set) fail = prop->set(object, prop->name, value); // Class has property and property has setter. else if (object->cls->default_prop.set) fail = object->cls->default_prop.set(object, prop_name, value); // Default getter exists. else { // Fallback to objects hash map. void* old = eina_hash_set(object->properties, prop_name, value); free(old); fail = true; } free(prop_name); return fail; }
int main(int argc, const char *argv[]) { Eina_Hash *phone_book = NULL; int i; int64_t entry_id = 4; char *phone = NULL; Eina_Bool r; Eina_Iterator *it; void *data; eina_init(); phone_book = eina_hash_int64_new(_phone_entry_free_cb); // Add initial entries to our hash for (i = 0; _start_entries[i].id != -1; i++) { eina_hash_add(phone_book, &_start_entries[i].id, strdup(_start_entries[i].number)); } // Look for a specific entry and get its phone number phone = eina_hash_find(phone_book, &entry_id); if (phone) { printf("Printing entry.\n"); printf("Id: %lld\n", entry_id); printf("Number: %s\n\n", phone); } // Delete this entry r = eina_hash_del(phone_book, &entry_id, NULL); printf("Hash entry successfully deleted? %d\n\n", r); // Modify the pointer data of an entry and free the old one int64_t id3 = 3; phone = eina_hash_modify(phone_book, &id3, strdup("+23 45 111-11111")); free(phone); // Modify or add an entry to the hash with eina_hash_set // Let's first add a new entry int64_t id5 = 5; eina_error_set(0); phone = eina_hash_set(phone_book, &id5, strdup("+55 01 234-56789")); if (!phone) { Eina_Error err = eina_error_get(); if (!err) { printf("No previous phone found for id5. "); printf("Creating new entry.\n"); } else printf("Error when setting phone for Raul Seixas\n"); } else { printf("Old phone for id5 was %s\n", phone); free(phone); } printf("\n"); // Now change the phone number eina_error_set(0); phone = eina_hash_set(phone_book, &id5, strdup("+55 02 222-22222")); if (phone) { printf("Changing phone for id5 to +55 02 222-22222. "); printf("Old phone was %s\n", phone); free(phone); } else { Eina_Error err = eina_error_get(); if (err) printf("Error when changing phone for id5\n"); else { printf("No previous phone found for id5. "); printf("Creating new entry.\n"); } } // There are many ways to iterate over our Phone book. // First, iterate showing the names and associated numbers. printf("List of phones:\n"); eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL); printf("\n"); // Now iterate using an iterator printf("List of phones:\n"); it = eina_hash_iterator_tuple_new(phone_book); while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; const int64_t *id = t->key; const char *number = t->data; printf("%lld: %s\n", *id, number); } eina_iterator_free(it); // Always free the iterator after its use printf("\n"); // Just iterate over the keys (names) printf("List of ids in the phone book:\n"); it = eina_hash_iterator_key_new(phone_book); while (eina_iterator_next(it, &data)) { const int64_t *id = data; printf("%lld\n", *id); } eina_iterator_free(it); printf("\n"); // Just iterate over the data (numbers) printf("List of numbers in the phone book:\n"); it = eina_hash_iterator_data_new(phone_book); while (eina_iterator_next(it, &data)) { const char *number = data; printf("%s\n", number); } eina_iterator_free(it); printf("\n"); // Check how many items are in the phone book printf("There are %d items in the hash.\n\n", eina_hash_population(phone_book)); // Change the name (key) on an entry int64_t id6 = 6; eina_hash_move(phone_book, &id5, &id6); printf("List of phones after change:\n"); eina_hash_foreach(phone_book, _phone_book_foreach_cb, NULL); printf("\n"); // Empty the phone book, but don't destroy it eina_hash_free_buckets(phone_book); printf("There are %d items in the hash.\n\n", eina_hash_population(phone_book)); // Phone book could still be used, but we are freeing it since we are // done for now eina_hash_free(phone_book); eina_shutdown(); }