COMPS_DocCategory* comps_doccategory_union(COMPS_DocCategory *c1, COMPS_DocCategory *c2) { COMPS_DocCategory *res; COMPS_ObjListIt *it; COMPS_Set *set; COMPS_Object *obj; void *data; int index; res = COMPS_OBJECT_CREATE(COMPS_DocCategory,NULL); COMPS_OBJECT_DESTROY(res->properties); res->properties = comps_objdict_union(c1->properties, c2->properties); set = comps_set_create(); comps_set_init(set, NULL, NULL, &comps_object_destroy_v, &__comps_docgroupid_cmp_set); it = c1->group_ids?c1->group_ids->first:NULL; for (; it != NULL; it = it->next) { obj = comps_object_copy(it->comps_obj); comps_set_add(set, (void*)comps_object_incref(obj)); comps_doccategory_add_groupid(res, (COMPS_DocGroupId*)obj); } it = c2->group_ids ? c2->group_ids->first : NULL; for (; it != NULL; it = it->next) { if ((data = comps_set_data_at(set, (void*)it->comps_obj)) != NULL) { index = comps_objlist_index(res->group_ids, (COMPS_Object*)data); comps_objlist_remove_at(res->group_ids, index); comps_objlist_insert_at_x(res->group_ids, index, comps_object_copy(it->comps_obj)); } else { comps_doccategory_add_groupid(res, (COMPS_DocGroupId*) comps_object_copy(it->comps_obj)); } } comps_set_destroy(&set); COMPS_OBJECT_DESTROY(res->name_by_lang); COMPS_OBJECT_DESTROY(res->desc_by_lang); res->name_by_lang = comps_objdict_union(c1->name_by_lang, c2->name_by_lang); res->desc_by_lang = comps_objdict_union(c1->desc_by_lang, c2->desc_by_lang); return res; }
COMPS_DocGroup* comps_docgroup_union(COMPS_DocGroup *g1, COMPS_DocGroup *g2) { COMPS_DocGroup *res; COMPS_ObjListIt *it; COMPS_Set *set; COMPS_DocGroupPackage *pkg; res = COMPS_OBJECT_CREATE(COMPS_DocGroup, NULL); COMPS_OBJECT_DESTROY(res->properties); res->properties = comps_objdict_union(g1->properties, g2->properties); set = comps_set_create(); comps_set_init(set, NULL, NULL, (void(*)(void*))&comps_object_destroy, &comps_docpackage_cmp_set); it = g1->packages?g1->packages->first:NULL; for (; it != NULL; it = it->next) { pkg = (COMPS_DocGroupPackage*) comps_object_copy(it->comps_obj); comps_set_add(set, (void*)comps_object_incref((COMPS_Object*)pkg)); comps_docgroup_add_package(res, pkg); } void *data; int index; it = g2->packages?g2->packages->first:NULL; for (; it != NULL; it = it->next) { if ((data = comps_set_data_at(set, (void*)it->comps_obj)) != NULL) { index = comps_objlist_index(res->packages, (COMPS_Object*)data); comps_objlist_remove_at(res->packages, index); comps_objlist_insert_at_x(res->packages, index, comps_object_copy(it->comps_obj)); } else { comps_docgroup_add_package(res, (COMPS_DocGroupPackage*) comps_object_copy(it->comps_obj)); } } comps_set_destroy(&set); comps_object_destroy((COMPS_Object*)res->name_by_lang); comps_object_destroy((COMPS_Object*)res->desc_by_lang); res->name_by_lang = comps_objdict_union(g1->name_by_lang, g2->name_by_lang); res->desc_by_lang = comps_objdict_union(g1->desc_by_lang, g2->desc_by_lang); return res; }