Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-05-11 16:18:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-05-11 16:18:12 +0400
commita19f7899fbc71b696ee803f47df3c9ce1657d09b (patch)
treeb2e48c5fc9937818b6ea1bed08b70b82123535a2 /source/blender/blenlib
parenta919b0e4c3968dac3f357b2d65d1f2c9b285168b (diff)
utility functions to reverse and rotate linklists.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_listbase.h2
-rw-r--r--source/blender/blenlib/intern/listbase.c40
2 files changed, 41 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index 41968f1ebd6..767f61b29dd 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -71,6 +71,8 @@ void BLI_freelinkN(struct ListBase *listbase, void *vlink);
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);
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index 00b2d3bee74..f5f67ba3645 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -543,8 +543,10 @@ int BLI_findstringindex(const ListBase *listbase, const char *id, const int offs
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_duplicatelist(ListBase *dst, const ListBase *src)
}
}
+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)
{