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/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h6
-rw-r--r--source/blender/makesrna/intern/rna_access.c21
2 files changed, 27 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 5441cf44ac9..eb25733a88a 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -1117,6 +1117,11 @@ void RNA_property_collection_next(CollectionPropertyIterator *iter);
void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num);
void RNA_property_collection_end(CollectionPropertyIterator *iter);
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop);
+/**
+ * Return true when `RNA_property_collection_length(ptr, prop) == 0`,
+ * without having to iterate over items in the collection (needed for some kinds of collections).
+ */
+bool RNA_property_collection_is_empty(PointerRNA *ptr, PropertyRNA *prop);
int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *t_ptr);
int RNA_property_collection_lookup_int(PointerRNA *ptr,
PropertyRNA *prop,
@@ -1445,6 +1450,7 @@ void RNA_pointer_add(PointerRNA *ptr, const char *name);
void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter);
int RNA_collection_length(PointerRNA *ptr, const char *name);
+bool RNA_collection_is_empty(PointerRNA *ptr, const char *name);
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value);
void RNA_collection_clear(PointerRNA *ptr, const char *name);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 8189dc6b16f..6c3b46c4408 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -3753,6 +3753,16 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
return length;
}
+bool RNA_property_collection_is_empty(PointerRNA *ptr, PropertyRNA *prop)
+{
+ BLI_assert(RNA_property_type(prop) == PROP_COLLECTION);
+ CollectionPropertyIterator iter;
+ RNA_property_collection_begin(ptr, prop, &iter);
+ bool test = iter.valid;
+ RNA_property_collection_end(&iter);
+ return !test;
+}
+
/* This helper checks whether given collection property itself is editable (we only currently
* support a limited set of operations, insertion of new items, and re-ordering of those new items
* exclusively). */
@@ -6417,6 +6427,17 @@ int RNA_collection_length(PointerRNA *ptr, const char *name)
return 0;
}
+bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
+{
+ PropertyRNA *prop = RNA_struct_find_property(ptr, name);
+
+ if (prop) {
+ return RNA_property_collection_is_empty(ptr, prop);
+ }
+ printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
+ return false;
+}
+
bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
{
prop = rna_ensure_property(prop);