RNA access: Add utils to search a collection item from its name, and get both item pointer and its index in the collection.
This commit is contained in:
parent
8afa42b05a
commit
5e509a3aa9
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue