[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56684] trunk/blender/source/blender/ blenlib: utility functions to reverse and rotate linklists.
Campbell Barton
ideasman42 at gmail.com
Sat May 11 14:18:12 CEST 2013
Revision: 56684
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56684
Author: campbellbarton
Date: 2013-05-11 12:18:12 +0000 (Sat, 11 May 2013)
Log Message:
-----------
utility functions to reverse and rotate linklists.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_listbase.h
trunk/blender/source/blender/blenlib/intern/listbase.c
Modified: trunk/blender/source/blender/blenlib/BLI_listbase.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_listbase.h 2013-05-11 10:15:27 UTC (rev 56683)
+++ trunk/blender/source/blender/blenlib/BLI_listbase.h 2013-05-11 12:18:12 UTC (rev 56684)
@@ -71,6 +71,8 @@
void BLI_movelisttolist(struct ListBase *dst, struct ListBase *src);
void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src);
+void BLI_reverselist(struct ListBase *lb);
+void BLI_rotatelist(struct ListBase *lb, LinkData *vlink);
/* create a generic list node containing link to provided data */
struct LinkData *BLI_genericNodeN(void *data);
Modified: trunk/blender/source/blender/blenlib/intern/listbase.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/listbase.c 2013-05-11 10:15:27 UTC (rev 56683)
+++ trunk/blender/source/blender/blenlib/intern/listbase.c 2013-05-11 12:18:12 UTC (rev 56684)
@@ -543,8 +543,10 @@
return -1;
}
+/**
+ * Sets dst to a duplicate of the entire contents of src. dst may be the same as src.
+ */
void BLI_duplicatelist(ListBase *dst, const ListBase *src)
-/* sets dst to a duplicate of the entire contents of src. dst may be the same as src. */
{
struct Link *dst_link, *src_link;
@@ -560,6 +562,42 @@
}
}
+void BLI_reverselist(ListBase *lb)
+{
+ struct Link *curr = lb->first;
+ struct Link *prev = NULL;
+ struct Link *next = NULL;
+ while(curr) {
+ next = curr->next;
+ curr->next = prev;
+ curr->prev = next;
+ prev = curr;
+ curr = next;
+ }
+
+ /* swap first/last */
+ curr = lb->first;
+ lb->first = lb->last;
+ lb->last = curr;
+}
+
+/**
+ * \param vlink Link to make first.
+ */
+void BLI_rotatelist(ListBase *lb, LinkData *vlink)
+{
+ /* make circular */
+ ((LinkData *)lb->first)->prev = lb->last;
+ ((LinkData *)lb->last)->next = lb->first;
+
+ lb->first = vlink;
+ lb->last = vlink->prev;
+
+ ((LinkData *)lb->first)->prev = NULL;
+ ((LinkData *)lb->last)->next = NULL;
+}
+
+
/* create a generic list node containing link to provided data */
LinkData *BLI_genericNodeN(void *data)
{
More information about the Bf-blender-cvs
mailing list