/* 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_MAP_H)26#define ATF_C_DETAIL_MAP_H2728#include <stdarg.h>29#include <stdbool.h>3031#include <atf-c/detail/list.h>32#include <atf-c/error_fwd.h>3334/* ---------------------------------------------------------------------35* The "atf_map_citer" type.36* --------------------------------------------------------------------- */3738struct atf_map_citer {39const struct atf_map *m_map;40const void *m_entry;41atf_list_citer_t m_listiter;42};43typedef struct atf_map_citer atf_map_citer_t;4445/* Getters. */46const char *atf_map_citer_key(const atf_map_citer_t);47const void *atf_map_citer_data(const atf_map_citer_t);48atf_map_citer_t atf_map_citer_next(const atf_map_citer_t);4950/* Operators. */51bool atf_equal_map_citer_map_citer(const atf_map_citer_t,52const atf_map_citer_t);5354/* ---------------------------------------------------------------------55* The "atf_map_iter" type.56* --------------------------------------------------------------------- */5758struct atf_map_iter {59struct atf_map *m_map;60void *m_entry;61atf_list_iter_t m_listiter;62};63typedef struct atf_map_iter atf_map_iter_t;6465/* Getters. */66const char *atf_map_iter_key(const atf_map_iter_t);67void *atf_map_iter_data(const atf_map_iter_t);68atf_map_iter_t atf_map_iter_next(const atf_map_iter_t);6970/* Operators. */71bool atf_equal_map_iter_map_iter(const atf_map_iter_t,72const atf_map_iter_t);7374/* ---------------------------------------------------------------------75* The "atf_map" type.76* --------------------------------------------------------------------- */7778/* A list-based map. Typically very inefficient, but our maps are small79* enough. */80struct atf_map {81atf_list_t m_list;82};83typedef struct atf_map atf_map_t;8485/* Constructors and destructors */86atf_error_t atf_map_init(atf_map_t *);87atf_error_t atf_map_init_charpp(atf_map_t *, const char *const *);88void atf_map_fini(atf_map_t *);8990/* Getters. */91atf_map_iter_t atf_map_begin(atf_map_t *);92atf_map_citer_t atf_map_begin_c(const atf_map_t *);93atf_map_iter_t atf_map_end(atf_map_t *);94atf_map_citer_t atf_map_end_c(const atf_map_t *);95atf_map_iter_t atf_map_find(atf_map_t *, const char *);96atf_map_citer_t atf_map_find_c(const atf_map_t *, const char *);97size_t atf_map_size(const atf_map_t *);98char **atf_map_to_charpp(const atf_map_t *);99100/* Modifiers. */101atf_error_t atf_map_insert(atf_map_t *, const char *, void *, bool);102103/* Macros. */104#define atf_map_for_each(iter, map) \105for (iter = atf_map_begin(map); \106!atf_equal_map_iter_map_iter((iter), atf_map_end(map)); \107iter = atf_map_iter_next(iter))108#define atf_map_for_each_c(iter, map) \109for (iter = atf_map_begin_c(map); \110!atf_equal_map_citer_map_citer((iter), atf_map_end_c(map)); \111iter = atf_map_citer_next(iter))112113#endif /* !defined(ATF_C_DETAIL_MAP_H) */114115116