static void _test__type_get_varg_value__stub(void* pv_output, _typeinfo_t* pt_info, ...) { va_list val_elemlist; va_start(val_elemlist, pt_info); _type_get_varg_value(pt_info, val_elemlist, pv_output); va_end(val_elemlist); }
/** * Finds the position of the first element in an ordered range that has a value greater than or equivalent to a specified value, * where the ordering criterion may be specified by a binary predicate. */ forward_iterator_t _algo_lower_bound_if_varg(forward_iterator_t it_first, forward_iterator_t it_last, bfun_t bfun_op, va_list val_elemlist) { void* pv_value = NULL; bool_t b_result = false; size_t t_len = 0; size_t t_halflen = 0; iterator_t it_middle; assert(_iterator_valid_range(it_first, it_last, _FORWARD_ITERATOR)); if (bfun_op == NULL) { bfun_op = _fun_get_binary(it_first, _LESS_FUN); } pv_value = _iterator_allocate_init_elem(it_first); _type_get_varg_value(_iterator_get_typeinfo(it_first), val_elemlist, pv_value); if (strncmp(_iterator_get_typebasename(it_first), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) { t_len = iterator_distance(it_first, it_last); while (t_len > 0) { t_halflen = t_len >> 1; it_middle = iterator_advance(it_first, t_halflen); (*bfun_op)(iterator_get_pointer(it_middle), string_c_str((string_t*)pv_value), &b_result); if (b_result) { /* *it_middle < value */ it_first = iterator_next(it_middle); t_len = t_len - t_halflen - 1; } else { t_len = t_halflen; } } } else {
void test__type_get_varg_value__invalid_typeinfo(void** state) { _typeinfo_t info; int n_output = 0; va_list val_elemlist; info._pt_type = NULL; expect_assert_failure(_type_get_varg_value(&info, val_elemlist, &n_output)); }
/** * Return the number of specific elements in an hash_multimap */ size_t _hash_multimap_count_varg(const hash_multimap_t* cphmmap_map, va_list val_elemlist) { assert(cphmmap_map != NULL); _type_get_varg_value(&((hash_multimap_t*)cphmmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cphmmap_map->_pair_temp._pv_first); return _hashtable_count(&cphmmap_map->_t_hashtable, &cphmmap_map->_pair_temp); }
/** * Erase an element from a hash_multimap that match a specified element. */ size_t _hash_multimap_erase_varg(hash_multimap_t* phmmap_map, va_list val_elemlist) { assert(phmmap_map != NULL); _type_get_varg_value(&phmmap_map->_pair_temp._t_typeinfofirst, val_elemlist, phmmap_map->_pair_temp._pv_first); return _hashtable_erase(&phmmap_map->_t_hashtable, &phmmap_map->_pair_temp); }
/** * Obtain data from variable argument list, the data type and deque element data type are same. */ void _deque_get_varg_value_auxiliary(deque_t* pdeq_deque, va_list val_elemlist, void* pv_varg) { assert(pdeq_deque != NULL); assert(_deque_is_inited(pdeq_deque) || _deque_is_created(pdeq_deque)); _deque_init_elem_auxiliary(pdeq_deque, pv_varg); _type_get_varg_value(&pdeq_deque->_t_typeinfo, val_elemlist, pv_varg); }
/** * Obtain data from variable argument list, the data type and hash_set element data type are same. */ void _hash_set_get_varg_value_auxiliary(hash_set_t* phset_set, va_list val_elemlist, void* pv_varg) { assert(phset_set != NULL); assert(pv_varg != NULL); _hash_set_init_elem_auxiliary(phset_set, pv_varg); _type_get_varg_value(&phset_set->_t_hashtable._t_typeinfo, val_elemlist, pv_varg); }
void test__type_get_varg_value__invalid_typeinfo_style2(void** state) { _typeinfo_t t_info; int n_output = 0; va_list val_elemlist; _test__get_type(&t_info, "char"); t_info._t_style = 100; expect_assert_failure(_type_get_varg_value(&t_info, val_elemlist, &n_output)); }
/** * Obtain data from variable argument slist, the data type and slist element data type are same. */ void _slist_get_varg_value_auxiliary(slist_t* pslist_slist, va_list val_elemlist, _slistnode_t* pt_node) { assert(pslist_slist != NULL); assert(pt_node != NULL); assert(_slist_is_inited(pslist_slist) || _slist_is_created(pslist_slist)); _slist_init_node_auxiliary(pslist_slist, pt_node); _type_get_varg_value(&pslist_slist->_t_typeinfo, val_elemlist, pt_node->_pby_data); }
/** * Obtain data from variable argument list, the data type and vector element data type are same. */ void _vector_get_varg_value_auxiliary(vector_t* pvec_vector, va_list val_elemlist, void* pv_varg) { assert(pvec_vector != NULL); assert(pv_varg != NULL); assert(_vector_is_inited(pvec_vector) || _vector_is_created(pvec_vector)); _vector_init_elem_auxiliary(pvec_vector, pv_varg); _type_get_varg_value(&pvec_vector->_t_typeinfo, val_elemlist, pv_varg); }
/** * Assignment for the first element of pair. */ void _pair_make_first(pair_t* ppair_pair, ...) { va_list val_elemlist; assert(ppair_pair != NULL); assert(_pair_is_inited(ppair_pair)); va_start(val_elemlist, ppair_pair); _type_get_varg_value(&ppair_pair->_t_typeinfofirst, val_elemlist, ppair_pair->_pv_first); va_end(val_elemlist); }
/** * Return the number of specific elements in an map */ size_t _map_count_varg(const map_t* cpmap_map, va_list val_elemlist) { assert(cpmap_map != NULL); assert(_pair_is_inited(&cpmap_map->_pair_temp)); _type_get_varg_value(&((map_t*)cpmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE return _avl_tree_count(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #else return _rb_tree_count(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #endif }
/** * Erase an element from a map that match a specified element. */ size_t _map_erase_varg(map_t* pmap_map, va_list val_elemlist) { assert(pmap_map != NULL); assert(_pair_is_inited(&pmap_map->_pair_temp)); /* get key */ _type_get_varg_value(&pmap_map->_pair_temp._t_typeinfofirst, val_elemlist, pmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE return _avl_tree_erase(&pmap_map->_t_tree, &pmap_map->_pair_temp); #else return _rb_tree_erase(&pmap_map->_t_tree, &pmap_map->_pair_temp); #endif }
/** * Find specific element. */ hash_multimap_iterator_t _hash_multimap_find_varg(const hash_multimap_t* cphmmap_map, va_list val_elemlist) { hash_multimap_iterator_t it_iter; assert(cphmmap_map != NULL); _type_get_varg_value(&((hash_multimap_t*)cphmmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cphmmap_map->_pair_temp._pv_first); it_iter = _hashtable_find(&cphmmap_map->_t_hashtable, &cphmmap_map->_pair_temp); _ITERATOR_CONTAINER(it_iter) = (hash_multimap_t*)cphmmap_map; _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _HASH_MULTIMAP_CONTAINER; _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR; return it_iter; }
/** * Add specificed element from variable argument list at the end of vector container. */ void _vector_push_back_varg(vector_t* pvec_vector, va_list val_elemlist) { _byte_t* pby_last = NULL; assert(pvec_vector != NULL); assert(_vector_is_inited(pvec_vector)); /* if the remain capacity is less then the element count */ if (vector_capacity(pvec_vector) == vector_size(pvec_vector)) { vector_reserve(pvec_vector, _vector_calculate_new_capacity(vector_size(pvec_vector), 1)); } /* initialize the last element */ pby_last = pvec_vector->_pby_finish; assert(pby_last != NULL); pvec_vector->_pby_finish += _GET_VECTOR_TYPE_SIZE(pvec_vector); _vector_init_elem_auxiliary(pvec_vector, pby_last); /* copy value from varg */ _type_get_varg_value(&pvec_vector->_t_typeinfo, val_elemlist, pby_last); }
/** * Return an iterator range that is equal to a specific element. */ range_t _hash_multimap_equal_range_varg(const hash_multimap_t* cphmmap_map, va_list val_elemlist) { range_t r_range; assert(cphmmap_map != NULL); _type_get_varg_value(&((hash_multimap_t*)cphmmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cphmmap_map->_pair_temp._pv_first); r_range = _hashtable_equal_range(&cphmmap_map->_t_hashtable, &cphmmap_map->_pair_temp); _ITERATOR_CONTAINER(r_range.it_begin) = (hash_multimap_t*)cphmmap_map; _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(r_range.it_begin) = _HASH_MULTIMAP_CONTAINER; _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(r_range.it_begin) = _BIDIRECTIONAL_ITERATOR; _ITERATOR_CONTAINER(r_range.it_end) = (hash_multimap_t*)cphmmap_map; _HASH_MULTIMAP_ITERATOR_CONTAINER_TYPE(r_range.it_end) = _HASH_MULTIMAP_CONTAINER; _HASH_MULTIMAP_ITERATOR_ITERATOR_TYPE(r_range.it_end) = _BIDIRECTIONAL_ITERATOR; return r_range; }
/** * Return an iterator to the first element that is greater than a specific element. */ map_iterator_t _map_upper_bound_varg(const map_t* cpmap_map, va_list val_elemlist) { map_iterator_t it_iter; assert(cpmap_map != NULL); assert(_pair_is_inited(&cpmap_map->_pair_temp)); _type_get_varg_value(&((map_t*)cpmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE it_iter = _avl_tree_upper_bound(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #else it_iter = _rb_tree_upper_bound(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #endif _ITERATOR_CONTAINER(it_iter) = (map_t*)cpmap_map; _MAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MAP_CONTAINER; _MAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR; return it_iter; }
/** * Find specific element. */ multimap_iterator_t _multimap_find_varg(const multimap_t* cpmmap_map, va_list val_elemlist) { multimap_iterator_t it_iter; assert(cpmmap_map != NULL); assert(_pair_is_inited(&cpmmap_map->_pair_temp)); /* get key */ _type_get_varg_value(&((multimap_t*)cpmmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmmap_map->_pair_temp._pv_first); /* find key in tree */ #ifdef CSTL_MULTIMAP_AVL_TREE it_iter = _avl_tree_find(&cpmmap_map->_t_tree, &cpmmap_map->_pair_temp); #else it_iter = _rb_tree_find(&cpmmap_map->_t_tree, &cpmmap_map->_pair_temp); #endif _GET_CONTAINER(it_iter) = (multimap_t*)cpmmap_map; _GET_MULTIMAP_CONTAINER_TYPE(it_iter) = _MULTIMAP_CONTAINER; _GET_MULTIMAP_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR; return it_iter; }
/** * Return an iterator range that is equal to a specific element. */ range_t _map_equal_range_varg(const map_t* cpmap_map, va_list val_elemlist) { range_t r_range; assert(cpmap_map != NULL); assert(_pair_is_inited(&cpmap_map->_pair_temp)); _type_get_varg_value(&((map_t*)cpmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE r_range = _avl_tree_equal_range(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #else r_range = _rb_tree_equal_range(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #endif _ITERATOR_CONTAINER(r_range.it_begin) = (map_t*)cpmap_map; _MAP_ITERATOR_CONTAINER_TYPE(r_range.it_begin) = _MAP_CONTAINER; _MAP_ITERATOR_ITERATOR_TYPE(r_range.it_begin) = _BIDIRECTIONAL_ITERATOR; _ITERATOR_CONTAINER(r_range.it_end) = (map_t*)cpmap_map; _MAP_ITERATOR_CONTAINER_TYPE(r_range.it_end) = _MAP_CONTAINER; _MAP_ITERATOR_ITERATOR_TYPE(r_range.it_end) = _BIDIRECTIONAL_ITERATOR; return r_range; }
/** * Access an element with specific index. */ void* _map_at_varg(map_t* pmap_map, va_list val_elemlist) { map_iterator_t it_iter; va_list val_elemlist_copy; assert(pmap_map != NULL); assert(_pair_is_inited(&pmap_map->_pair_temp)); va_copy(val_elemlist_copy, val_elemlist); _type_get_varg_value(&pmap_map->_pair_temp._t_typeinfofirst, val_elemlist, pmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE it_iter = _avl_tree_insert_unique(&pmap_map->_t_tree, &pmap_map->_pair_temp); #else it_iter = _rb_tree_insert_unique(&pmap_map->_t_tree, &pmap_map->_pair_temp); #endif _ITERATOR_CONTAINER(it_iter) = pmap_map; _MAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MAP_CONTAINER; _MAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR; if(iterator_equal(it_iter, map_end(pmap_map))) { it_iter = _map_find_varg(pmap_map, val_elemlist_copy); } va_end(val_elemlist_copy); /* char* */ if(strncmp(_GET_MAP_SECOND_TYPE_BASENAME(pmap_map), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) { return (char*)string_c_str((string_t*)((pair_t*)iterator_get_pointer(it_iter))->_pv_second); } else { return ((pair_t*)iterator_get_pointer(it_iter))->_pv_second; } }
void test__type_get_varg_value__null_typeinof(void** state) { int n_output = 0; va_list val_elemlist; expect_assert_failure(_type_get_varg_value(NULL, val_elemlist, &n_output)); }