libosmovty  0.9.3
Osmocom VTY library
include/osmocom/vty/vector.h
00001 /*
00002  * Generic vector interface header.
00003  * Copyright (C) 1997, 98 Kunihiro Ishiguro
00004  *
00005  * This file is part of GNU Zebra.
00006  *
00007  * GNU Zebra is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by the
00009  * Free Software Foundation; either version 2, or (at your option) any
00010  * later version.
00011  *
00012  * GNU Zebra is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
00019  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020  * 02111-1307, USA.
00021  */
00022 
00023 #pragma once
00024 
00025 /* struct for vector */
00026 struct _vector {
00027         unsigned int active;    /* number of active slots */
00028         unsigned int alloced;   /* number of allocated slot */
00029         void **index;           /* index to data */
00030 };
00031 typedef struct _vector *vector;
00032 
00033 #define VECTOR_MIN_SIZE 1
00034 
00035 /* (Sometimes) usefull macros.  This macro convert index expression to
00036  array expression. */
00037 /* Reference slot at given index, caller must ensure slot is active */
00038 #define vector_slot(V,I)  ((V)->index[(I)])
00039 /* Number of active slots.
00040  * Note that this differs from vector_count() as it the count returned
00041  * will include any empty slots
00042  */
00043 #define vector_active(V) ((V)->active)
00044 
00045 /* Prototypes. */
00046 vector vector_init(unsigned int size);
00047 void vector_ensure(vector v, unsigned int num);
00048 int vector_empty_slot(vector v);
00049 int vector_set(vector v, void *val);
00050 int vector_set_index(vector v, unsigned int i, void *val);
00051 void vector_unset(vector v, unsigned int i);
00052 unsigned int vector_count(vector v);
00053 void vector_only_wrapper_free(vector v);
00054 void vector_only_index_free(void *index);
00055 void vector_free(vector v);
00056 vector vector_copy(vector v);
00057 
00058 void *vector_lookup(vector, unsigned int);
00059 void *vector_lookup_ensure(vector, unsigned int);
00060 
00061 extern void *tall_vty_vec_ctx;