eina: add an helper to setup Eina_Value structure description.

This is particularly useful on system like Windows who doesn't allow
setting pointer at compile time in static const structure.
This commit is contained in:
Cedric BAIL 2017-09-27 16:30:31 -07:00
parent d23aca3c8e
commit 3a3ae49afd
1 changed files with 22 additions and 0 deletions

View File

@ -3066,6 +3066,28 @@ struct _Eina_Value_Struct
void *memory; /**< The managed structure memory */
};
#define EINA_VALUE_STRUCT_DESC_DEFINE(Name, Ops, Size, ...) \
static Eina_Value_Struct_Desc * \
Name(void) \
{ \
Eina_Value_Struct_Member tmp[] = { __VA_ARGS__ }; \
static Eina_Value_Struct_Member members[EINA_C_ARRAY_LENGTH(tmp) + 1] = { { "", NULL, 0 } }; \
static Eina_Value_Struct_Desc r = { \
EINA_VALUE_STRUCT_DESC_VERSION, \
NULL, \
members, \
EINA_C_ARRAY_LENGTH(tmp), \
Size \
}; \
\
if (members[0].name) \
{ \
r.ops = Ops; \
memcpy(members, tmp, sizeof(tmp)); \
} \
return &r; \
}
/**
* @brief Creates generic value storage of type struct.
* @param desc How to manage this struct members.