diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index b0c874b64..5728983a6 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -17193,6 +17193,33 @@ clutter_actor_iter_init (ClutterActorIter *iter, ri->age = root->priv->age; } +/** + * clutter_actor_iter_is_valid: + * @iter: a #ClutterActorIter + * + * Checks whether a #ClutterActorIter is still valid. + * + * An iterator is considered valid if it has been initialized, and + * if the #ClutterActor that it refers to hasn't been modified after + * the initialization. + * + * Return value: %TRUE if the iterator is valid, and %FALSE otherwise + * + * Since: 1.12 + */ +gboolean +clutter_actor_iter_is_valid (const ClutterActorIter *iter) +{ + RealActorIter *ri = (RealActorIter *) iter; + + g_return_val_if_fail (iter != NULL, FALSE); + + if (ri->root == NULL) + return FALSE; + + return ri->root->priv->age == ri->age; +} + /** * clutter_actor_iter_next: * @iter: a #ClutterActorIter diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h index ae95418df..e98cd5532 100644 --- a/clutter/clutter-actor.h +++ b/clutter/clutter-actor.h @@ -617,6 +617,8 @@ CLUTTER_AVAILABLE_IN_1_10 void clutter_actor_iter_remove (ClutterActorIter *iter); CLUTTER_AVAILABLE_IN_1_10 void clutter_actor_iter_destroy (ClutterActorIter *iter); +CLUTTER_AVAILABLE_IN_1_12 +gboolean clutter_actor_iter_is_valid (const ClutterActorIter *iter); /* Transformations */ gboolean clutter_actor_is_rotated (ClutterActor *self); diff --git a/clutter/clutter.symbols b/clutter/clutter.symbols index fd32e8246..39307e793 100644 --- a/clutter/clutter.symbols +++ b/clutter/clutter.symbols @@ -178,6 +178,7 @@ clutter_actor_is_rotated clutter_actor_is_scaled clutter_actor_iter_destroy clutter_actor_iter_init +clutter_actor_iter_is_valid clutter_actor_iter_next clutter_actor_iter_prev clutter_actor_iter_remove diff --git a/tests/conform/actor-iter.c b/tests/conform/actor-iter.c index 5633e2fec..4c550797b 100644 --- a/tests/conform/actor-iter.c +++ b/tests/conform/actor-iter.c @@ -33,6 +33,8 @@ actor_iter_traverse_children (TestConformSimpleFixture *fixture G_GNUC_UNUSED, i = 0; clutter_actor_iter_init (&iter, actor); + g_assert (clutter_actor_iter_is_valid (&iter)); + while (clutter_actor_iter_next (&iter, &child)) { g_assert (CLUTTER_IS_ACTOR (child)); @@ -54,6 +56,8 @@ actor_iter_traverse_children (TestConformSimpleFixture *fixture G_GNUC_UNUSED, i = 0; clutter_actor_iter_init (&iter, actor); + g_assert (clutter_actor_iter_is_valid (&iter)); + while (clutter_actor_iter_prev (&iter, &child)) { g_assert (CLUTTER_IS_ACTOR (child)); @@ -105,6 +109,8 @@ actor_iter_traverse_remove (TestConformSimpleFixture *fixture G_GNUC_UNUSED, i = 0; clutter_actor_iter_init (&iter, actor); + g_assert (clutter_actor_iter_is_valid (&iter)); + while (clutter_actor_iter_next (&iter, &child)) { g_assert (CLUTTER_IS_ACTOR (child)); @@ -120,6 +126,7 @@ actor_iter_traverse_remove (TestConformSimpleFixture *fixture G_GNUC_UNUSED, g_assert (child == clutter_actor_get_last_child (actor)); clutter_actor_iter_remove (&iter); + g_assert (clutter_actor_iter_is_valid (&iter)); i += 1; } @@ -163,6 +170,9 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED, iter_b = iter_a; + g_assert (clutter_actor_iter_is_valid (&iter_a)); + g_assert (clutter_actor_iter_is_valid (&iter_b)); + while (clutter_actor_iter_next (&iter_a, &child)) { g_assert (CLUTTER_IS_ACTOR (child)); @@ -182,7 +192,7 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED, g_assert_cmpint (i, ==, n_actors); - i = n_actors; + i = n_actors - 1; while (clutter_actor_iter_prev (&iter_b, &child)) { @@ -191,16 +201,16 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED, if (g_test_verbose ()) g_print ("actor %2d = '%s'\n", i, clutter_actor_get_name (child)); - if (i == n_actors) + if (i == n_actors - 1) g_assert (child == clutter_actor_get_last_child (actor)); - if (i == 1) + if (i == 0) g_assert (child == clutter_actor_get_first_child (actor)); i -= 1; } - g_assert_cmpint (i, ==, 0); + g_assert_cmpint (i, ==, -1); g_object_unref (actor); }