/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_list_ref_t tb_list_init(tb_size_t grow, tb_element_t element) { // check tb_assert_and_check_return_val(element.size && element.data && element.dupl && element.repl, tb_null); // done tb_bool_t ok = tb_false; tb_list_t* list = tb_null; do { // using the default grow if (!grow) grow = TB_LIST_GROW; // make self list = tb_malloc0_type(tb_list_t); tb_assert_and_check_break(list); // init element list->element = element; // init iterator list->itor.mode = TB_ITERATOR_MODE_FORWARD | TB_ITERATOR_MODE_REVERSE; list->itor.priv = tb_null; list->itor.step = element.size; list->itor.size = tb_list_itor_size; list->itor.head = tb_list_itor_head; list->itor.last = tb_list_itor_last; list->itor.tail = tb_list_itor_tail; list->itor.prev = tb_list_itor_prev; list->itor.next = tb_list_itor_next; list->itor.item = tb_list_itor_item; list->itor.copy = tb_list_itor_copy; list->itor.comp = tb_list_itor_comp; list->itor.remove = tb_list_itor_remove; list->itor.remove_range = tb_list_itor_remove_range; // init pool, item = entry + data list->pool = tb_fixed_pool_init(tb_null, grow, sizeof(tb_list_entry_t) + element.size, tb_null, tb_list_item_exit, (tb_cpointer_t)list); tb_assert_and_check_break(list->pool); // init head tb_list_entry_init_(&list->head, 0, sizeof(tb_list_entry_t) + element.size, tb_null); // ok ok = tb_true; } while (0); // failed? if (!ok) { // exit it if (list) tb_list_exit((tb_list_ref_t)list); list = tb_null; } // ok? return (tb_list_ref_t)list; }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ gb_mesh_face_list_ref_t gb_mesh_face_list_init(tb_element_t element) { // check tb_assert_and_check_return_val(element.data && element.dupl && element.repl, tb_null); // done tb_bool_t ok = tb_false; gb_mesh_face_list_impl_t* impl = tb_null; do { // make list impl = tb_malloc0_type(gb_mesh_face_list_impl_t); tb_assert_and_check_break(impl); // init element impl->element = element; // init pool, item = face + data impl->pool = tb_fixed_pool_init(tb_null, GB_MESH_FACE_LIST_GROW, sizeof(gb_mesh_face_t) + element.size, tb_null, gb_mesh_face_exit, (tb_cpointer_t)impl); tb_assert_and_check_break(impl->pool); // init head tb_list_entry_init_(&impl->head, 0, sizeof(gb_mesh_face_t) + element.size, tb_null); // init order impl->order = GB_MESH_ORDER_INSERT_TAIL; // ok ok = tb_true; } while (0); // failed? if (!ok) { // exit it if (impl) gb_mesh_face_list_exit((gb_mesh_face_list_ref_t)impl); impl = tb_null; } // ok? return (gb_mesh_face_list_ref_t)impl; }