eina_value_util: eina_value_X_get() helpers.

These helpers will validate the type prior to get its value, also
enforcing the correct pointer is passed.
This commit is contained in:
Gustavo Sverzut Barbieri 2017-08-23 18:28:06 -03:00
parent f4b02d87d6
commit 103b134916
1 changed files with 306 additions and 0 deletions

View File

@ -671,6 +671,312 @@ eina_value_error_init(Eina_Error err)
return v;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param c Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_uchar_get(const Eina_Value *v, unsigned char *c)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(c, EINA_FALSE);
*c = 0;
if (v && v->type == EINA_VALUE_TYPE_UCHAR)
return eina_value_get(v, c);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param s Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_ushort_get(const Eina_Value *v, unsigned short *s)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
*s = 0;
if (v && v->type == EINA_VALUE_TYPE_USHORT)
return eina_value_get(v, s);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param i Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_uint_get(const Eina_Value *v, unsigned int *i)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
*i = 0;
if (v && v->type == EINA_VALUE_TYPE_UINT)
return eina_value_get(v, i);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param l Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_ulong_get(const Eina_Value *v, unsigned long *l)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(l, EINA_FALSE);
*l = 0;
if (v && v->type == EINA_VALUE_TYPE_ULONG)
return eina_value_get(v, l);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param i Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_uint64_get(const Eina_Value *v, uint64_t *i)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
*i = 0;
if (v && v->type == EINA_VALUE_TYPE_UINT64)
return eina_value_get(v, i);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param c Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_char_get(const Eina_Value *v, char *c)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(c, EINA_FALSE);
*c = 0;
if (v && v->type == EINA_VALUE_TYPE_CHAR)
return eina_value_get(v, c);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param s Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_short_get(const Eina_Value *v, short *s)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
*s = 0;
if (v && v->type == EINA_VALUE_TYPE_SHORT)
return eina_value_get(v, s);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param i Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_int_get(const Eina_Value *v, int *i)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
*i = 0;
if (v && v->type == EINA_VALUE_TYPE_INT)
return eina_value_get(v, i);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param l Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_long_get(const Eina_Value *v, long *l)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(l, EINA_FALSE);
*l = 0;
if (v && v->type == EINA_VALUE_TYPE_LONG)
return eina_value_get(v, l);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param i Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_int64_get(const Eina_Value *v, int64_t *i)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
*i = 0;
if (v && v->type == EINA_VALUE_TYPE_INT64)
return eina_value_get(v, i);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param f Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_float_get(const Eina_Value *v, float *f)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(f, EINA_FALSE);
*f = 0.0f;
if (v && v->type == EINA_VALUE_TYPE_FLOAT)
return eina_value_get(v, f);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param d Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_double_get(const Eina_Value *v, double *d)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(d, EINA_FALSE);
*d = 0.0;
if (v && v->type == EINA_VALUE_TYPE_DOUBLE)
return eina_value_get(v, d);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param b Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_bool_get(const Eina_Value *v, Eina_Bool *b)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(b, EINA_FALSE);
*b = EINA_FALSE;
if (v && v->type == EINA_VALUE_TYPE_UCHAR)
return eina_value_get(v, b);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param str Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_string_get(const Eina_Value *v, const char **str)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
*str = NULL;
if (v && v->type == EINA_VALUE_TYPE_STRING)
return eina_value_get(v, str);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param str Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_stringshare_get(const Eina_Value *v, const char **str)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
*str = NULL;
if (v && v->type == EINA_VALUE_TYPE_STRINGSHARE)
return eina_value_get(v, str);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param t Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_time_get(const Eina_Value *v, time_t *t)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(t, EINA_FALSE);
*t = 0;
if (v && v->type == EINA_VALUE_TYPE_TIMESTAMP)
return eina_value_get(v, t);
return EINA_FALSE;
}
/**
* @brief Check value type and get contents.
* @param v The value to check type and get contents.
* @param err Where to store the value contents.
* @return #EINA_TRUE if type matches and fetched contents,
* #EINA_FALSE on different type or failures.
* @since 1.21
*/
static inline Eina_Bool
eina_value_error_get(const Eina_Value *v, Eina_Error *err)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(err, EINA_FALSE);
*err = 0;
if (v && v->type == EINA_VALUE_TYPE_ERROR)
return eina_value_get(v, err);
return EINA_FALSE;
}
/**
* @brief Create a new #Eina_Value containing the passed parameter
* @param val The value to use