table.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* table.h - Iterative table interface.
  2. Copyright (C) 2006 g10 Code GmbH
  3. This file is part of Scute.
  4. Scute is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. Scute is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Scute; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. In addition, as a special exception, g10 Code GmbH gives permission
  16. to link this library: with the Mozilla Foundation's code for
  17. Mozilla (or with modified versions of it that use the same license
  18. as the "Mozilla" code), and distribute the linked executables. You
  19. must obey the GNU General Public License in all respects for all of
  20. the code used other than "Mozilla". If you modify this file, you
  21. may extend this exception to your version of the file, but you are
  22. not obligated to do so. If you do not wish to do so, delete this
  23. exception statement from your version. */
  24. #ifndef TABLE_H
  25. #define TABLE_H 1
  26. #include <stdbool.h>
  27. #include <gpg-error.h>
  28. /* The indexed list type. */
  29. struct scute_table;
  30. typedef struct scute_table *scute_table_t;
  31. /* TABLE interface. */
  32. /* A table entry allocator function callback. Should return the new
  33. table entry in DATA_R. */
  34. typedef gpg_error_t (*scute_table_alloc_cb_t) (void **data_r, void *hook);
  35. /* A table entry deallocator function callback. */
  36. typedef void (*scute_table_dealloc_cb_t) (void *data);
  37. /* Allocate a new table and return it in TABLE_R. */
  38. gpg_error_t scute_table_create (scute_table_t *table_r,
  39. scute_table_alloc_cb_t alloc,
  40. scute_table_dealloc_cb_t dealloc);
  41. /* Destroy the indexed list TABLE. This also calls the deallocator on
  42. all entries. */
  43. void scute_table_destroy (scute_table_t table);
  44. /* Allocate a new table entry with a free index. Returns the index
  45. pointing to the new list entry in INDEX_R. This calls the
  46. allocator on the new entry before returning. Also returns the
  47. table entry in *DATA_R if this is not NULL. */
  48. gpg_error_t scute_table_alloc (scute_table_t table, int *index_r,
  49. void **data_r, void *hook);
  50. /* Deallocate the list entry index. Afterwards, INDEX points to the
  51. following entry. This calls the deallocator on the entry before
  52. returning. */
  53. void scute_table_dealloc (scute_table_t table, int *index);
  54. /* Return the index for the beginning of the list TABLE. */
  55. int scute_table_first (scute_table_t table);
  56. /* Return the index following INDEX. If INDEX is the last element in
  57. the list, return 0. */
  58. int scute_table_next (scute_table_t table, int index);
  59. /* Return true iff INDEX is the end-of-list marker. */
  60. bool scute_table_last (scute_table_t table, int index);
  61. /* Return the user data associated with INDEX. Return NULL if INDEX is
  62. the end-of-list marker. */
  63. void *scute_table_data (scute_table_t table, int index);
  64. /* Return the number of entries in the table TABLE. */
  65. int scute_table_used (scute_table_t table);
  66. #endif /* !TABLE_H */