Since k-s is on the road this days, we'd better write some code ourselves.
This is array counterpart of eina_value_struct_value_get(), and retrieves
an item from an Eina_Value_Array as an Eina_Value.
Code writing the setter is welcome.
Patch by: "Raphael Kubo da Costa" <kubo@profusion.mobi>
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@68581
7cbeb6ba-43b4-40fd-8cce-
4c39aea84d33
return EINA_FALSE;
}
+static inline Eina_Bool
+eina_value_array_value_get(const Eina_Value *src, unsigned int position, Eina_Value *dst)
+{
+ Eina_Value_Array desc;
+
+ EINA_VALUE_TYPE_ARRAY_CHECK_RETURN_VAL(src, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(dst, EINA_FALSE);
+
+ if (!eina_value_pget(src, &desc))
+ return EINA_FALSE;
+ if (position >= eina_inarray_count(desc.array))
+ return EINA_FALSE;
+ if (!eina_value_setup(dst, desc.subtype))
+ return EINA_FALSE;
+ if (!eina_value_pset(dst, eina_inarray_nth(desc.array, position)))
+ {
+ eina_value_flush(dst);
+ return EINA_FALSE;
+ }
+
+ return EINA_TRUE;
+}
+
#undef EINA_VALUE_TYPE_ARRAY_CHECK_RETURN_VAL
#define EINA_VALUE_TYPE_LIST_CHECK_RETURN_VAL(value, retval) \
const void *ptr) EINA_ARG_NONNULL(1);
/**
+ * @brief Retrieves a value from the array as an Eina_Value copy.
+ * @param value source value object
+ * @param position index of the member
+ * @param dst where to return the array member
+ * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
+ *
+ * The argument @a dst is considered uninitialized and it's setup to
+ * the type of the member.
+ *
+ * @since 1.2
+ */
+static inline Eina_Bool eina_value_array_value_get(const Eina_Value *src,
+ unsigned int position,
+ Eina_Value *dst) EINA_ARG_NONNULL(1, 3);
+
+/**
* @}
*/
EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH,
myst_members, 4, sizeof(struct myst)
};
- Eina_Value *value;
+ Eina_Value *value, array_item;
char *str;
int i;
"]") == 0);
free(str);
+ eina_value_array_value_get(value, 2, &array_item);
+ eina_value_struct_get(&array_item, "a", &i);
+ ck_assert_int_eq(i, 2);
+ eina_value_struct_get(&array_item, "b", &i);
+ ck_assert_int_eq(i, 20);
+ eina_value_struct_get(&array_item, "c", &i);
+ ck_assert_int_eq(i, 200);
+ eina_value_struct_get(&array_item, "s", &str);
+ ck_assert_str_eq(str, "item02");
+ eina_value_flush(&array_item);
+
eina_value_free(value);
eina_shutdown();
}