www-content/pages/program_guide/eina/generic_value.txt

97 lines
3.5 KiB
Plaintext

{{page>index}}
-------
===== Generic Value =====
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.
=== Related Info ===
* [[https://build.enlightenment.org/job/nightly_efl_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/group__Eina__Value__Group.html|Generic Value API]]
|[[https://build.enlightenment.org/job/nightly_efl_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/eina_value_01_8c-example.html|Generic Value Example 1]]|[[https://build.enlightenment.org/job/nightly_efl_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/eina_value_02_8c-example.html|Generic Value Example 2]]|[[https://build.enlightenment.org/job/nightly_efl_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/eina_value_03_8c-example.html|Generic Value Example 3]]|
The ''Eina_Value'' can handle the following 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_TIMESTAMP'': unsigned long used for timestamps
* ''EINA_VALUE_TYPE_UINT64'': unsigned integer of 64 bits
* ''EINA_VALUE_TYPE_CHAR'': char
* ''EINA_VALUE_TYPE_SHORT'': short
* ''EINA_VALUE_TYPE_INT'': int
* ''EINA_VALUE_TYPE_LONG'': long
* ''EINA_VALUE_TYPE_INT64'': integer of 64 bits
* ''EINA_VALUE_TYPE_FLOAT'': float
* ''EINA_VALUE_TYPE_DOUBLE'': double
* ''EINA_VALUE_TYPE_STRINGSHARE'': stringshared string
* ''EINA_VALUE_TYPE_STRING'': string
* ''EINA_VALUE_TYPE_ARRAY'': array
* ''EINA_VALUE_TYPE_LIST'': list
* ''EINA_VALUE_TYPE_HASH'': hash
* ''EINA_VALUE_TYPE_TIMEVAL'': 'struct timeval'
* ''EINA_VALUE_TYPE_BLOB'': blob of bytes
* ''EINA_VALUE_TYPE_STRUCT'': struct
To set up a generic value:
__**1**__. Declare the necessary variables:
<code c>
// The Eina_Value itself
Eina_Value v;
// An integer
int i;
// And a char *
char *newstr;
</code>
__**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.
<code c>
eina_value_setup(&v, EINA_VALUE_TYPE_INT);
</code>
To manage the generic value:
* To set an integer, use the ''eina_value_set()'' function:
<code c>
eina_value_set(&v, 123);
</code>
* To get the value, use the ''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'').
<code c>
eina_value_get(&v, &i);
printf("v=%d\n", i);
</code>
The above example prints "v=123".
* To store a string, get its value, and print it:
<code c>
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);
</code>
* To store an ''Eina_List'', use the ''Eina_Value'' that corresponds to the ''EINA_VALUE_TYPE_LIST'' type.
* To create an ''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).
-------
{{page>index}}