1 /* Copyright (c) 2008 The NetBSD Foundation, Inc. 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. */ 25 26 #if !defined(ATF_C_DETAIL_LIST_H) 27 #define ATF_C_DETAIL_LIST_H 28 29 #include <stdarg.h> 30 #include <stdbool.h> 31 #include <stddef.h> 32 33 #include <atf-c/error_fwd.h> 34 35 /* --------------------------------------------------------------------- 36 * The "atf_list_citer" type. 37 * --------------------------------------------------------------------- */ 38 39 struct atf_list_citer { 40 const struct atf_list *m_list; 41 const void *m_entry; 42 }; 43 typedef struct atf_list_citer atf_list_citer_t; 44 45 /* Getters. */ 46 const void *atf_list_citer_data(const atf_list_citer_t); 47 atf_list_citer_t atf_list_citer_next(const atf_list_citer_t); 48 49 /* Operators. */ 50 bool atf_equal_list_citer_list_citer(const atf_list_citer_t, 51 const atf_list_citer_t); 52 53 /* --------------------------------------------------------------------- 54 * The "atf_list_iter" type. 55 * --------------------------------------------------------------------- */ 56 57 struct atf_list_iter { 58 struct atf_list *m_list; 59 void *m_entry; 60 }; 61 typedef struct atf_list_iter atf_list_iter_t; 62 63 /* Getters. */ 64 void *atf_list_iter_data(const atf_list_iter_t); 65 atf_list_iter_t atf_list_iter_next(const atf_list_iter_t); 66 67 /* Operators. */ 68 bool atf_equal_list_iter_list_iter(const atf_list_iter_t, 69 const atf_list_iter_t); 70 71 /* --------------------------------------------------------------------- 72 * The "atf_list" type. 73 * --------------------------------------------------------------------- */ 74 75 struct atf_list { 76 void *m_begin; 77 void *m_end; 78 79 size_t m_size; 80 }; 81 typedef struct atf_list atf_list_t; 82 83 /* Constructors and destructors */ 84 atf_error_t atf_list_init(atf_list_t *); 85 void atf_list_fini(atf_list_t *); 86 87 /* Getters. */ 88 atf_list_iter_t atf_list_begin(atf_list_t *); 89 atf_list_citer_t atf_list_begin_c(const atf_list_t *); 90 atf_list_iter_t atf_list_end(atf_list_t *); 91 atf_list_citer_t atf_list_end_c(const atf_list_t *); 92 void *atf_list_index(atf_list_t *, const size_t); 93 const void *atf_list_index_c(const atf_list_t *, const size_t); 94 size_t atf_list_size(const atf_list_t *); 95 char **atf_list_to_charpp(const atf_list_t *); 96 97 /* Modifiers. */ 98 atf_error_t atf_list_append(atf_list_t *, void *, bool); 99 void atf_list_append_list(atf_list_t *, atf_list_t *); 100 101 /* Macros. */ 102 #define atf_list_for_each(iter, list) \ 103 for (iter = atf_list_begin(list); \ 104 !atf_equal_list_iter_list_iter((iter), atf_list_end(list)); \ 105 iter = atf_list_iter_next(iter)) 106 #define atf_list_for_each_c(iter, list) \ 107 for (iter = atf_list_begin_c(list); \ 108 !atf_equal_list_citer_list_citer((iter), atf_list_end_c(list)); \ 109 iter = atf_list_citer_next(iter)) 110 111 #endif /* !defined(ATF_C_DETAIL_LIST_H) */ 112