1 /* Reference-counted string list.
2 Copyright (C) 2001-2018 Free Software Foundation, Inc.
3
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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #ifndef _RC_STR_LIST_H
18 #define _RC_STR_LIST_H
19
20 #include <stdlib.h>
21
22 #include "str-list.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28
29 /* A reference-counted list-of-immutable-strings type. */
30
31 typedef struct refcounted_string_list_ty refcounted_string_list_ty;
32 struct refcounted_string_list_ty
33 {
34 unsigned int refcount;
35 struct string_list_ty contents;
36 };
37
38 static inline refcounted_string_list_ty *
39 add_reference (refcounted_string_list_ty *rslp)
40 {
41 if (rslp != NULL)
42 rslp->refcount++;
43 return rslp;
44 }
45
46 static inline void
47 drop_reference (refcounted_string_list_ty *rslp)
48 {
49 if (rslp != NULL)
50 {
51 if (rslp->refcount > 1)
52 rslp->refcount--;
53 else
54 {
55 string_list_destroy (&rslp->contents);
56 free (rslp);
57 }
58 }
59 }
60
61
62 #ifdef __cplusplus
63 }
64 #endif
65
66
67 #endif /* _RC_STR_LIST_H */