2
0

vector.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2005 iptelorg GmbH
  3. *
  4. * This file is part of ser, a free SIP server.
  5. *
  6. * ser is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * For a license to use the ser software under conditions
  12. * other than those described here, or to purchase support for this
  13. * software, please contact iptel.org by e-mail at the following addresses:
  14. * [email protected]
  15. *
  16. * ser is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. #ifndef __VECTOR_H
  26. #define __VECTOR_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Structure representing dynamic array of elements of
  31. * equal size. */
  32. typedef struct {
  33. int element_size;
  34. /** the number of used elements */
  35. int element_count;
  36. /** the number of allocated elements */
  37. int allocated_count;
  38. /** number of elements allocated together (better than allocation
  39. * for each element separately) */
  40. int allocation_count;
  41. void *data;
  42. } vector_t;
  43. int vector_add(vector_t *vector, void *element);
  44. int vector_get(vector_t *vector, int index, void *element_dst);
  45. void* vector_get_ptr(vector_t *vector, int index);
  46. int vector_remove(vector_t *vector, int index);
  47. void vector_destroy(vector_t *vector);
  48. int vector_init(vector_t *vector, int element_size, int allocation_count);
  49. /** testing function - returns 0 if no errors */
  50. int vector_test(void);
  51. #define vector_size(v) (v)->element_count
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif