[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28828] branches/render25/source/blender/ blenlib: Render Branch: two utility functions:

Brecht Van Lommel brecht at blender.org
Tue May 18 16:35:58 CEST 2010


Revision: 28828
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28828
Author:   blendix
Date:     2010-05-18 16:35:53 +0200 (Tue, 18 May 2010)

Log Message:
-----------
Render Branch: two utility functions:

BLI_linklist_find: find link at an index
BLI_linklist_insert_after: insert link after another one

Modified Paths:
--------------
    branches/render25/source/blender/blenlib/BLI_linklist.h
    branches/render25/source/blender/blenlib/intern/BLI_linklist.c

Modified: branches/render25/source/blender/blenlib/BLI_linklist.h
===================================================================
--- branches/render25/source/blender/blenlib/BLI_linklist.h	2010-05-18 14:30:33 UTC (rev 28827)
+++ branches/render25/source/blender/blenlib/BLI_linklist.h	2010-05-18 14:35:53 UTC (rev 28828)
@@ -45,13 +45,16 @@
 } LinkNode;
 
 int		BLI_linklist_length		(struct LinkNode *list);
-int		BLI_linklist_index		(struct LinkNode *list, void *ptr);
+int		BLI_linklist_index			(struct LinkNode *list, void *ptr);
 
+struct LinkNode *BLI_linklist_find	(struct LinkNode *list, int index);
+
 void	BLI_linklist_reverse	(struct LinkNode **listp);
 
 void	BLI_linklist_prepend		(struct LinkNode **listp, void *ptr);
 void	BLI_linklist_append	    	(struct LinkNode **listp, void *ptr);
 void	BLI_linklist_prepend_arena	(struct LinkNode **listp, void *ptr, struct MemArena *ma);
+void	BLI_linklist_insert_after	(struct LinkNode **listp, void *ptr);
 
 void	BLI_linklist_free		(struct LinkNode *list, LinkNodeFreeFP freefunc);
 void	BLI_linklist_apply		(struct LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata);

Modified: branches/render25/source/blender/blenlib/intern/BLI_linklist.c
===================================================================
--- branches/render25/source/blender/blenlib/intern/BLI_linklist.c	2010-05-18 14:30:33 UTC (rev 28827)
+++ branches/render25/source/blender/blenlib/intern/BLI_linklist.c	2010-05-18 14:35:53 UTC (rev 28828)
@@ -45,18 +45,28 @@
 	}
 }
 
-int BLI_linklist_index(struct LinkNode *list, void *ptr)
+int BLI_linklist_index(LinkNode *list, void *ptr)
 {
 	int index;
 	
-	for (index = 0; list; list= list->next, index++) {
+	for (index = 0; list; list= list->next, index++)
 		if (list->link == ptr)
 			return index;
-	}
 	
 	return -1;
 }
 
+LinkNode *BLI_linklist_find(LinkNode *list, int index)
+{
+	int i;
+	
+	for (i = 0; list; list= list->next, i++)
+		if (i == index)
+			return list;
+
+	return NULL;
+}
+
 void BLI_linklist_reverse(LinkNode **listp) {
 	LinkNode *rhead= NULL, *cur= *listp;
 	
@@ -105,6 +115,22 @@
 	*listp= nlink;
 }
 
+void BLI_linklist_insert_after(LinkNode **listp, void *ptr) {
+	LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink");
+	LinkNode *node = *listp;
+
+	nlink->link = ptr;
+
+	if(node) {
+		nlink->next = node->next;
+		node->next = nlink;
+	}
+	else {
+		nlink->next = NULL;
+		*listp = nlink;
+	}
+}
+
 void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) {
 	while (list) {
 		LinkNode *next= list->next;





More information about the Bf-blender-cvs mailing list