Main Page | Class List | File List | Class Members | File Members

listnode.h

00001 /*
00002  * Copyright 2003, 2004 Ian Searle. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following
00006  * conditions are met:  
00007  *
00008  * 1: Redistributions of source code must retain the above
00009  * copyright notice, this list of conditions and the following
00010  * disclaimer. 
00011  *
00012  * 2: Redistributions in binary form must reproduce the above
00013  * copyright notice, this list of conditions and the following
00014  * disclaimer in the documentation and/or other materials
00015  * provided with the distribution. 
00016  *
00017  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY  EXPRESS OR IMPLIED
00018  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL IAN SEARLE OR CONTRIBUTORS
00021  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
00022  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00024  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00025  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00027  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00028  * DAMAGE. 
00029  *
00030  */
00031 
00032 #ifndef  LIST_NODE_H
00033 #define  LIST_NODE_H
00034 
00035 #include <stdlib.h>
00036 
00038 typedef struct _listNode ListNode;
00039 
00041 struct _listNode {
00042   void *data;               
00043   void (*delete) (void *);  
00044   ListNode *next;           
00045   ListNode *prev;           
00046 };
00047 
00048 void listNode_Init(void *(*ln_allocate)(size_t size), void (*ln_deallocate)(void *ptr));
00049 
00050 extern ListNode *listNode_Create (void);
00051 
00052 /*
00053  * Destroy a ListNode. The node itself is destroyed (free'd).
00054  * The data is untouched.  If you want to destroy the data,
00055  * you have to do it yourself.
00056  */
00057 extern void listNode_Destroy (ListNode *);
00058 
00059 /*
00060  * Copy a ListNode.  Note that the copy contains the same
00061  * data value pointer. The data is NOT copied. 
00062  */
00063 extern ListNode *listNode_Copy (ListNode *lnode);
00064 
00065 extern int listNode_AttachAhead (ListNode *, ListNode *);
00066 extern int listNode_AttachBehind (ListNode *, ListNode *);
00067 
00068 extern ListNode *listNode_AttachData (ListNode *lnode, void *data, void (*delete)(void *));
00069 
00070 extern int listNode_Detach (ListNode *);
00071 
00072 extern void listNode_Print (ListNode *listNode);
00073 
00074 #define listNode_IsNodeAttached(lnode) ((lnode->next || lnode->prev) ? 1 : 0)
00075 
00076 #define listNode_GetNodeAhead(lnode)     (lnode->next);
00077 #define listNode_GetNodeBehind(lnode)    (lnode->prev);
00078 
00079 #define listNode_GetNextNode(lnode)      (lnode->next)
00080 #define listNode_GetPrevNode(lnode)      (lnode->prev)
00081 
00082 #define listNode_GetData(a)              (((ListNode *) (a))->data)
00083 #define listNode_GetDelete(a)            (((ListNode *) (a))->delete)
00084 #endif /* LIST_NODE_H */

Generated on Wed Feb 25 23:01:10 2004 by doxygen 1.3.4