1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26 #if !defined(ATF_C_DETAIL_MAP_H)
27 #define ATF_C_DETAIL_MAP_H
32 #include <atf-c/detail/list.h>
33 #include <atf-c/error_fwd.h>
35 /* ---------------------------------------------------------------------
36 * The "atf_map_citer" type.
37 * --------------------------------------------------------------------- */
39 struct atf_map_citer {
40 const struct atf_map *m_map;
42 atf_list_citer_t m_listiter;
44 typedef struct atf_map_citer atf_map_citer_t;
47 const char *atf_map_citer_key(const atf_map_citer_t);
48 const void *atf_map_citer_data(const atf_map_citer_t);
49 atf_map_citer_t atf_map_citer_next(const atf_map_citer_t);
52 bool atf_equal_map_citer_map_citer(const atf_map_citer_t,
53 const atf_map_citer_t);
55 /* ---------------------------------------------------------------------
56 * The "atf_map_iter" type.
57 * --------------------------------------------------------------------- */
60 struct atf_map *m_map;
62 atf_list_iter_t m_listiter;
64 typedef struct atf_map_iter atf_map_iter_t;
67 const char *atf_map_iter_key(const atf_map_iter_t);
68 void *atf_map_iter_data(const atf_map_iter_t);
69 atf_map_iter_t atf_map_iter_next(const atf_map_iter_t);
72 bool atf_equal_map_iter_map_iter(const atf_map_iter_t,
73 const atf_map_iter_t);
75 /* ---------------------------------------------------------------------
77 * --------------------------------------------------------------------- */
79 /* A list-based map. Typically very inefficient, but our maps are small
84 typedef struct atf_map atf_map_t;
86 /* Constructors and destructors */
87 atf_error_t atf_map_init(atf_map_t *);
88 atf_error_t atf_map_init_charpp(atf_map_t *, const char *const *);
89 void atf_map_fini(atf_map_t *);
92 atf_map_iter_t atf_map_begin(atf_map_t *);
93 atf_map_citer_t atf_map_begin_c(const atf_map_t *);
94 atf_map_iter_t atf_map_end(atf_map_t *);
95 atf_map_citer_t atf_map_end_c(const atf_map_t *);
96 atf_map_iter_t atf_map_find(atf_map_t *, const char *);
97 atf_map_citer_t atf_map_find_c(const atf_map_t *, const char *);
98 size_t atf_map_size(const atf_map_t *);
99 char **atf_map_to_charpp(const atf_map_t *);
102 atf_error_t atf_map_insert(atf_map_t *, const char *, void *, bool);
105 #define atf_map_for_each(iter, map) \
106 for (iter = atf_map_begin(map); \
107 !atf_equal_map_iter_map_iter((iter), atf_map_end(map)); \
108 iter = atf_map_iter_next(iter))
109 #define atf_map_for_each_c(iter, map) \
110 for (iter = atf_map_begin_c(map); \
111 !atf_equal_map_citer_map_citer((iter), atf_map_end_c(map)); \
112 iter = atf_map_citer_next(iter))
114 #endif /* !defined(ATF_C_DETAIL_MAP_H) */