include/dlinklist.h

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    some simple double linked list macros
00004    Copyright (C) Andrew Tridgell 1998
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 /* To use these macros you must have a structure containing a next and
00022    prev pointer */
00023 
00024 #ifndef _DLINKLIST_H
00025 #define _DLINKLIST_H
00026 
00027 
00028 /* hook into the front of the list */
00029 #define DLIST_ADD(list, p) \
00030 do { \
00031         if (!(list)) { \
00032                 (list) = (p); \
00033                 (p)->next = (p)->prev = NULL; \
00034         } else { \
00035                 (list)->prev = (p); \
00036                 (p)->next = (list); \
00037                 (p)->prev = NULL; \
00038                 (list) = (p); \
00039         }\
00040 } while (0)
00041 
00042 /* remove an element from a list - element doesn't have to be in list. */
00043 #define DLIST_REMOVE(list, p) \
00044 do { \
00045         if ((p) == (list)) { \
00046                 (list) = (p)->next; \
00047                 if (list) (list)->prev = NULL; \
00048         } else { \
00049                 if ((p)->prev) (p)->prev->next = (p)->next; \
00050                 if ((p)->next) (p)->next->prev = (p)->prev; \
00051         } \
00052         if ((p) != (list)) (p)->next = (p)->prev = NULL; \
00053 } while (0)
00054 
00055 /* promote an element to the top of the list */
00056 #define DLIST_PROMOTE(list, p) \
00057 do { \
00058           DLIST_REMOVE(list, p); \
00059           DLIST_ADD(list, p); \
00060 } while (0)
00061 
00062 /* hook into the end of the list - needs the entry type */
00063 #define DLIST_ADD_END(list, p, type) \
00064 do { \
00065                 if (!(list)) { \
00066                         (list) = (p); \
00067                         (p)->next = (p)->prev = NULL; \
00068                 } else { \
00069                         type tmp; \
00070                         for (tmp = (list); tmp->next; tmp = tmp->next) ; \
00071                         tmp->next = (p); \
00072                         (p)->next = NULL; \
00073                         (p)->prev = tmp; \
00074                 } \
00075 } while (0)
00076 
00077 /* insert 'p' after the given element 'el' in a list. If el is NULL then
00078    this is the same as a DLIST_ADD() */
00079 #define DLIST_ADD_AFTER(list, p, el) \
00080 do { \
00081         if (!(list) || !(el)) { \
00082                 DLIST_ADD(list, p); \
00083         } else { \
00084                 p->prev = el; \
00085                 p->next = el->next; \
00086                 el->next = p; \
00087                 if (p->next) p->next->prev = p; \
00088         }\
00089 } while (0)
00090 
00091 /* demote an element to the end of the list, needs a tmp pointer */
00092 #define DLIST_DEMOTE(list, p, tmp) \
00093 do { \
00094                 DLIST_REMOVE(list, p); \
00095                 DLIST_ADD_END(list, p, tmp); \
00096 } while (0)
00097 
00098 /* concatenate two lists - putting all elements of the 2nd list at the
00099    end of the first list */
00100 #define DLIST_CONCATENATE(list1, list2, type) \
00101 do { \
00102                 if (!(list1)) { \
00103                         (list1) = (list2); \
00104                 } else { \
00105                         type tmp; \
00106                         for (tmp = (list1); tmp->next; tmp = tmp->next) ; \
00107                         tmp->next = (list2); \
00108                         if (list2) { \
00109                                 (list2)->prev = tmp;    \
00110                         } \
00111                 } \
00112 } while (0)
00113 
00114 #endif /* _DLINKLIST_H */

Sambaに対してSat Aug 29 21:22:54 2009に生成されました。  doxygen 1.4.7