openssl: update to 3.0.14
[openadk.git] / adk / tools / strmap.h
blob99687b236abd635bb01df6279171783815c5ac4f
1 /*
2 * strmap version 1.0.0
4 * ANSI C hash table for strings.
6 * strmap.h
8 * Copyright (c) 2009 Per Ola Kristensson.
10 * Per Ola Kristensson <pok21@cam.ac.uk>
11 * Inference Group, Department of Physics
12 * University of Cambridge
13 * Cavendish Laboratory
14 * JJ Thomson Avenue
15 * CB3 0HE Cambridge
16 * United Kingdom
18 * strmap is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Lesser General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * strmap is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with strmap. If not, see <http://www.gnu.org/licenses/>.
31 #ifndef _STRMAP_H_
32 #define _STRMAP_H_
34 #ifdef __cplusplus
35 extern "C"
37 #endif
39 #include <stdlib.h>
40 #include <string.h>
42 typedef struct StrMap StrMap;
45 * This callback function is called once per key-value when enumerating
46 * all keys associated to values.
48 * Parameters:
50 * key: A pointer to a null-terminated C string. The string must not
51 * be modified by the client.
53 * value: A pointer to a null-terminated C string. The string must
54 * not be modified by the client.
56 * obj: A pointer to a client-specific object. This parameter may be
57 * null.
59 * Return value: None.
61 typedef void(*strmap_enum_func)(const char *key, const char *value, const void *obj);
64 * Creates a string map.
66 * Parameters:
68 * capacity: The number of top-level slots this string map
69 * should allocate. This parameter must be > 0.
71 * Return value: A pointer to a string map object,
72 * or null if a new string map could not be allocated.
74 StrMap * strmap_new(unsigned int capacity);
77 * Releases all memory held by a string map object.
79 * Parameters:
81 * map: A pointer to a string map. This parameter cannot be null.
82 * If the supplied string map has been previously released, the
83 * behaviour of this function is undefined.
85 * Return value: None.
87 void strmap_delete(StrMap *map);
90 * Returns the value associated with the supplied key.
92 * Parameters:
94 * map: A pointer to a string map. This parameter cannot be null.
96 * key: A pointer to a null-terminated C string. This parameter cannot
97 * be null.
99 * out_buf: A pointer to an output buffer which will contain the value,
100 * if it exists and fits into the buffer.
102 * n_out_buf: The size of the output buffer in bytes.
104 * Return value: If out_buf is set to null and n_out_buf is set to 0 the return
105 * value will be the number of bytes required to store the value (if it exists)
106 * and its null-terminator. For all other parameter configurations the return value
107 * is 1 if an associated value was found and completely copied into the output buffer,
108 * 0 otherwise.
110 int strmap_get(const StrMap *map, const char *key, char *out_buf, unsigned int n_out_buf);
113 * Queries the existence of a key.
115 * Parameters:
117 * map: A pointer to a string map. This parameter cannot be null.
119 * key: A pointer to a null-terminated C string. This parameter cannot
120 * be null.
122 * Return value: 1 if the key exists, 0 otherwise.
124 int strmap_exists(const StrMap *map, const char *key);
127 * Associates a value with the supplied key. If the key is already
128 * associated with a value, the previous value is replaced.
130 * Parameters:
132 * map: A pointer to a string map. This parameter cannot be null.
134 * key: A pointer to a null-terminated C string. This parameter
135 * cannot be null. The string must have a string length > 0. The
136 * string will be copied.
138 * value: A pointer to a null-terminated C string. This parameter
139 * cannot be null. The string must have a string length > 0. The
140 * string will be copied.
142 * Return value: 1 if the association succeeded, 0 otherwise.
144 int strmap_put(StrMap *map, const char *key, const char *value);
147 * Returns the number of associations between keys and values.
149 * Parameters:
151 * map: A pointer to a string map. This parameter cannot be null.
153 * Return value: The number of associations between keys and values.
155 int strmap_get_count(const StrMap *map);
158 * Enumerates all associations between keys and values.
160 * Parameters:
162 * map: A pointer to a string map. This parameter cannot be null.
164 * enum_func: A pointer to a callback function that will be
165 * called by this procedure once for every key associated
166 * with a value. This parameter cannot be null.
168 * obj: A pointer to a client-specific object. This parameter will be
169 * passed back to the client's callback function. This parameter can
170 * be null.
172 * Return value: 1 if enumeration completed, 0 otherwise.
174 int strmap_enum(const StrMap *map, strmap_enum_func enum_func, const void *obj);
176 #ifdef __cplusplus
178 #endif
180 #endif
184 GNU LESSER GENERAL PUBLIC LICENSE
185 Version 3, 29 June 2007
187 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
188 Everyone is permitted to copy and distribute verbatim copies
189 of this license document, but changing it is not allowed.
192 This version of the GNU Lesser General Public License incorporates
193 the terms and conditions of version 3 of the GNU General Public
194 License, supplemented by the additional permissions listed below.
196 0. Additional Definitions.
198 As used herein, "this License" refers to version 3 of the GNU Lesser
199 General Public License, and the "GNU GPL" refers to version 3 of the GNU
200 General Public License.
202 "The Library" refers to a covered work governed by this License,
203 other than an Application or a Combined Work as defined below.
205 An "Application" is any work that makes use of an interface provided
206 by the Library, but which is not otherwise based on the Library.
207 Defining a subclass of a class defined by the Library is deemed a mode
208 of using an interface provided by the Library.
210 A "Combined Work" is a work produced by combining or linking an
211 Application with the Library. The particular version of the Library
212 with which the Combined Work was made is also called the "Linked
213 Version".
215 The "Minimal Corresponding Source" for a Combined Work means the
216 Corresponding Source for the Combined Work, excluding any source code
217 for portions of the Combined Work that, considered in isolation, are
218 based on the Application, and not on the Linked Version.
220 The "Corresponding Application Code" for a Combined Work means the
221 object code and/or source code for the Application, including any data
222 and utility programs needed for reproducing the Combined Work from the
223 Application, but excluding the System Libraries of the Combined Work.
225 1. Exception to Section 3 of the GNU GPL.
227 You may convey a covered work under sections 3 and 4 of this License
228 without being bound by section 3 of the GNU GPL.
230 2. Conveying Modified Versions.
232 If you modify a copy of the Library, and, in your modifications, a
233 facility refers to a function or data to be supplied by an Application
234 that uses the facility (other than as an argument passed when the
235 facility is invoked), then you may convey a copy of the modified
236 version:
238 a) under this License, provided that you make a good faith effort to
239 ensure that, in the event an Application does not supply the
240 function or data, the facility still operates, and performs
241 whatever part of its purpose remains meaningful, or
243 b) under the GNU GPL, with none of the additional permissions of
244 this License applicable to that copy.
246 3. Object Code Incorporating Material from Library Header Files.
248 The object code form of an Application may incorporate material from
249 a header file that is part of the Library. You may convey such object
250 code under terms of your choice, provided that, if the incorporated
251 material is not limited to numerical parameters, data structure
252 layouts and accessors, or small macros, inline functions and templates
253 (ten or fewer lines in length), you do both of the following:
255 a) Give prominent notice with each copy of the object code that the
256 Library is used in it and that the Library and its use are
257 covered by this License.
259 b) Accompany the object code with a copy of the GNU GPL and this license
260 document.
262 4. Combined Works.
264 You may convey a Combined Work under terms of your choice that,
265 taken together, effectively do not restrict modification of the
266 portions of the Library contained in the Combined Work and reverse
267 engineering for debugging such modifications, if you also do each of
268 the following:
270 a) Give prominent notice with each copy of the Combined Work that
271 the Library is used in it and that the Library and its use are
272 covered by this License.
274 b) Accompany the Combined Work with a copy of the GNU GPL and this license
275 document.
277 c) For a Combined Work that displays copyright notices during
278 execution, include the copyright notice for the Library among
279 these notices, as well as a reference directing the user to the
280 copies of the GNU GPL and this license document.
282 d) Do one of the following:
284 0) Convey the Minimal Corresponding Source under the terms of this
285 License, and the Corresponding Application Code in a form
286 suitable for, and under terms that permit, the user to
287 recombine or relink the Application with a modified version of
288 the Linked Version to produce a modified Combined Work, in the
289 manner specified by section 6 of the GNU GPL for conveying
290 Corresponding Source.
292 1) Use a suitable shared library mechanism for linking with the
293 Library. A suitable mechanism is one that (a) uses at run time
294 a copy of the Library already present on the user's computer
295 system, and (b) will operate properly with a modified version
296 of the Library that is interface-compatible with the Linked
297 Version.
299 e) Provide Installation Information, but only if you would otherwise
300 be required to provide such information under section 6 of the
301 GNU GPL, and only to the extent that such information is
302 necessary to install and execute a modified version of the
303 Combined Work produced by recombining or relinking the
304 Application with a modified version of the Linked Version. (If
305 you use option 4d0, the Installation Information must accompany
306 the Minimal Corresponding Source and Corresponding Application
307 Code. If you use option 4d1, you must provide the Installation
308 Information in the manner specified by section 6 of the GNU GPL
309 for conveying Corresponding Source.)
311 5. Combined Libraries.
313 You may place library facilities that are a work based on the
314 Library side by side in a single library together with other library
315 facilities that are not Applications and are not covered by this
316 License, and convey such a combined library under terms of your
317 choice, if you do both of the following:
319 a) Accompany the combined library with a copy of the same work based
320 on the Library, uncombined with any other library facilities,
321 conveyed under the terms of this License.
323 b) Give prominent notice with the combined library that part of it
324 is a work based on the Library, and explaining where to find the
325 accompanying uncombined form of the same work.
327 6. Revised Versions of the GNU Lesser General Public License.
329 The Free Software Foundation may publish revised and/or new versions
330 of the GNU Lesser General Public License from time to time. Such new
331 versions will be similar in spirit to the present version, but may
332 differ in detail to address new problems or concerns.
334 Each version is given a distinguishing version number. If the
335 Library as you received it specifies that a certain numbered version
336 of the GNU Lesser General Public License "or any later version"
337 applies to it, you have the option of following the terms and
338 conditions either of that published version or of any later version
339 published by the Free Software Foundation. If the Library as you
340 received it does not specify a version number of the GNU Lesser
341 General Public License, you may choose any version of the GNU Lesser
342 General Public License ever published by the Free Software Foundation.
344 If the Library as you received it specifies that a proxy can decide
345 whether future versions of the GNU Lesser General Public License shall
346 apply, that proxy's public statement of acceptance of any version is
347 permanent authorization for you to choose that version for the
348 Library.