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-04-25 21:58:55 +0300
committerBastien Montagne <bastien@blender.org>2020-04-28 16:25:19 +0300
commit9f090bac5c7455ab22cd22cc3f6ea94b54d6de33 (patch)
treec434f5958335b1f4be6f2de7aba8c240ed8bc1e6 /source/blender/blenkernel/intern/idprop.c
parent7d85b6431fc331d9869f945bf7c9f3353b7b8c95 (diff)
IDProperties: add a foreach looper and use it in libquery code.
Note: part of fix for T75279. Differential Revision: https://developer.blender.org/D7550
Diffstat (limited to 'source/blender/blenkernel/intern/idprop.c')
-rw-r--r--source/blender/blenkernel/intern/idprop.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index 5530a126ffc..669539ca574 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -1130,4 +1130,45 @@ void IDP_Reset(IDProperty *prop, const IDProperty *reference)
}
}
+/**
+ * Loop through all ID properties in hierarchy of given \a id_property_root included.
+ *
+ * \note Container types (groups and arrays) are processed after applying the callback on them.
+ *
+ * \param type_filter: If not 0, only apply callback on properties of matching types, see
+ * IDP_TYPE_FILTER_ enum in DNA_ID.h.
+ */
+void IDP_foreach_property(IDProperty *id_property_root,
+ const int type_filter,
+ IDPForeachPropertyCallback callback,
+ void *user_data)
+{
+ if (!id_property_root) {
+ return;
+ }
+
+ if (type_filter == 0 || (1 << id_property_root->type) & type_filter) {
+ callback(id_property_root, user_data);
+ }
+
+ /* Recursive call into container types of ID properties. */
+ switch (id_property_root->type) {
+ case IDP_GROUP: {
+ LISTBASE_FOREACH (IDProperty *, loop, &id_property_root->data.group) {
+ IDP_foreach_property(loop, type_filter, callback, user_data);
+ }
+ break;
+ }
+ case IDP_IDPARRAY: {
+ IDProperty *loop = IDP_Array(id_property_root);
+ for (int i = 0; i < id_property_root->len; i++) {
+ IDP_foreach_property(&loop[i], type_filter, callback, user_data);
+ }
+ break;
+ }
+ default:
+ break; /* Nothing to do here with other types of IDProperties... */
+ }
+}
+
/** \} */