diff options
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; |