gl_xoset.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Abstract ordered set 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_XOSET_H
  15. #define _GL_XOSET_H
  16. #include "gl_oset.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_XOSET_INLINE
  23. # define GL_XOSET_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_oset.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_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
  33. gl_setelement_compar_fn compar_fn,
  34. gl_setelement_dispose_fn dispose_fn);
  35. extern bool gl_oset_add (gl_oset_t set, const void *elt);
  36. #endif
  37. GL_XOSET_INLINE gl_oset_t
  38. gl_oset_create_empty (gl_oset_implementation_t implementation,
  39. gl_setelement_compar_fn compar_fn,
  40. gl_setelement_dispose_fn dispose_fn)
  41. {
  42. gl_oset_t result =
  43. gl_oset_nx_create_empty (implementation, compar_fn, dispose_fn);
  44. if (result == NULL)
  45. xalloc_die ();
  46. return result;
  47. }
  48. GL_XOSET_INLINE bool
  49. gl_oset_add (gl_oset_t set, const void *elt)
  50. {
  51. int result = gl_oset_nx_add (set, elt);
  52. if (result < 0)
  53. xalloc_die ();
  54. return result;
  55. }
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. _GL_INLINE_HEADER_END
  60. #endif /* _GL_XOSET_H */