Logo Search packages:      
Sourcecode: rapple version File versions  Download package

void rpl_list_insert ( rpl_list list_p,
rpl_list_node node_p,
RPL_LIST_INSERT_POS  position,
rpl_list_node new_node_p,
void *  data_ptr 
)

Inserts a new node into before or after a selected node in a list.

Definition at line 109 of file list.c.

References rpl_list::count, rpl_list::first, rpl_list::last, RPL_LIST_INSERT_AFTER, and RPL_LIST_INSERT_BEFORE.

{
    assert(list_p != NULL);
    assert(node_p != NULL);
    assert(new_node_p != NULL);
    assert(data_ptr != NULL);

    list_p->count++;
    new_node_p->data_ptr = data_ptr;

    switch (position)
    {
        case RPL_LIST_INSERT_BEFORE:
            /* Fix up the newNode prev and next ptrs */
            new_node_p->prev = node_p->prev;
            new_node_p->next = node_p;

            /*Ensure that node pointing to node_p now points to the new_node_p */
            if (node_p->prev != NULL)
            {
                node_p->prev->next = new_node_p;
            }

            /* check if being inserted at head of list */
            if (list_p->first == node_p)
            {
                list_p->first = new_node_p;
            }

            /* Ensure that the node_p prev pointer points to new node */
            node_p->prev = new_node_p;
            break;

        case RPL_LIST_INSERT_AFTER:
            /* Fix up newNode prev and next */
            new_node_p->prev = node_p;
            new_node_p->next = node_p->next;

            if (node_p->next != NULL)
            {
                node_p->next->prev = new_node_p;
            }

            /* check if being inserted at the tail of the list */
            if ( list_p->last == node_p )
            {
                list_p->last = new_node_p;
            }

            /* Ensure that the node_p next pointer points to new node */
            node_p->next = new_node_p;
            break;

        default:
            /* invalid position parameter */
            assert (0);
    }
}


Generated by  Doxygen 1.6.0   Back to index