gl_xlist.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* Abstract sequential list data type, with out-of-memory checking.
  2. Copyright (C) 2009-2020 Free Software Foundation, Inc.
  3. Written by Bruno Haible <bruno@clisp.org>, 2009.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #ifndef _GL_XLIST_H
  15. #define _GL_XLIST_H
  16. #include "gl_list.h"
  17. #include "xalloc.h"
  18. #ifndef _GL_INLINE_HEADER_BEGIN
  19. #error "Please include config.h first."
  20. #endif
  21. _GL_INLINE_HEADER_BEGIN
  22. #ifndef GL_XLIST_INLINE
  23. # define GL_XLIST_INLINE _GL_INLINE
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* These functions are thin wrappers around the corresponding functions with
  29. _nx_ infix from gl_list.h. Upon out-of-memory, they invoke xalloc_die (),
  30. instead of returning an error indicator. */
  31. #if 0 /* These are defined inline below. */
  32. extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
  33. gl_listelement_equals_fn equals_fn,
  34. gl_listelement_hashcode_fn hashcode_fn,
  35. gl_listelement_dispose_fn dispose_fn,
  36. bool allow_duplicates);
  37. extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
  38. gl_listelement_equals_fn equals_fn,
  39. gl_listelement_hashcode_fn hashcode_fn,
  40. gl_listelement_dispose_fn dispose_fn,
  41. bool allow_duplicates,
  42. size_t count, const void **contents);
  43. extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
  44. const void *elt);
  45. extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
  46. const void *elt);
  47. extern gl_list_node_t gl_list_set_first (gl_list_t list, const void *elt);
  48. extern gl_list_node_t gl_list_set_last (gl_list_t list, const void *elt);
  49. extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
  50. extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
  51. extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
  52. const void *elt);
  53. extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
  54. const void *elt);
  55. extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
  56. const void *elt);
  57. extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
  58. gl_listelement_compar_fn compar,
  59. const void *elt);
  60. #endif
  61. GL_XLIST_INLINE gl_list_t
  62. gl_list_create_empty (gl_list_implementation_t implementation,
  63. gl_listelement_equals_fn equals_fn,
  64. gl_listelement_hashcode_fn hashcode_fn,
  65. gl_listelement_dispose_fn dispose_fn,
  66. bool allow_duplicates)
  67. {
  68. gl_list_t result =
  69. gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
  70. allow_duplicates);
  71. if (result == NULL)
  72. xalloc_die ();
  73. return result;
  74. }
  75. GL_XLIST_INLINE gl_list_t
  76. gl_list_create (gl_list_implementation_t implementation,
  77. gl_listelement_equals_fn equals_fn,
  78. gl_listelement_hashcode_fn hashcode_fn,
  79. gl_listelement_dispose_fn dispose_fn,
  80. bool allow_duplicates,
  81. size_t count, const void **contents)
  82. {
  83. gl_list_t result =
  84. gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
  85. allow_duplicates, count, contents);
  86. if (result == NULL)
  87. xalloc_die ();
  88. return result;
  89. }
  90. GL_XLIST_INLINE void
  91. gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
  92. {
  93. int result = gl_list_node_nx_set_value (list, node, elt);
  94. if (result < 0)
  95. xalloc_die ();
  96. }
  97. GL_XLIST_INLINE gl_list_node_t
  98. gl_list_set_at (gl_list_t list, size_t position, const void *elt)
  99. {
  100. gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
  101. if (result == NULL)
  102. xalloc_die ();
  103. return result;
  104. }
  105. GL_XLIST_INLINE gl_list_node_t
  106. gl_list_set_first (gl_list_t list, const void *elt)
  107. {
  108. gl_list_node_t result = gl_list_nx_set_first (list, elt);
  109. if (result == NULL)
  110. xalloc_die ();
  111. return result;
  112. }
  113. GL_XLIST_INLINE gl_list_node_t
  114. gl_list_set_last (gl_list_t list, const void *elt)
  115. {
  116. gl_list_node_t result = gl_list_nx_set_last (list, elt);
  117. if (result == NULL)
  118. xalloc_die ();
  119. return result;
  120. }
  121. GL_XLIST_INLINE gl_list_node_t
  122. gl_list_add_first (gl_list_t list, const void *elt)
  123. {
  124. gl_list_node_t result = gl_list_nx_add_first (list, elt);
  125. if (result == NULL)
  126. xalloc_die ();
  127. return result;
  128. }
  129. GL_XLIST_INLINE gl_list_node_t
  130. gl_list_add_last (gl_list_t list, const void *elt)
  131. {
  132. gl_list_node_t result = gl_list_nx_add_last (list, elt);
  133. if (result == NULL)
  134. xalloc_die ();
  135. return result;
  136. }
  137. GL_XLIST_INLINE gl_list_node_t
  138. gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
  139. {
  140. gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
  141. if (result == NULL)
  142. xalloc_die ();
  143. return result;
  144. }
  145. GL_XLIST_INLINE gl_list_node_t
  146. gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
  147. {
  148. gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
  149. if (result == NULL)
  150. xalloc_die ();
  151. return result;
  152. }
  153. GL_XLIST_INLINE gl_list_node_t
  154. gl_list_add_at (gl_list_t list, size_t position, const void *elt)
  155. {
  156. gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
  157. if (result == NULL)
  158. xalloc_die ();
  159. return result;
  160. }
  161. GL_XLIST_INLINE gl_list_node_t
  162. gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
  163. const void *elt)
  164. {
  165. gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
  166. if (result == NULL)
  167. xalloc_die ();
  168. return result;
  169. }
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. _GL_INLINE_HEADER_END
  174. #endif /* _GL_XLIST_H */