XBPS Library API 20240111
The X Binary Package System
xbps_dictionary.h
1/* $NetBSD: prop_dictionary.h,v 1.9 2008/04/28 20:22:51 martin Exp $ */
2
3/*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _XBPS_DICTIONARY_H_
33#define _XBPS_DICTIONARY_H_
34
35#include <stdint.h>
36#include <xbps/xbps_object.h>
37#include <xbps/xbps_array.h>
38
39typedef struct _prop_dictionary *xbps_dictionary_t;
40typedef struct _prop_dictionary_keysym *xbps_dictionary_keysym_t;
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46xbps_dictionary_t xbps_dictionary_create(void);
47xbps_dictionary_t xbps_dictionary_create_with_capacity(unsigned int);
48
49xbps_dictionary_t xbps_dictionary_copy(xbps_dictionary_t);
50xbps_dictionary_t xbps_dictionary_copy_mutable(xbps_dictionary_t);
51
52unsigned int xbps_dictionary_count(xbps_dictionary_t);
53bool xbps_dictionary_ensure_capacity(xbps_dictionary_t,
54 unsigned int);
55
56void xbps_dictionary_make_immutable(xbps_dictionary_t);
57
58xbps_object_iterator_t xbps_dictionary_iterator(xbps_dictionary_t);
59xbps_array_t xbps_dictionary_all_keys(xbps_dictionary_t);
60
61xbps_object_t xbps_dictionary_get(xbps_dictionary_t, const char *);
62bool xbps_dictionary_set(xbps_dictionary_t, const char *,
63 xbps_object_t);
64void xbps_dictionary_remove(xbps_dictionary_t, const char *);
65
66xbps_object_t xbps_dictionary_get_keysym(xbps_dictionary_t,
67 xbps_dictionary_keysym_t);
68bool xbps_dictionary_set_keysym(xbps_dictionary_t,
69 xbps_dictionary_keysym_t,
70 xbps_object_t);
71void xbps_dictionary_remove_keysym(xbps_dictionary_t,
72 xbps_dictionary_keysym_t);
73
74bool xbps_dictionary_equals(xbps_dictionary_t, xbps_dictionary_t);
75
76char * xbps_dictionary_externalize(xbps_dictionary_t);
77xbps_dictionary_t xbps_dictionary_internalize(const char *);
78
79bool xbps_dictionary_externalize_to_file(xbps_dictionary_t,
80 const char *);
81bool xbps_dictionary_externalize_to_zfile(xbps_dictionary_t,
82 const char *);
83xbps_dictionary_t xbps_dictionary_internalize_from_file(const char *);
84xbps_dictionary_t xbps_dictionary_internalize_from_zfile(const char *);
85
86const char * xbps_dictionary_keysym_cstring_nocopy(xbps_dictionary_keysym_t);
87
88bool xbps_dictionary_keysym_equals(xbps_dictionary_keysym_t,
89 xbps_dictionary_keysym_t);
90
91/*
92 * Utility routines to make it more convenient to work with values
93 * stored in dictionaries.
94 */
95bool xbps_dictionary_get_dict(xbps_dictionary_t, const char *,
96 xbps_dictionary_t *);
97bool xbps_dictionary_get_bool(xbps_dictionary_t, const char *,
98 bool *);
99bool xbps_dictionary_set_bool(xbps_dictionary_t, const char *,
100 bool);
101
102bool xbps_dictionary_get_int8(xbps_dictionary_t, const char *,
103 int8_t *);
104bool xbps_dictionary_get_uint8(xbps_dictionary_t, const char *,
105 uint8_t *);
106bool xbps_dictionary_set_int8(xbps_dictionary_t, const char *,
107 int8_t);
108bool xbps_dictionary_set_uint8(xbps_dictionary_t, const char *,
109 uint8_t);
110
111bool xbps_dictionary_get_int16(xbps_dictionary_t, const char *,
112 int16_t *);
113bool xbps_dictionary_get_uint16(xbps_dictionary_t, const char *,
114 uint16_t *);
115bool xbps_dictionary_set_int16(xbps_dictionary_t, const char *,
116 int16_t);
117bool xbps_dictionary_set_uint16(xbps_dictionary_t, const char *,
118 uint16_t);
119
120bool xbps_dictionary_get_int32(xbps_dictionary_t, const char *,
121 int32_t *);
122bool xbps_dictionary_get_uint32(xbps_dictionary_t, const char *,
123 uint32_t *);
124bool xbps_dictionary_set_int32(xbps_dictionary_t, const char *,
125 int32_t);
126bool xbps_dictionary_set_uint32(xbps_dictionary_t, const char *,
127 uint32_t);
128
129bool xbps_dictionary_get_int64(xbps_dictionary_t, const char *,
130 int64_t *);
131bool xbps_dictionary_get_uint64(xbps_dictionary_t, const char *,
132 uint64_t *);
133bool xbps_dictionary_set_int64(xbps_dictionary_t, const char *,
134 int64_t);
135bool xbps_dictionary_set_uint64(xbps_dictionary_t, const char *,
136 uint64_t);
137
138bool xbps_dictionary_get_cstring(xbps_dictionary_t, const char *,
139 char **);
140bool xbps_dictionary_set_cstring(xbps_dictionary_t, const char *,
141 const char *);
142
143bool xbps_dictionary_get_cstring_nocopy(xbps_dictionary_t,
144 const char *,
145 const char **);
146bool xbps_dictionary_set_cstring_nocopy(xbps_dictionary_t,
147 const char *,
148 const char *);
149bool xbps_dictionary_set_and_rel(xbps_dictionary_t,
150 const char *,
151 xbps_object_t);
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif /* _XBPS_DICTIONARY_H_ */