XBPS Library API 20240111
The X Binary Package System
xbps_array.h
1/* $NetBSD: prop_array.h,v 1.8 2008/09/11 13:15:13 haad 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_ARRAY_H_
33#define _XBPS_ARRAY_H_
34
35#include <stdint.h>
36#include <xbps/xbps_object.h>
37
38typedef struct _prop_array *xbps_array_t;
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44xbps_array_t xbps_array_create(void);
45xbps_array_t xbps_array_create_with_capacity(unsigned int);
46
47xbps_array_t xbps_array_copy(xbps_array_t);
48xbps_array_t xbps_array_copy_mutable(xbps_array_t);
49
50unsigned int xbps_array_capacity(xbps_array_t);
51unsigned int xbps_array_count(xbps_array_t);
52bool xbps_array_ensure_capacity(xbps_array_t, unsigned int);
53
54void xbps_array_make_immutable(xbps_array_t);
55bool xbps_array_mutable(xbps_array_t);
56
57xbps_object_iterator_t xbps_array_iterator(xbps_array_t);
58
59xbps_object_t xbps_array_get(xbps_array_t, unsigned int);
60bool xbps_array_set(xbps_array_t, unsigned int, xbps_object_t);
61bool xbps_array_add(xbps_array_t, xbps_object_t);
62bool xbps_array_add_first(xbps_array_t, xbps_object_t);
63void xbps_array_remove(xbps_array_t, unsigned int);
64
65bool xbps_array_equals(xbps_array_t, xbps_array_t);
66
67char * xbps_array_externalize(xbps_array_t);
68xbps_array_t xbps_array_internalize(const char *);
69
70bool xbps_array_externalize_to_file(xbps_array_t, const char *);
71bool xbps_array_externalize_to_zfile(xbps_array_t, const char *);
72xbps_array_t xbps_array_internalize_from_file(const char *);
73xbps_array_t xbps_array_internalize_from_zfile(const char *);
74
75/*
76 * Utility routines to make it more convenient to work with values
77 * stored in dictionaries.
78 */
79bool xbps_array_get_bool(xbps_array_t, unsigned int,
80 bool *);
81bool xbps_array_set_bool(xbps_array_t, unsigned int,
82 bool);
83
84bool xbps_array_get_int8(xbps_array_t, unsigned int,
85 int8_t *);
86bool xbps_array_get_uint8(xbps_array_t, unsigned int,
87 uint8_t *);
88bool xbps_array_set_int8(xbps_array_t, unsigned int,
89 int8_t);
90bool xbps_array_set_uint8(xbps_array_t, unsigned int,
91 uint8_t);
92
93bool xbps_array_get_int16(xbps_array_t, unsigned int,
94 int16_t *);
95bool xbps_array_get_uint16(xbps_array_t, unsigned int,
96 uint16_t *);
97bool xbps_array_set_int16(xbps_array_t, unsigned int,
98 int16_t);
99bool xbps_array_set_uint16(xbps_array_t, unsigned int,
100 uint16_t);
101
102bool xbps_array_get_int32(xbps_array_t, unsigned int,
103 int32_t *);
104bool xbps_array_get_uint32(xbps_array_t, unsigned int,
105 uint32_t *);
106bool xbps_array_set_int32(xbps_array_t, unsigned int,
107 int32_t);
108bool xbps_array_set_uint32(xbps_array_t, unsigned int,
109 uint32_t);
110
111bool xbps_array_get_int64(xbps_array_t, unsigned int,
112 int64_t *);
113bool xbps_array_get_uint64(xbps_array_t, unsigned int,
114 uint64_t *);
115bool xbps_array_set_int64(xbps_array_t, unsigned int,
116 int64_t);
117bool xbps_array_set_uint64(xbps_array_t, unsigned int,
118 uint64_t);
119
120bool xbps_array_add_int8(xbps_array_t, int8_t);
121bool xbps_array_add_uint8(xbps_array_t, uint8_t);
122
123bool xbps_array_add_int16(xbps_array_t, int16_t);
124bool xbps_array_add_uint16(xbps_array_t, uint16_t);
125
126bool xbps_array_add_int32(xbps_array_t, int32_t);
127bool xbps_array_add_uint32(xbps_array_t, uint32_t);
128
129bool xbps_array_add_int64(xbps_array_t, int64_t);
130bool xbps_array_add_uint64(xbps_array_t, uint64_t);
131
132bool xbps_array_get_cstring(xbps_array_t, unsigned int,
133 char **);
134bool xbps_array_set_cstring(xbps_array_t, unsigned int,
135 const char *);
136bool xbps_array_add_cstring(xbps_array_t, const char *);
137bool xbps_array_add_cstring_nocopy(xbps_array_t,
138 const char *);
139bool xbps_array_get_cstring_nocopy(xbps_array_t,
140 unsigned int,
141 const char **);
142bool xbps_array_set_cstring_nocopy(xbps_array_t,
143 unsigned int,
144 const char *);
145bool xbps_array_add_and_rel(xbps_array_t, xbps_object_t);
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif /* _XBPS_ARRAY_H_ */