su_vector.c File Reference


Detailed Description

Simple pointer vectors.

The vectors are resizeable unidimensional arrays.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Date:
Created: Fri Sep 27 14:43:29 2002 ppessi

#include "config.h"
#include <stdlib.h>
#include <stddef.h>
#include <memory.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
#include "sofia-sip/su_config.h"
#include "sofia-sip/su_vector.h"

Include dependency graph for su_vector.c:


Functions

su_vector_t * su_vector_create (su_home_t *home, su_free_func_t free_func)
 Create a vector.
void su_vector_destroy (su_vector_t *vector)
 Destroy a vector.
int su_vector_insert (su_vector_t *vector, usize_t index, void *item)
 Insert an item to vector.
int su_vector_remove (su_vector_t *vector, usize_t index)
 Remove an item from vector.
int su_vector_empty (su_vector_t *vector)
 Remove all items from vector.
int su_vector_append (su_vector_t *vector, void *item)
 Append a item to vector.
void * su_vector_item (su_vector_t const *vector, usize_t i)
 Get a numbered item from vector.
usize_t su_vector_len (su_vector_t const *l)
 Get number of items in vector.
void ** su_vector_get_array (su_vector_t *vector)
 Get an array of pointers from the vector.
void su_vector_free_array (su_vector_t *vector, void **array)
 Free a string array.

Function Documentation

int su_vector_append ( su_vector_t *  vector,
void *  item 
)

Append a item to vector.

The function su_vector_append() appends an item to the vector.

Parameters:
vector pointer to a vector object
item item to be appended
Return values:
0 if successful
-1 upon an error

su_vector_t* su_vector_create ( su_home_t home,
su_free_func_t  free_func 
)

Create a vector.

The function su_vector_create() creates a pointer vector object. The vector is initially empty. The function clones a memory home for the vector object from home. If a free_func is provided then that will be used to free the individual nodes (NULL if not used).

void su_vector_destroy ( su_vector_t *  vector  ) 

Destroy a vector.

The function su_vector_destroy() destroys a vector and frees all its nodes if a freeing function is available

int su_vector_empty ( su_vector_t *  vector  ) 

Remove all items from vector.

The function su_vector_empty() removes all items from the vector.

Parameters:
vector pointer to a vector object
Return values:
0 if successful
-1 upon an error

void su_vector_free_array ( su_vector_t *  vector,
void **  array 
)

Free a string array.

The function su_vector_free_array() discards a string array allocated with su_vector_get_array().

Parameters:
vector pointer to a vector object
array string array to be freed

void** su_vector_get_array ( su_vector_t *  vector  ) 

Get an array of pointers from the vector.

The function su_vector_get_array() returns an array of pointer. The length of the array is always one longer than the length of the vector, and the last item in the returned array is always NULL.

Parameters:
vector pointer to a vector object
Returns:
Pointer to array, or NULL if error occurred.

int su_vector_insert ( su_vector_t *  vector,
usize_t  index,
void *  item 
)

Insert an item to vector.

The function su_vector_insert() inserts an item to the vector. The items after the index will be moved further within the vector.

Parameters:
vector pointer to a vector object
item item to be appended
index index for the new item
Return values:
0 when successful
-1 upon an error

void* su_vector_item ( su_vector_t const *  vector,
usize_t  i 
)

Get a numbered item from vector.

The function su_vector_item() returns a numbered item from vector. The numbering starts from 0.

Parameters:
vector pointer to a vector object
i index
Returns:
Pointer, if item exists, or NULL upon an error.

usize_t su_vector_len ( su_vector_t const *  l  ) 

Get number of items in vector.

The function su_vector_len() returns the number of items in the vector.

int su_vector_remove ( su_vector_t *  vector,
usize_t  index 
)

Remove an item from vector.

The function su_vector_remove() removes an item from the vector. The items after the index will be moved backwards within the vector.

Parameters:
vector pointer to a vector object
index index for the removed item
Return values:
0 when successful
-1 upon an error


Sofia-SIP 1.12.6 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.