Nut/OS  4.10.3
API Reference
lili.h
Go to the documentation of this file.
00001 #ifndef GORP_LILI_LILI_H
00002 #define GORP_LILI_LILI_H
00003 
00004 /*
00005  * Copyright 2010 by egnite GmbH
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the copyright holders nor the names of
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00029  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00030  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00032  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * For additional information see http://www.ethernut.de/
00036  */
00037 
00038 /*
00039  * \file include/gorp/lili.h
00040  * \brief Linked list definitions.
00041  *
00042  * \verbatim
00043  * $Id$
00044  * \endverbatim
00045  */
00046 
00047 #include <compiler.h>
00048 #include <stdint.h>
00049 
00054 
00058 #define LILI_F_LIFO     0x00
00059 
00060 #define LILI_F_FIFO     0x01
00061 
00062 #define LILI_F_SORT     0x02
00063 
00064 #define LILI_F_ORDER    0x03
00065 
00066 #define LILI_F_UNIQUE   0x80
00067 
00070 typedef intptr_t LILI_ITEMREF;
00071 
00072 typedef LILI_ITEMREF (*LiLiItemCreateFunc) (LILI_ITEMREF);
00073 typedef void (*LiLiItemDestroyFunc) (LILI_ITEMREF);
00074 typedef int (*LiLiItemCompareFunc) (LILI_ITEMREF, LILI_ITEMREF);
00075 
00077 typedef struct _LILI_NODE LILI_NODE;
00078 
00080 struct _LILI_NODE {
00081     LILI_NODE *nod_nxt;
00082     LILI_NODE *nod_prv;
00083     LILI_ITEMREF nod_itm;
00084 };
00085 
00087 typedef struct _LILI LILI;
00088 
00090 struct _LILI {
00091     LILI_NODE *lst_head;
00092     LILI_NODE *lst_tail;
00093     uint_fast8_t lst_flags;
00094     LiLiItemCreateFunc lst_icreate;
00095     LiLiItemDestroyFunc lst_idestroy;
00096     LiLiItemCompareFunc lst_icompare;
00097 };
00098 
00102 #define LiLiIsLifo(list) (((list)->lst_flags & LILI_F_ORDER) == LILI_F_LIFO)
00103 
00107 #define LiLiIsFifo(list) (((list)->lst_flags & LILI_F_ORDER) == LILI_F_FIFO)
00108 
00112 #define LiLiIsSorted(list) (((list)->lst_flags & LILI_F_ORDER) == LILI_F_SORT)
00113 
00117 #define LiLiIsEmpty(list) ((list)->lst_head == NULL)
00118 
00122 #define LiLiHasUniqueItems(list) (((list)->lst_flags & LILI_F_UNIQUE) == LILI_F_UNIQUE)
00123 
00127 #define LiLiFirstNode(list) ((list)->lst_head)
00128 
00132 #define LiLiLastNode(list) ((list)->lst_tail)
00133 
00137 #define LiLiNextNode(node) ((node)->nod_nxt)
00138 
00142 #define LiLiPreviousNode(node) ((node)->nod_prv)
00143 
00147 #define LiLiNodeItem(node) ((node)->nod_itm)
00148 
00151 __BEGIN_DECLS
00152 /* Prototypes */
00153 
00154 extern LILI *LiLiCreate(uint8_t flags, LiLiItemCreateFunc cre, LiLiItemDestroyFunc des, LiLiItemCompareFunc cmp);
00155 extern void LiLiClean(LILI *list);
00156 extern void LiLiDestroy(LILI *list);
00157 extern int LiLiNodes(LILI *list);
00158 
00159 extern int LiLiPushItem(LILI *list, LILI_ITEMREF ref);
00160 extern int LiLiPopItem(LILI *list, LILI_ITEMREF *refp);
00161 extern LILI_NODE *LiLiFindItem(LILI *list, LILI_ITEMREF ref);
00162 extern LILI_NODE *LiLiLocateItem(LILI *list, LILI_ITEMREF ref);
00163 
00164 extern LILI_NODE *LiLiInsertItemAfterNode(LILI *list, LILI_NODE *node, LILI_ITEMREF ref);
00165 extern LILI_NODE *LiLiInsertItemBeforeNode(LILI *list, LILI_NODE *node, LILI_ITEMREF ref);
00166 extern void LiLiRemoveNode(LILI *list, LILI_NODE *node);
00167 
00168 extern LILI_ITEMREF LiLiCreateStringItemCopy(LILI_ITEMREF ref);
00169 extern void LiLiDestroyStringItemCopy(LILI_ITEMREF ref);
00170 extern int LiLiCompareStringItems(LILI_ITEMREF ref1, LILI_ITEMREF ref2);
00171 
00172 __END_DECLS
00173 /* End of prototypes */
00174 #endif