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