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:
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_listbase.h2
-rw-r--r--source/blender/blenlib/intern/listbase.c38
2 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index abe7eacb1ac..1330a74bea3 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -48,11 +48,13 @@ int BLI_findstringindex(const struct ListBase *listbase, const char *id, const i
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);
+void *BLI_findptr(const struct ListBase *listbase, const void *ptr, 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);
+void *BLI_rfindptr(const struct ListBase *listbase, const void *ptr, const int offset);
void BLI_freelistN(struct ListBase *listbase);
void BLI_addtail(struct ListBase *listbase, void *vlink);
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index 8fe9a94b466..ad718ed8e11 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -439,6 +439,44 @@ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int of
return NULL;
}
+void *BLI_findptr(const ListBase *listbase, const void *ptr, const int offset)
+{
+ Link *link = NULL;
+ const void *ptr_iter;
+
+ if (listbase == NULL) return NULL;
+
+ for (link = listbase->first; link; link = link->next) {
+ /* exact copy of BLI_findstring(), except for this line */
+ ptr_iter = *((const char **)(((const char *)link) + offset));
+
+ if (ptr == ptr_iter) {
+ return link;
+ }
+ }
+
+ return NULL;
+}
+/* same as above but find reverse */
+void *BLI_rfindptr(const ListBase *listbase, const void *ptr, const int offset)
+{
+ Link *link = NULL;
+ const void *ptr_iter;
+
+ if (listbase == NULL) return NULL;
+
+ for (link = listbase->last; link; link = link->prev) {
+ /* exact copy of BLI_rfindstring(), except for this line */
+ ptr_iter = *((const char **)(((const char *)link) + offset));
+
+ if (ptr == ptr_iter) {
+ return link;
+ }
+ }
+
+ return NULL;
+}
+
int BLI_findstringindex(const ListBase *listbase, const char *id, const int offset)
{
Link *link = NULL;