Esempio n. 1
0
/**
 * Initialize vector container with an exist vector range.
 */
void vector_init_copy_range(vector_t* pvec_dest, vector_iterator_t it_begin, vector_iterator_t it_end)
{
    vector_iterator_t it_dest;
    vector_iterator_t it_src;
    bool_t            b_result = false;

    assert(pvec_dest != NULL);
    assert(_vector_is_created(pvec_dest));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_begin), it_begin));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_end), it_end));
    assert(iterator_equal(it_begin, it_end) || _vector_iterator_before(it_begin, it_end));
    assert(_vector_same_vector_iterator_type(pvec_dest, it_begin));
    assert(_vector_same_vector_iterator_type(pvec_dest, it_end));

    /* initialize all elements with default value */
    vector_init_n(pvec_dest, iterator_distance(it_begin, it_end));

    /* copy values for range */
    for(it_dest = vector_begin(pvec_dest), it_src = it_begin;
        !iterator_equal(it_dest, vector_end(pvec_dest)) && !iterator_equal(it_src, it_end);
        it_dest = iterator_next(it_dest), it_src = iterator_next(it_src))
    {
        b_result = _GET_VECTOR_TYPE_SIZE(pvec_dest);
        _GET_VECTOR_TYPE_COPY_FUNCTION(pvec_dest)(_VECTOR_ITERATOR_COREPOS(it_dest), _VECTOR_ITERATOR_COREPOS(it_src), &b_result);
        assert(b_result);
    }
    assert(iterator_equal(it_dest, vector_end(pvec_dest)) && iterator_equal(it_src, it_end));
}
Esempio n. 2
0
/**
 * Get the pointer that point to the iterator reference data, but ignore char*.
 */
const void* _vector_iterator_get_pointer_ignore_cstr(vector_iterator_t it_iter)
{
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));
    assert(!_vector_iterator_equal(it_iter, vector_end(_VECTOR_ITERATOR_CONTAINER(it_iter))));

    return _VECTOR_ITERATOR_COREPOS(it_iter);
}
Esempio n. 3
0
/**
 * Get the iterator that reference previous n data.
 */
vector_iterator_t _vector_iterator_prev_n(vector_iterator_t it_iter, int n_step)
{
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));
    _VECTOR_ITERATOR_COREPOS(it_iter) -= _GET_VECTOR_TYPE_SIZE(_VECTOR_ITERATOR_CONTAINER(it_iter)) * n_step;
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));

    return it_iter;
}
Esempio n. 4
0
/**
 * Get the iterator that reference next data.
 */
vector_iterator_t _vector_iterator_next(vector_iterator_t it_iter)
{
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));
    _VECTOR_ITERATOR_COREPOS(it_iter) += _GET_VECTOR_TYPE_SIZE(_VECTOR_ITERATOR_CONTAINER(it_iter));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));

    return it_iter;
}
Esempio n. 5
0
/**
 * Test the type that saved in the vector container and referenced by it_iter are same.
 */
bool_t _vector_same_vector_iterator_type(const vector_t* cpvec_vector, vector_iterator_t it_iter)
{
    assert(cpvec_vector != NULL);
    assert(_VECTOR_ITERATOR_CONTAINER(it_iter) != NULL);
    assert(_VECTOR_ITERATOR_CONTAINER_TYPE(it_iter) == _VECTOR_CONTAINER);
    assert(_VECTOR_ITERATOR_ITERATOR_TYPE(it_iter) == _RANDOM_ACCESS_ITERATOR);

    return _vector_same_type(cpvec_vector, _VECTOR_ITERATOR_CONTAINER(it_iter));
}
Esempio n. 6
0
/**
 * Compare two iterators for equality.
 */
bool_t _vector_iterator_equal(vector_iterator_t it_first, vector_iterator_t it_second)
{
    assert(_iterator_same_type(it_first, it_second));
    assert(_VECTOR_ITERATOR_CONTAINER(it_first) == _VECTOR_ITERATOR_CONTAINER(it_second));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_first), it_first));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_second), it_second));

    return _VECTOR_ITERATOR_COREPOS(it_first) == _VECTOR_ITERATOR_COREPOS(it_second) ? true : false;
}
Esempio n. 7
0
/**
 * Calculate the distance between two iterators.
 */
int _vector_iterator_minus(vector_iterator_t it_first, vector_iterator_t it_second)
{
    assert(_iterator_same_type(it_first, it_second));
    assert(_VECTOR_ITERATOR_CONTAINER(it_first) == _VECTOR_ITERATOR_CONTAINER(it_second));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_first), it_first));
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_second), it_second));

    return (_VECTOR_ITERATOR_COREPOS(it_first) - _VECTOR_ITERATOR_COREPOS(it_second)) / 
           (int)_GET_VECTOR_TYPE_SIZE(_VECTOR_ITERATOR_CONTAINER(it_first));
}
Esempio n. 8
0
/**
 * Get the pointer that point to the iterator reference data.
 */
const void* _vector_iterator_get_pointer(vector_iterator_t it_iter)
{
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));
    assert(!_vector_iterator_equal(it_iter, vector_end(_VECTOR_ITERATOR_CONTAINER(it_iter))));

    /* char* */
    if (strncmp(_GET_VECTOR_TYPE_BASENAME(_VECTOR_ITERATOR_CONTAINER(it_iter)), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) {
        return string_c_str((string_t*)_VECTOR_ITERATOR_COREPOS(it_iter));
    } else {
        return _VECTOR_ITERATOR_COREPOS(it_iter);
    }
}
Esempio n. 9
0
/**
 * Set iterator reference data.
 */
void _vector_iterator_set_value(vector_iterator_t it_iter, const void* cpv_value)
{
    bool_t b_result = false;

    assert(cpv_value != NULL);
    assert(_vector_iterator_belong_to_vector(_VECTOR_ITERATOR_CONTAINER(it_iter), it_iter));
    assert(!_vector_iterator_equal(it_iter, vector_end(_VECTOR_ITERATOR_CONTAINER(it_iter))));

    /* char* */
    if (strncmp(_GET_VECTOR_TYPE_BASENAME(_VECTOR_ITERATOR_CONTAINER(it_iter)), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) {
        string_assign_cstr((string_t*)_VECTOR_ITERATOR_COREPOS(it_iter), (char*)cpv_value);
    } else {
        b_result = _GET_VECTOR_TYPE_SIZE(_VECTOR_ITERATOR_CONTAINER(it_iter));
        _GET_VECTOR_TYPE_COPY_FUNCTION(_VECTOR_ITERATOR_CONTAINER(it_iter))(_VECTOR_ITERATOR_COREPOS(it_iter), cpv_value, &b_result);
        assert(b_result);
    }
}
Esempio n. 10
0
/**
 * Test iterator referenced data is within the vector.
 */
bool_t _vector_iterator_belong_to_vector(const vector_t* cpvec_vector, vector_iterator_t it_iter)
{
    assert(cpvec_vector != NULL);
    assert(_vector_is_inited(cpvec_vector));
    assert(_VECTOR_ITERATOR_ITERATOR_TYPE(it_iter) == _RANDOM_ACCESS_ITERATOR);
    assert(_VECTOR_ITERATOR_CONTAINER_TYPE(it_iter) == _VECTOR_CONTAINER);
    assert(_VECTOR_ITERATOR_CONTAINER(it_iter) == cpvec_vector);

    if (_VECTOR_ITERATOR_COREPOS(it_iter) >= cpvec_vector->_pby_start &&
        _VECTOR_ITERATOR_COREPOS(it_iter) <= cpvec_vector->_pby_finish) {
        return true;
    } else {
        return false;
    }
}