/*
 * This file is part of the Poliqarp suite.
 * 
 * Copyright (C) 2009 by Instytut Podstaw Informatyki Polskiej
 * Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 * Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file gpl.txt included in the packaging
 * of this file.  (See http://www.gnu.org/licenses/translations.html for
 * unofficial translations.)
 * 
 * A commercial license is available from IPI PAN (contact
 * Michal.Ciesiolka@ipipan.waw.pl or ipi@ipipan.waw.pl for more
 * information).  Licensees holding a valid commercial license from IPI
 * PAN may use this file in accordance with that license.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

#ifndef BPNG_LIST_H
#define BPNG_LIST_H 1

#include <stddef.h>

/**
 * A list.
 */
struct list {
   size_t length;
   size_t capacity;
   void **items;
};

#define list_empty_body {\
   .length = 0,\
   .capacity = 0,\
   .items = NULL\
}

/**
 * An empty list.
 */
static const struct list list_empty = list_empty_body;

typedef void (*list_destroy_fn)(void *fn);

/**
 * Remove all elements of the list.
 * @note Memory is not freed.
 * @see list_destroy
 * @param fn function to be called on each removed, or NULL
 */
void list_clear(struct list *, list_destroy_fn fn);

/**
 * Destroy the entire list.
 * @param fn function to be called on each item, or NULL
 */
void list_destroy(struct list *, list_destroy_fn fn);

/** Append the new item to the end of the list. */
void list_append(struct list *, void *item);

/** Remove and return the last element of the list. */
void *list_pop(struct list *);

#endif /* BPNG_LIST_H */
