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:
authorBastien Montagne <bastien@blender.org>2020-09-18 16:16:30 +0300
committerBastien Montagne <bastien@blender.org>2020-09-20 17:26:39 +0300
commit5e509a3aa9d1f14d3293da3b0cc72fb633d7773a (patch)
treee716b732269221d1245ea19c4c32093dbb01b347 /source/blender/makesrna
parent8afa42b05a260eb4b77327b296e19b24b74b123b (diff)
RNA access: Add utils to search a collection item from its name, and get both item pointer and its index in the collection.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h2
-rw-r--r--source/blender/makesrna/intern/rna_access.c22
2 files changed, 19 insertions, 5 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 7a72ba2dc14..38438f66a0f 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -1029,6 +1029,8 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr,
PropertyRNA *prop,
const char *key,
PointerRNA *r_ptr);
+int RNA_property_collection_lookup_string_index(
+ PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index);
int RNA_property_collection_assign_int(PointerRNA *ptr,
PropertyRNA *prop,
const int key,
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 793552c5c34..45508aec67a 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -4216,10 +4216,8 @@ int RNA_property_collection_lookup_int(PointerRNA *ptr,
}
}
-int RNA_property_collection_lookup_string(PointerRNA *ptr,
- PropertyRNA *prop,
- const char *key,
- PointerRNA *r_ptr)
+int RNA_property_collection_lookup_string_index(
+ PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(prop);
@@ -4237,9 +4235,10 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr,
int found = 0;
int keylen = strlen(key);
int namelen;
+ int index = 0;
RNA_property_collection_begin(ptr, prop, &iter);
- for (; iter.valid; RNA_property_collection_next(&iter)) {
+ for (; iter.valid; RNA_property_collection_next(&iter), index++) {
if (iter.ptr.data && iter.ptr.type->nameproperty) {
nameprop = iter.ptr.type->nameproperty;
@@ -4263,12 +4262,25 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr,
if (!iter.valid) {
memset(r_ptr, 0, sizeof(*r_ptr));
+ *r_index = -1;
+ }
+ else {
+ *r_index = index;
}
return iter.valid;
}
}
+int RNA_property_collection_lookup_string(PointerRNA *ptr,
+ PropertyRNA *prop,
+ const char *key,
+ PointerRNA *r_ptr)
+{
+ int index;
+ return RNA_property_collection_lookup_string_index(ptr, prop, key, r_ptr, &index);
+}
+
/* zero return is an assignment error */
int RNA_property_collection_assign_int(PointerRNA *ptr,
PropertyRNA *prop,