Generic Value Struct management
[Generic Value Storage]
Data Structures | |
struct | _Eina_Value_Struct_Operations |
How to manage struct. More... | |
struct | _Eina_Value_Struct_Member |
Describes a single member of struct. More... | |
struct | _Eina_Value_Struct_Desc |
Describes the struct by listing its size, members and operations. More... | |
struct | _Eina_Value_Struct |
Used to store the memory and its description. More... | |
Defines | |
#define | EINA_VALUE_STRUCT_OPERATIONS_VERSION (1) |
Current API version, used to validate _Eina_Value_Struct_Operations. | |
#define | EINA_VALUE_STRUCT_DESC_VERSION (1) |
Current API version, used to validate _Eina_Value_Struct_Desc. | |
#define | EINA_VALUE_STRUCT_MEMBER(eina_value_type, type, member) {#member, eina_value_type, offsetof(type, member)} |
Helper to define Eina_Value_Struct_Member fields, uses offsetof() with type and member. | |
#define | EINA_VALUE_STRUCT_MEMBER_SENTINEL {NULL, NULL, 0} |
Helper to define Eina_Value_Struct_Member fields for sentinel (last item), useful if you did not define member_count . | |
Typedefs | |
typedef struct _Eina_Value_Struct_Operations | Eina_Value_Struct_Operations |
How to manage struct. | |
typedef struct _Eina_Value_Struct_Member | Eina_Value_Struct_Member |
Describes a single member of struct. | |
typedef struct _Eina_Value_Struct_Desc | Eina_Value_Struct_Desc |
Describes the struct by listing its size, members and operations. | |
typedef struct _Eina_Value_Struct | Eina_Value_Struct |
Value type for EINA_VALUE_TYPE_STRUCT. | |
Functions | |
Eina_Value * | eina_value_struct_new (const Eina_Value_Struct_Desc *desc) |
Create generic value storage of type struct. | |
static Eina_Bool | eina_value_struct_setup (Eina_Value *value, const Eina_Value_Struct_Desc *desc) |
Initialize generic value storage of type struct. | |
static Eina_Bool | eina_value_struct_set (Eina_Value *value, const char *name,...) |
Set the generic value in an struct member. | |
static Eina_Bool | eina_value_struct_get (const Eina_Value *value, const char *name,...) |
Get the generic value from an struct member. | |
static Eina_Bool | eina_value_struct_vset (Eina_Value *value, const char *name, va_list args) |
Set the generic value in an struct member. | |
static Eina_Bool | eina_value_struct_vget (const Eina_Value *value, const char *name, va_list args) |
Get the generic value from an struct member. | |
static Eina_Bool | eina_value_struct_pset (Eina_Value *value, const char *name, const void *ptr) |
Set the generic value in an struct member from pointer. | |
static Eina_Bool | eina_value_struct_pget (const Eina_Value *value, const char *name, void *ptr) |
Get the generic value to pointer from an struct member. | |
static Eina_Bool | eina_value_struct_value_get (const Eina_Value *src, const char *name, Eina_Value *dst) |
Get the member as Eina_Value copy. | |
static Eina_Bool | eina_value_struct_value_set (Eina_Value *dst, const char *name, const Eina_Value *src) |
Set the member from Eina_Value source. | |
static Eina_Bool | eina_value_struct_member_value_get (const Eina_Value *src, const Eina_Value_Struct_Member *member, Eina_Value *dst) |
Get the member as Eina_Value copy given its member description. | |
static Eina_Bool | eina_value_struct_member_value_set (Eina_Value *dst, const Eina_Value_Struct_Member *member, const Eina_Value *src) |
Set the member from Eina_Value source. | |
Variables | |
const Eina_Value_Struct_Operations * | EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH |
Assumes members is sorted by name and applies binary search for names. | |
const Eina_Value_Struct_Operations * | EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE |
Assumes members name are stringshared and can be compared for equality without using its contents (simple pointer comparison). |
Define Documentation
#define EINA_VALUE_STRUCT_MEMBER | ( | eina_value_type, | |||
type, | |||||
member | ) | {#member, eina_value_type, offsetof(type, member)} |
Helper to define Eina_Value_Struct_Member fields, uses offsetof() with type and member.
- Since:
- 1.2
#define EINA_VALUE_STRUCT_MEMBER_SENTINEL {NULL, NULL, 0} |
Helper to define Eina_Value_Struct_Member fields for sentinel (last item), useful if you did not define member_count
.
- Since:
- 1.2
Typedef Documentation
How to manage struct.
Any NULL
callback is ignored.
A structure can specify alternative methods to allocate, free and copy itself. See structure definition for all methods.
- See also:
- _Eina_Value_Struct_Operations explains fields.
- Since:
- 1.2
Describes a single member of struct.
The member holds a name, type and its byte offset within the struct memory. Most Eina_Value_Struct functions takes the member name as parameter, as in eina_value_struct_set().
- See also:
- _Eina_Value_Struct_Member explains fields.
- Since:
- 1.2
Describes the struct by listing its size, members and operations.
- See also:
- _Eina_Value_Struct_Desc explains fields.
- Since:
- 1.2
Function Documentation
Eina_Value* eina_value_struct_new | ( | const Eina_Value_Struct_Desc * | desc | ) |
Create generic value storage of type struct.
- Parameters:
-
desc how to manage this struct members.
- Returns:
- The new value or
NULL
on failure.
On failure, NULL
is returned and EINA_ERROR_OUT_OF_MEMORY or EINA_ERROR_VALUE_FAILED is set.
- Note:
- this creates from mempool and then uses eina_value_struct_setup().
- Since:
- 1.2
References eina_mempool_free(), eina_mempool_malloc(), and eina_value_struct_setup().
static Eina_Bool eina_value_struct_setup | ( | Eina_Value * | value, | |
const Eina_Value_Struct_Desc * | desc | |||
) | [inline, static] |
Initialize generic value storage of type struct.
- Parameters:
-
value value object desc how to manage this struct members.
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
This is the same as calling eina_value_set() with EINA_VALUE_TYPE_STRUCT followed by eina_value_pset() with the Eina_Value_Struct description configured.
- Note:
- Existing contents are ignored! If the value was previously used, then use eina_value_flush() first.
- See also:
- eina_value_flush()
- Since:
- 1.2
Referenced by eina_value_struct_new().
static Eina_Bool eina_value_struct_set | ( | Eina_Value * | value, | |
const char * | name, | |||
... | ||||
) | [inline, static] |
Set the generic value in an struct member.
- Parameters:
-
value source value object name name to find the member
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
- EINA_VALUE_TYPE_UCHAR: unsigned char
- EINA_VALUE_TYPE_USHORT: unsigned short
- EINA_VALUE_TYPE_UINT: unsigned int
- EINA_VALUE_TYPE_ULONG: unsigned long
- EINA_VALUE_TYPE_UINT64: uint64_t
- EINA_VALUE_TYPE_CHAR: char
- EINA_VALUE_TYPE_SHORT: short
- EINA_VALUE_TYPE_INT: int
- EINA_VALUE_TYPE_LONG: long
- EINA_VALUE_TYPE_INT64: int64_t
- EINA_VALUE_TYPE_FLOAT: float
- EINA_VALUE_TYPE_DOUBLE: double
- EINA_VALUE_TYPE_STRINGSHARE: const char *
- EINA_VALUE_TYPE_STRING: const char *
- EINA_VALUE_TYPE_HASH: Eina_Value_Hash
- EINA_VALUE_TYPE_TIMEVAL: struct timeval*
- EINA_VALUE_TYPE_BLOB: Eina_Value_Blob*
- EINA_VALUE_TYPE_STRUCT: Eina_Value_Struct*
struct myst { int i; char c; }; const Eina_Value_Struct_Member myst_members[] = { {"i", EINA_VALUE_TYPE_INT, 0}, {"c", EINA_VALUE_TYPE_CHAR, 4}, {NULL, NULL, 0} }; const Eina_Value_Struct_Desc myst_desc = { EINA_VALUE_STRUCT_DESC_VERSION, NULL, myst_members, 2, sizeof(struct myst) }; Eina_Value *value = eina_value_struct_new(&my_desc); int x; char y; eina_value_struct_set(value, "i", 5678); eina_value_struct_get(value, "i", &x); eina_value_struct_set(value, "c", 0xf); eina_value_struct_get(value, "c", &y); eina_value_free(value);
- Since:
- 1.2
static Eina_Bool eina_value_struct_get | ( | const Eina_Value * | value, | |
const char * | name, | |||
... | ||||
) | [inline, static] |
Get the generic value from an struct member.
- Parameters:
-
value source value object name name to find the member
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
The variable argument is dependent on chosen member type. The list for basic types:
- EINA_VALUE_TYPE_UCHAR: unsigned char*
- EINA_VALUE_TYPE_USHORT: unsigned short*
- EINA_VALUE_TYPE_UINT: unsigned int*
- EINA_VALUE_TYPE_ULONG: unsigned long*
- EINA_VALUE_TYPE_UINT64: uint64_t*
- EINA_VALUE_TYPE_CHAR: char*
- EINA_VALUE_TYPE_SHORT: short*
- EINA_VALUE_TYPE_INT: int*
- EINA_VALUE_TYPE_LONG: long*
- EINA_VALUE_TYPE_INT64: int64_t*
- EINA_VALUE_TYPE_FLOAT: float*
- EINA_VALUE_TYPE_DOUBLE: double*
- EINA_VALUE_TYPE_STRINGSHARE: const char **
- EINA_VALUE_TYPE_STRING: const char **
- EINA_VALUE_TYPE_HASH: Eina_Value_Hash*
- EINA_VALUE_TYPE_TIMEVAL: struct timeval*
- EINA_VALUE_TYPE_BLOB: Eina_Value_Blob*
- EINA_VALUE_TYPE_STRUCT: Eina_Value_Struct*
struct myst { int i; char c; }; const Eina_Value_Struct_Member myst_members[] = { {"i", EINA_VALUE_TYPE_INT, 0}, {"c", EINA_VALUE_TYPE_CHAR, 4}, {NULL, NULL, 0} }; const Eina_Value_Struct_Desc myst_desc = { EINA_VALUE_STRUCT_DESC_VERSION, NULL, myst_members, 2, sizeof(struct myst) }; Eina_Value *value = eina_value_struct_new(&my_desc); int x; char y; eina_value_struct_set(value, "i", 5678); eina_value_struct_get(value, "i", &x); eina_value_struct_set(value, "c", 0xf); eina_value_struct_get(value, "c", &y); eina_value_free(value);
- Since:
- 1.2
static Eina_Bool eina_value_struct_vset | ( | Eina_Value * | value, | |
const char * | name, | |||
va_list | args | |||
) | [inline, static] |
Set the generic value in an struct member.
- Parameters:
-
value source value object name name to find the member args variable argument
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
- Since:
- 1.2
static Eina_Bool eina_value_struct_vget | ( | const Eina_Value * | value, | |
const char * | name, | |||
va_list | args | |||
) | [inline, static] |
Get the generic value from an struct member.
- Parameters:
-
value source value object name name to find the member args variable argument
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
- Since:
- 1.2
static Eina_Bool eina_value_struct_pset | ( | Eina_Value * | value, | |
const char * | name, | |||
const void * | ptr | |||
) | [inline, static] |
Set the generic value in an struct member from pointer.
- Parameters:
-
value source value object name name to find the member ptr pointer to specify the contents.
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
- EINA_VALUE_TYPE_UCHAR: unsigned char*
- EINA_VALUE_TYPE_USHORT: unsigned short*
- EINA_VALUE_TYPE_UINT: unsigned int*
- EINA_VALUE_TYPE_ULONG: unsigned long*
- EINA_VALUE_TYPE_UINT64: uint64_t*
- EINA_VALUE_TYPE_CHAR: char*
- EINA_VALUE_TYPE_SHORT: short*
- EINA_VALUE_TYPE_INT: int*
- EINA_VALUE_TYPE_LONG: long*
- EINA_VALUE_TYPE_INT64: int64_t*
- EINA_VALUE_TYPE_FLOAT: float*
- EINA_VALUE_TYPE_DOUBLE: double*
- EINA_VALUE_TYPE_STRINGSHARE: const char **
- EINA_VALUE_TYPE_STRING: const char **
- EINA_VALUE_TYPE_HASH: Eina_Value_Hash*
- EINA_VALUE_TYPE_TIMEVAL: struct timeval*
- EINA_VALUE_TYPE_BLOB: Eina_Value_Blob*
- EINA_VALUE_TYPE_STRUCT: Eina_Value_Struct*
- Note:
- the pointer contents are written using the size defined by type. It can be larger than void* or uint64_t.
struct myst { int i; char c; }; const Eina_Value_Struct_Member myst_members[] = { {"i", EINA_VALUE_TYPE_INT, 0}, {"c", EINA_VALUE_TYPE_CHAR, 4}, {NULL, NULL, 0} }; const Eina_Value_Struct_Desc myst_desc = { EINA_VALUE_STRUCT_DESC_VERSION, NULL, myst_members, 2, sizeof(struct myst) }; Eina_Value *value = eina_value_struct_new(&my_desc); int x = 5678; char y = 0xf; eina_value_struct_pset(value, "i", &); eina_value_struct_pget(value, "i", &x); eina_value_struct_pset(value, "c", &y); eina_value_struct_pget(value, "c", &y); eina_value_free(value);
- Since:
- 1.2
static Eina_Bool eina_value_struct_pget | ( | const Eina_Value * | value, | |
const char * | name, | |||
void * | ptr | |||
) | [inline, static] |
Get the generic value to pointer from an struct member.
- Parameters:
-
value source value object name name to find the member ptr pointer to receive the contents.
- Returns:
- EINA_TRUE on success, EINA_FALSE otherwise.
The pointer type is dependent on chosen value type. The list for basic types:
- EINA_VALUE_TYPE_UCHAR: unsigned char*
- EINA_VALUE_TYPE_USHORT: unsigned short*
- EINA_VALUE_TYPE_UINT: unsigned int*
- EINA_VALUE_TYPE_ULONG: unsigned long*
- EINA_VALUE_TYPE_UINT64: uint64_t*
- EINA_VALUE_TYPE_CHAR: char*
- EINA_VALUE_TYPE_SHORT: short*
- EINA_VALUE_TYPE_INT: int*
- EINA_VALUE_TYPE_LONG: long*
- EINA_VALUE_TYPE_INT64: int64_t*
- EINA_VALUE_TYPE_FLOAT: float*
- EINA_VALUE_TYPE_DOUBLE: double*
- EINA_VALUE_TYPE_STRINGSHARE: const char **
- EINA_VALUE_TYPE_STRING: const char **
- EINA_VALUE_TYPE_HASH: Eina_Value_Hash*
- EINA_VALUE_TYPE_TIMEVAL: struct timeval*
- EINA_VALUE_TYPE_BLOB: Eina_Value_Blob*
- EINA_VALUE_TYPE_STRUCT: Eina_Value_Struct*
struct myst { int i; char c; }; const Eina_Value_Struct_Member myst_members[] = { {"i", EINA_VALUE_TYPE_INT, 0}, {"c", EINA_VALUE_TYPE_CHAR, 4}, {NULL, NULL, 0} }; const Eina_Value_Struct_Desc myst_desc = { EINA_VALUE_STRUCT_DESC_VERSION, NULL, myst_members, 2, sizeof(struct myst) }; Eina_Value *value = eina_value_struct_new(&my_desc); int x = 5678; char y = 0xf; eina_value_struct_pset(value, "i", &); eina_value_struct_pget(value, "i", &x); eina_value_struct_pset(value, "c", &y); eina_value_struct_pget(value, "c", &y); eina_value_free(value);
- Since:
- 1.2
static Eina_Bool eina_value_struct_value_get | ( | const Eina_Value * | src, | |
const char * | name, | |||
Eina_Value * | dst | |||
) | [inline, static] |
Get the member as Eina_Value copy.
- Parameters:
-
src source value object name name to find the member dst where to return the member value.
- Returns:
- EINA_TRUE on success, EINA_FALSE on failure.
- Since:
- 1.2
static Eina_Bool eina_value_struct_value_set | ( | Eina_Value * | dst, | |
const char * | name, | |||
const Eina_Value * | src | |||
) | [inline, static] |
Set the member from Eina_Value source.
- Parameters:
-
dst destination value object name name to find the member src source value
- Returns:
- EINA_TRUE on success, EINA_FALSE on failure.
- Since:
- 1.2
static Eina_Bool eina_value_struct_member_value_get | ( | const Eina_Value * | src, | |
const Eina_Value_Struct_Member * | member, | |||
Eina_Value * | dst | |||
) | [inline, static] |
Get the member as Eina_Value copy given its member description.
- Parameters:
-
src source value object member the member description to use dst where to return the member value.
- Returns:
- EINA_TRUE on success, EINA_FALSE on failure.
- Since:
- 1.2
static Eina_Bool eina_value_struct_member_value_set | ( | Eina_Value * | dst, | |
const Eina_Value_Struct_Member * | member, | |||
const Eina_Value * | src | |||
) | [inline, static] |
Set the member from Eina_Value source.
- Parameters:
-
dst destination value object member the member description to use src source value
- Returns:
- EINA_TRUE on success, EINA_FALSE on failure.
- Since:
- 1.2
Variable Documentation
Assumes members
is sorted by name and applies binary search for names.
Ideally the member_count
field is set to speed it up.
No other methods are set (alloc, free, copy, compare), then it uses the default operations.
Assumes members
name are stringshared and can be compared for equality without using its contents (simple pointer comparison).
Ideally the search name
will be stringshared as well, but it will do a second loop with a forced stringshare if it did not find the member.
No other methods are set (alloc, free, copy, compare), then it uses the default operations.