vector.h

00001 /* 
00002  * Copyright (C) 2005 iptelorg GmbH
00003  *
00004  * This file is part of ser, a free SIP server.
00005  *
00006  * ser is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * For a license to use the ser software under conditions
00012  * other than those described here, or to purchase support for this
00013  * software, please contact iptel.org by e-mail at the following addresses:
00014  *    info@iptel.org
00015  *
00016  * ser is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #ifndef __VECTOR_H
00027 #define __VECTOR_H
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 /* Structure representing dynamic array of elements of
00034  * equal size. */
00035 typedef struct {
00036         int element_size;
00038         int element_count;
00040         int allocated_count;
00043         int allocation_count;
00044         void *data;
00045 } vector_t;
00046 
00047 int vector_add(vector_t *vector, void *element);
00048 int vector_get(vector_t *vector, int index, void *element_dst);
00049 void* vector_get_ptr(vector_t *vector, int index);
00050 int vector_remove(vector_t *vector, int index);
00051 void vector_destroy(vector_t *vector);
00052 int vector_init(vector_t *vector, int element_size, int allocation_count);
00053 
00055 int vector_test(void);
00056 
00057 #define vector_size(v) (v)->element_count
00058 
00059 #ifdef __cplusplus
00060 }
00061 #endif
00062 
00063 #endif