]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/clists.h
UCW::CGI: Bug fixes
[libucw.git] / ucw / clists.h
index bc8779d9d9e764ba7cbc4de9dd3cfd8f95782c7a..17d2201793b6b250f5c03e8465bc39dd358580b1 100644 (file)
@@ -73,15 +73,34 @@ static inline int clist_empty(clist *l)
   return (l->head.next == &l->head);
 }
 
   return (l->head.next == &l->head);
 }
 
+/**
+ * Loop over all nodes in the @list and perform the next C statement on them. The current node is stored in @n which must be defined before as pointer to any type.
+ * The list should not be changed during this loop command.
+ **/
 #define CLIST_WALK(n,list) for(n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
 #define CLIST_WALK(n,list) for(n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
+
+/**
+ * Same as @CLIST_WALK(), but allows removal of the current node. This macro requires one more variable to store some temporary pointers.
+ **/
 #define CLIST_WALK_DELSAFE(n,list,tmp) for(n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
 #define CLIST_WALK_DELSAFE(n,list,tmp) for(n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
+
+/**
+ * Same as @CLIST_WALK(), but it defines the variable for the current node in place. @type should be a pointer type.
+ **/
 #define CLIST_FOR_EACH(type,n,list) for(type n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
 #define CLIST_FOR_EACH(type,n,list) for(type n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
+
+/**
+ * Same as @CLIST_WALK_DELSAFE(), but it defines the variable for the current node in place. @type should be a pointer type. The temporary variable must be still known before.
+ **/
 #define CLIST_FOR_EACH_DELSAFE(type,n,list,tmp) for(type n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
 
 #define CLIST_FOR_EACH_DELSAFE(type,n,list,tmp) for(type n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
 
+/**
+ * Reversed version of @CLIST_FOR_EACH().
+ **/
 #define CLIST_FOR_EACH_BACKWARDS(type,n,list) for(type n=(void*)(list).head.prev; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->prev)
 
 /**
 #define CLIST_FOR_EACH_BACKWARDS(type,n,list) for(type n=(void*)(list).head.prev; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->prev)
 
 /**
- * Insert a new node just after the node @after. To insert a new head, use @clist_add_head() instead.
+ * Insert a new node just after the node @after. To insert at the head of the list, use @clist_add_head() instead.
  **/
 static inline void clist_insert_after(cnode *what, cnode *after)
 {
  **/
 static inline void clist_insert_after(cnode *what, cnode *after)
 {
@@ -93,7 +112,7 @@ static inline void clist_insert_after(cnode *what, cnode *after)
 }
 
 /**
 }
 
 /**
- * Insert a new node just before the node @before. To insert a new tail, use @clist_add_tail() instead.
+ * Insert a new node just before the node @before. To insert at the tail of the list, use @clist_add_tail() instead.
  **/
 static inline void clist_insert_before(cnode *what, cnode *before)
 {
  **/
 static inline void clist_insert_before(cnode *what, cnode *before)
 {
@@ -170,6 +189,17 @@ static inline void clist_insert_list_after(clist *what, cnode *after)
     }
 }
 
     }
 }
 
+/**
+ * Move all items from a source list to a destination list. The source list
+ * becomes empty, the original contents of the destination list are destroyed.
+ **/
+static inline void clist_move(clist *to, clist *from)
+{
+  clist_init(to);
+  clist_insert_list_after(from, &to->head);
+  clist_init(from);
+}
+
 /**
  * Compute the number of nodes in @l. Beware linear time complexity.
  **/
 /**
  * Compute the number of nodes in @l. Beware linear time complexity.
  **/