eina_value: add helper: eina_value_struct_desc_get().
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Thu, 24 Aug 2017 14:13:56 +0000 (11:13 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Thu, 24 Aug 2017 14:13:56 +0000 (11:13 -0300)
this helper will validate a struct and fetch its description, also
checking if the user version matches.

src/lib/eina/eina_inline_value.x
src/lib/eina/eina_value.h

index b8614c7..17f9cc4 100644 (file)
@@ -1413,6 +1413,19 @@ eina_value_struct_setup(Eina_Value *value, const Eina_Value_Struct_Desc *sdesc)
    return EINA_TRUE;
 }
 
+static inline const Eina_Value_Struct_Desc *
+eina_value_struct_desc_get(const Eina_Value *value)
+{
+   const Eina_Value_Struct *st;
+
+   EINA_VALUE_TYPE_STRUCT_CHECK_RETURN_VAL(value, NULL);
+   st = (const Eina_Value_Struct *)eina_value_memory_get(value);
+   if ((!st) || (!st->desc))
+     return NULL;
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(st->desc->version == EINA_VALUE_STRUCT_DESC_VERSION, NULL);
+   return st->desc;
+}
+
 static inline void *
 eina_value_struct_member_memory_get(const Eina_Value_Struct *st, const Eina_Value_Struct_Member *member)
 {
index a1ed51d..3617bfb 100644 (file)
@@ -3047,6 +3047,16 @@ static inline Eina_Bool eina_value_struct_setup(Eina_Value *value,
                                                 const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1, 2);
 
 /**
+ * @brief Checks for a struct and get its description.
+ * @param value Value object
+ * @return structure description, with all members and size.
+ * on failure, #NULL is returned.
+ *
+ * @since 1.21
+ */
+static inline const Eina_Value_Struct_Desc *eina_value_struct_desc_get(const Eina_Value *value) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
+
+/**
  * @brief Sets the generic value in an struct member.
  * @param value Source value object
  * @param name Name to find the member