From f032ac00cf3ebb8d39d6f89debba18f1577f2b71 Mon Sep 17 00:00:00 2001 From: Ashok Sidipotu Date: Wed, 23 Mar 2022 10:02:48 +0530 Subject: [PATCH] properties: Add get count API This API returns the count of the number of properties or items. --- lib/wp/properties.c | 15 +++++++++++++++ lib/wp/properties.h | 6 ++++++ tests/wp/properties.c | 2 ++ 3 files changed, 23 insertions(+) diff --git a/lib/wp/properties.c b/lib/wp/properties.c index 67044f50..9d8de968 100644 --- a/lib/wp/properties.c +++ b/lib/wp/properties.c @@ -928,6 +928,21 @@ wp_properties_iterator_item_get_value (const GValue * item) return wp_properties_item_get_value (pi); } +/*! + * \brief gets the number of items + * \ingroup wpproperties + * \param self a properties object + */ +guint +wp_properties_get_count (WpProperties * self) +{ + const struct spa_dict *dict = wp_properties_peek_dict(self); + g_return_val_if_fail (dict != NULL, 0); + + return dict->n_items; +} + + /*! * \brief Sorts the keys in alphabetical order * \ingroup wpproperties diff --git a/lib/wp/properties.h b/lib/wp/properties.h index 124a62af..00157020 100644 --- a/lib/wp/properties.h +++ b/lib/wp/properties.h @@ -165,6 +165,12 @@ WP_API G_DEPRECATED_FOR(wp_properties_item_get_value) const gchar * wp_properties_iterator_item_get_value (const GValue * item); +/* count */ + +WP_API +guint wp_properties_get_count (WpProperties * self); + + /* sort */ WP_API diff --git a/tests/wp/properties.c b/tests/wp/properties.c index 3603c21a..e4b820c8 100644 --- a/tests/wp/properties.c +++ b/tests/wp/properties.c @@ -44,6 +44,8 @@ test_properties_wrap_dict (void) p = wp_properties_new_wrap_dict (&dict); g_assert_nonnull (p); + g_assert_cmpint (wp_properties_get_count (p), ==, + SPA_N_ELEMENTS (dict_items)); g_assert_cmpstr (wp_properties_get (p, "key1"), ==, "value1"); g_assert_cmpstr (wp_properties_get (p, "key2"), ==, "value2"); g_assert_cmpstr (wp_properties_get (p, "key3"), ==, NULL);