diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-03-04 02:07:58 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-03-04 02:07:58 +0400 |
commit | 1531e3677a639b9265d26d73e3bc5ee21e996af8 (patch) | |
tree | 4eaa8230aefc3a9071dc4d1359244aade8156e12 /source/blender/blenlib | |
parent | 685fda4f13715ccadb32fa72af1b557cb55c9574 (diff) |
bmesh py api
* add BLI_rfindlink for reverse index lookup (used so bm.select_history[-1] doesn't have to loop the entire list twice).
* add bm.select_history.active so you can get the last selected item or None without having to check seq length.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index b0a5e80d850..abe7eacb1ac 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -41,15 +41,16 @@ extern "C" { #endif void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink); -void *BLI_findlink(const struct ListBase *listbase, int number); int BLI_findindex(const struct ListBase *listbase, void *vlink); int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset); /* find forwards */ +void *BLI_findlink(const struct ListBase *listbase, int number); void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset); void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset); /* find backwards */ +void *BLI_rfindlink(const struct ListBase *listbase, int number); void *BLI_rfindstring(const struct ListBase *listbase, const char *id, const int offset); void *BLI_rfindstring_ptr(const struct ListBase *listbase, const char *id, const int offset); diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 52fd857d6e4..6155bf83a57 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -338,6 +338,21 @@ void *BLI_findlink(const ListBase *listbase, int number) return link; } +void *BLI_rfindlink(const ListBase *listbase, int number) +{ + Link *link = NULL; + + if (number >= 0) { + link = listbase->last; + while (link != NULL && number != 0) { + number--; + link = link->prev; + } + } + + return link; +} + int BLI_findindex(const ListBase *listbase, void *vlink) { Link *link= NULL; |