The Eina_Value
object provides generic data storage and access, allowing
you to store what you want in one single type of Eina_Value
. It is meant
for simple data types, providing uniform access and release functions, useful
to exchange data preserving their types. The Eina_Value
comes with
predefined types for numbers, array, list, hash, blob, and structs, and it can
convert between data types, including string.
The Eina_Value
can handle the following types:
EINA_VALUE_TYPE_UCHAR
: unsigned charEINA_VALUE_TYPE_USHORT
: unsigned shortEINA_VALUE_TYPE_UINT
: unsigned intEINA_VALUE_TYPE_ULONG
: unsigned longEINA_VALUE_TYPE_TIMESTAMP
: unsigned long used for timestampsEINA_VALUE_TYPE_UINT64
: unsigned integer of 64 bitsEINA_VALUE_TYPE_CHAR
: charEINA_VALUE_TYPE_SHORT
: shortEINA_VALUE_TYPE_INT
: intEINA_VALUE_TYPE_LONG
: longEINA_VALUE_TYPE_INT64
: integer of 64 bitsEINA_VALUE_TYPE_FLOAT
: floatEINA_VALUE_TYPE_DOUBLE
: doubleEINA_VALUE_TYPE_STRINGSHARE
: stringshared stringEINA_VALUE_TYPE_STRING
: stringEINA_VALUE_TYPE_ARRAY
: arrayEINA_VALUE_TYPE_LIST
: listEINA_VALUE_TYPE_HASH
: hashEINA_VALUE_TYPE_TIMEVAL
: 'struct timeval'EINA_VALUE_TYPE_BLOB
: blob of bytesEINA_VALUE_TYPE_STRUCT
: structTo set up a generic value:
1. Declare the necessary variables:
// The Eina_Value itself Eina_Value v; // An integer int i; // And a char * char *newstr;
2. To set up an Eina_Value for an integer, use the
eina_value_setup()
function. The first argument is the Eina_Value
and
the second is the type.
eina_value_setup(&v, EINA_VALUE_TYPE_INT);
To manage the generic value:
eina_value_set()
function:eina_value_set(&v, 123);
eina_value_get()
function. Pass the Eina_Value
as the first argument, and a pointer to a variable to store the value (the target variable must have the same type as the Eina_Value
).eina_value_get(&v, &i); printf("v=%d\n", i);
The above example prints “v=123”.
const char *s; eina_value_setup(&v, EINA_VALUE_TYPE_STRING); eina_value_set(&v, "My string"); eina_value_get(&v, &s); printf("v=%s (pointer: %p)\n", s, s);
Eina_List
, use the Eina_Value
that corresponds to the EINA_VALUE_TYPE_LIST
type.Eina_Value_List
, use the eina_value_list_setup()
function. The function initializes a generic value storage of the list type. The first parameter is the “object” value, and the second one is the type (how to manage the stored list members).