gl_xlist.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* Abstract sequential list data type, with out-of-memory checking.
  2. Copyright (C) 2009-2013 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 <http://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_add_first (gl_list_t list, const void *elt);
  48. extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
  49. extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
  50. const void *elt);
  51. extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
  52. const void *elt);
  53. extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
  54. const void *elt);
  55. extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
  56. gl_listelement_compar_fn compar,
  57. const void *elt);
  58. #endif
  59. GL_XLIST_INLINE gl_list_t
  60. gl_list_create_empty (gl_list_implementation_t implementation,
  61. gl_listelement_equals_fn equals_fn,
  62. gl_listelement_hashcode_fn hashcode_fn,
  63. gl_listelement_dispose_fn dispose_fn,
  64. bool allow_duplicates)
  65. {
  66. gl_list_t result =
  67. gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
  68. allow_duplicates);
  69. if (result == NULL)
  70. xalloc_die ();
  71. return result;
  72. }
  73. GL_XLIST_INLINE gl_list_t
  74. gl_list_create (gl_list_implementation_t implementation,
  75. gl_listelement_equals_fn equals_fn,
  76. gl_listelement_hashcode_fn hashcode_fn,
  77. gl_listelement_dispose_fn dispose_fn,
  78. bool allow_duplicates,
  79. size_t count, const void **contents)
  80. {
  81. gl_list_t result =
  82. gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
  83. allow_duplicates, count, contents);
  84. if (result == NULL)
  85. xalloc_die ();
  86. return result;
  87. }
  88. GL_XLIST_INLINE void
  89. gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
  90. {
  91. int result = gl_list_node_nx_set_value (list, node, elt);
  92. if (result < 0)
  93. xalloc_die ();
  94. }
  95. GL_XLIST_INLINE gl_list_node_t
  96. gl_list_set_at (gl_list_t list, size_t position, const void *elt)
  97. {
  98. gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
  99. if (result == NULL)
  100. xalloc_die ();
  101. return result;
  102. }
  103. GL_XLIST_INLINE gl_list_node_t
  104. gl_list_add_first (gl_list_t list, const void *elt)
  105. {
  106. gl_list_node_t result = gl_list_nx_add_first (list, elt);
  107. if (result == NULL)
  108. xalloc_die ();
  109. return result;
  110. }
  111. GL_XLIST_INLINE gl_list_node_t
  112. gl_list_add_last (gl_list_t list, const void *elt)
  113. {
  114. gl_list_node_t result = gl_list_nx_add_last (list, elt);
  115. if (result == NULL)
  116. xalloc_die ();
  117. return result;
  118. }
  119. GL_XLIST_INLINE gl_list_node_t
  120. gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
  121. {
  122. gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
  123. if (result == NULL)
  124. xalloc_die ();
  125. return result;
  126. }
  127. GL_XLIST_INLINE gl_list_node_t
  128. gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
  129. {
  130. gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
  131. if (result == NULL)
  132. xalloc_die ();
  133. return result;
  134. }
  135. GL_XLIST_INLINE gl_list_node_t
  136. gl_list_add_at (gl_list_t list, size_t position, const void *elt)
  137. {
  138. gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
  139. if (result == NULL)
  140. xalloc_die ();
  141. return result;
  142. }
  143. GL_XLIST_INLINE gl_list_node_t
  144. gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
  145. const void *elt)
  146. {
  147. gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
  148. if (result == NULL)
  149. xalloc_die ();
  150. return result;
  151. }
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. _GL_INLINE_HEADER_END
  156. #endif /* _GL_XLIST_H */