forked from enlightenment/efl
Eina: Add eina_value_array_value_get().
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> SVN revision: 68581
This commit is contained in:
parent
5cfb0b0c34
commit
37efb6c4db
|
@ -823,6 +823,29 @@ eina_value_array_pappend(Eina_Value *value, const void *ptr)
|
|||
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) \
|
||||
|
|
|
@ -1719,6 +1719,22 @@ static inline Eina_Bool eina_value_array_pinsert(Eina_Value *value,
|
|||
static inline Eina_Bool eina_value_array_pappend(Eina_Value *value,
|
||||
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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -1750,7 +1750,7 @@ START_TEST(eina_value_test_array_of_struct)
|
|||
EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH,
|
||||
myst_members, 4, sizeof(struct myst)
|
||||
};
|
||||
Eina_Value *value;
|
||||
Eina_Value *value, array_item;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
|
@ -1792,6 +1792,17 @@ START_TEST(eina_value_test_array_of_struct)
|
|||
"]") == 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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue