Eina_Value_Struct *st;
void *mem;
- EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(value, 0);
+ EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(value, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ptr, EINA_FALSE);
st = (Eina_Value_Struct *)eina_value_memory_get(value);
if (!st)
return EINA_FALSE;
const void *mem;
Eina_Bool ret;
- EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(value, 0);
+ EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(value, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ptr, EINA_FALSE);
st = (const Eina_Value_Struct *)eina_value_memory_get(value);
if (!st)
return EINA_FALSE;
ret = eina_value_type_pget(member->type, mem, ptr);
return ret;
}
+
+static inline Eina_Bool
+eina_value_struct_value_get(const Eina_Value *src, const char *name, Eina_Value *dst)
+{
+ const Eina_Value_Struct_Member *member;
+ const Eina_Value_Struct *st;
+ const void *mem;
+
+ EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(src, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(dst, EINA_FALSE);
+ st = (const Eina_Value_Struct *)eina_value_memory_get(src);
+ if (!st)
+ return EINA_FALSE;
+ member = eina_value_struct_member_find(st, name);
+ if (!member)
+ return EINA_FALSE;
+ mem = eina_value_struct_member_memory_get(st, member);
+ if (!mem)
+ return EINA_FALSE;
+ if (!eina_value_setup(dst, member->type))
+ return EINA_FALSE;
+ if (!eina_value_pset(dst, mem))
+ {
+ eina_value_flush(dst);
+ return EINA_FALSE;
+ }
+ return EINA_TRUE;
+}
+
+static inline Eina_Bool
+eina_value_struct_value_set(Eina_Value *dst, const char *name, const Eina_Value *src)
+{
+ const Eina_Value_Struct_Member *member;
+ Eina_Value_Struct *st;
+ void *mem;
+ const void *ptr;
+
+ EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(dst, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(src, EINA_FALSE);
+
+ st = (Eina_Value_Struct *)eina_value_memory_get(dst);
+ if (!st)
+ return EINA_FALSE;
+ member = eina_value_struct_member_find(st, name);
+ if (!member)
+ return EINA_FALSE;
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(src->type == member->type, EINA_FALSE);
+
+ mem = eina_value_struct_member_memory_get(st, member);
+ if (!mem)
+ return EINA_FALSE;
+
+ ptr = eina_value_memory_get(src);
+ if (!ptr)
+ return EINA_FALSE;
+
+ eina_value_type_flush(member->type, mem);
+ if (!eina_value_type_setup(member->type, mem)) goto error_setup;
+ if (!eina_value_type_pset(member->type, mem, ptr)) goto error_set;
+ return EINA_TRUE;
+
+ error_set:
+ eina_value_type_flush(member->type, mem);
+ error_setup:
+ return EINA_FALSE;
+}
+
#undef EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL
* @param copy destination value object
* @return #EINA_TRUE on success, #EINA_FALSE otherwise.
*
- * The @a copy object is considered internalized and its existing
+ * The @a copy object is considered uninitialized and its existing
* contents are overwritten (just as if eina_value_flush() was called on
* it).
*
*/
static inline Eina_Bool eina_value_struct_set(Eina_Value *value,
const char *name,
- ...) EINA_ARG_NONNULL(1);
+ ...) EINA_ARG_NONNULL(1, 2);
/**
* @brief Get the generic value from an struct member.
*/
static inline Eina_Bool eina_value_struct_get(const Eina_Value *value,
const char *name,
- ...) EINA_ARG_NONNULL(1);
+ ...) EINA_ARG_NONNULL(1, 2);
/**
* @brief Set the generic value in an struct member.
*/
static inline Eina_Bool eina_value_struct_vset(Eina_Value *value,
const char *name,
- va_list args) EINA_ARG_NONNULL(1);
+ va_list args) EINA_ARG_NONNULL(1, 2);
/**
* @brief Get the generic value from an struct member.
*/
static inline Eina_Bool eina_value_struct_vget(const Eina_Value *value,
const char *name,
- va_list args) EINA_ARG_NONNULL(1);
+ va_list args) EINA_ARG_NONNULL(1, 2);
/**
* @brief Set the generic value in an struct member from pointer.
*/
static inline Eina_Bool eina_value_struct_pset(Eina_Value *value,
const char *name,
- const void *ptr) EINA_ARG_NONNULL(1, 3);
+ const void *ptr) EINA_ARG_NONNULL(1, 2, 3);
/**
* @brief Get the generic value to pointer from an struct member.
*/
static inline Eina_Bool eina_value_struct_pget(const Eina_Value *value,
const char *name,
- void *ptr) EINA_ARG_NONNULL(1, 3);
+ void *ptr) EINA_ARG_NONNULL(1, 2, 3);
+
+/**
+ * @brief Get the member as Eina_Value copy
+ * @param src source value object
+ * @param name name to find the member
+ * @param dst where to return the member value.
+ *
+ * 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_struct_value_get(const Eina_Value *src,
+ const char *name,
+ Eina_Value *dst) EINA_ARG_NONNULL(1, 2, 3);
+
+/**
+ * @brief Set the member from Eina_Value source
+ * @param dst destination value object
+ * @param name name to find the member
+ * @param src source value
+ *
+ * @since 1.2
+ */
+static inline Eina_Bool eina_value_struct_value_set(Eina_Value *dst,
+ const char *name,
+ const Eina_Value *src) EINA_ARG_NONNULL(1, 2, 3);
/**
* @}
static Eina_Bool
_eina_model_interface_properties_struct_get(const Eina_Model *model, const char *name, Eina_Value *val)
{
- EINA_MODEL_INTERFACE_PROPERTIES_STRUCT_GET(model);
- const Eina_Value_Struct_Member *m;
- const void *p;
-
- /* highly optimized, but duplicates code from eina_inline_value.x */
-
- m = eina_value_struct_member_find(priv, name);
- EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
-
- p = eina_value_struct_member_memory_get(priv, m);
- EINA_SAFETY_ON_NULL_RETURN_VAL(p, EINA_FALSE);
- EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_setup(val, m->type), EINA_FALSE);
- EINA_SAFETY_ON_FALSE_GOTO(eina_value_pset(val, p), error);
- return EINA_TRUE;
-
- error:
- eina_value_flush(val);
- return EINA_FALSE;
+ const Eina_Value *v = eina_model_interface_private_data_get
+ (model, EINA_MODEL_INTERFACE_PROPERTIES_STRUCT);
+ return eina_value_struct_value_get(v, name, val);
}
static Eina_Bool
_eina_model_interface_properties_struct_set(Eina_Model *model, const char *name, const Eina_Value *val)
{
- EINA_MODEL_INTERFACE_PROPERTIES_STRUCT_GET(model);
- const Eina_Value_Struct_Member *m;
- const void *src;
- void *dst;
-
- /* highly optimized, but duplicates code from eina_inline_value.x */
-
- m = eina_value_struct_member_find(priv, name);
- EINA_SAFETY_ON_NULL_RETURN_VAL(m, EINA_FALSE);
- EINA_SAFETY_ON_FALSE_RETURN_VAL(val->type == m->type, EINA_FALSE);
-
- dst = eina_value_struct_member_memory_get(priv, m);
- EINA_SAFETY_ON_NULL_RETURN_VAL(dst, EINA_FALSE);
- src = eina_value_memory_get(val);
- EINA_SAFETY_ON_NULL_RETURN_VAL(src, EINA_FALSE);
-
- eina_value_type_flush(m->type, dst);
- if (!eina_value_type_setup(m->type, dst)) goto error_setup;
- if (!eina_value_type_pset(m->type, dst, src)) goto error_set;
- return EINA_TRUE;
-
- error_set:
- eina_value_type_flush(m->type, dst);
- error_setup:
- return EINA_FALSE;
+ Eina_Value *v = eina_model_interface_private_data_get
+ (model, EINA_MODEL_INTERFACE_PROPERTIES_STRUCT);
+ return eina_value_struct_value_set(v, name, val);
}
static Eina_Bool
};
Eina_Value inv, outv;
int i;
- char c;
+ char c, *s;
Eina_List *lst;
Eina_Bool ck;
/* negative test (check safety was displayed by using print_cb) */
eina_log_print_cb_set(_eina_test_model_check_safety_null, &ck);
- ck = EINA_FALSE;
fail_if(eina_model_property_get(m, "non-existent", &outv));
- fail_unless(ck == EINA_TRUE);
ck = EINA_FALSE;
fail_if(eina_model_property_get(m, NULL, &outv));
eina_value_flush(&inv);
+ s = eina_model_to_string(m);
+ fail_unless(s != NULL);
+ ck_assert_str_eq(s, "Eina_Model_Type_Struct({c: 33, i: 1234}, [])");
+ free(s);
+
ck_assert_int_eq(eina_model_refcount(m), 1);
eina_model_unref(m);