/* Copyright (c) 2008 The NetBSD Foundation, Inc.1* All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */2425#if !defined(ATF_C_DETAIL_LIST_H)26#define ATF_C_DETAIL_LIST_H2728#include <stdarg.h>29#include <stdbool.h>30#include <stddef.h>3132#include <atf-c/error_fwd.h>3334/* ---------------------------------------------------------------------35* The "atf_list_citer" type.36* --------------------------------------------------------------------- */3738struct atf_list_citer {39const struct atf_list *m_list;40const void *m_entry;41};42typedef struct atf_list_citer atf_list_citer_t;4344/* Getters. */45const void *atf_list_citer_data(const atf_list_citer_t);46atf_list_citer_t atf_list_citer_next(const atf_list_citer_t);4748/* Operators. */49bool atf_equal_list_citer_list_citer(const atf_list_citer_t,50const atf_list_citer_t);5152/* ---------------------------------------------------------------------53* The "atf_list_iter" type.54* --------------------------------------------------------------------- */5556struct atf_list_iter {57struct atf_list *m_list;58void *m_entry;59};60typedef struct atf_list_iter atf_list_iter_t;6162/* Getters. */63void *atf_list_iter_data(const atf_list_iter_t);64atf_list_iter_t atf_list_iter_next(const atf_list_iter_t);6566/* Operators. */67bool atf_equal_list_iter_list_iter(const atf_list_iter_t,68const atf_list_iter_t);6970/* ---------------------------------------------------------------------71* The "atf_list" type.72* --------------------------------------------------------------------- */7374struct atf_list {75void *m_begin;76void *m_end;7778size_t m_size;79};80typedef struct atf_list atf_list_t;8182/* Constructors and destructors */83atf_error_t atf_list_init(atf_list_t *);84void atf_list_fini(atf_list_t *);8586/* Getters. */87atf_list_iter_t atf_list_begin(atf_list_t *);88atf_list_citer_t atf_list_begin_c(const atf_list_t *);89atf_list_iter_t atf_list_end(atf_list_t *);90atf_list_citer_t atf_list_end_c(const atf_list_t *);91void *atf_list_index(atf_list_t *, const size_t);92const void *atf_list_index_c(const atf_list_t *, const size_t);93size_t atf_list_size(const atf_list_t *);94char **atf_list_to_charpp(const atf_list_t *);9596/* Modifiers. */97atf_error_t atf_list_append(atf_list_t *, void *, bool);98void atf_list_append_list(atf_list_t *, atf_list_t *);99100/* Macros. */101#define atf_list_for_each(iter, list) \102for (iter = atf_list_begin(list); \103!atf_equal_list_iter_list_iter((iter), atf_list_end(list)); \104iter = atf_list_iter_next(iter))105#define atf_list_for_each_c(iter, list) \106for (iter = atf_list_begin_c(list); \107!atf_equal_list_citer_list_citer((iter), atf_list_end_c(list)); \108iter = atf_list_citer_next(iter))109110#endif /* !defined(ATF_C_DETAIL_LIST_H) */111112113