aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_value.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/eina/src/include/eina_value.h511
1 files changed, 465 insertions, 46 deletions
diff --git a/libraries/eina/src/include/eina_value.h b/libraries/eina/src/include/eina_value.h
index 846c4ef..341781f 100644
--- a/libraries/eina/src/include/eina_value.h
+++ b/libraries/eina/src/include/eina_value.h
@@ -19,12 +19,244 @@
19#ifndef EINA_VALUE_H_ 19#ifndef EINA_VALUE_H_
20#define EINA_VALUE_H_ 20#define EINA_VALUE_H_
21 21
22#include <stdarg.h>
23
22#include "eina_types.h" 24#include "eina_types.h"
23#include "eina_fp.h" /* defines int64_t and uint64_t */ 25#include "eina_fp.h" /* defines int64_t and uint64_t */
24#include "eina_inarray.h" 26#include "eina_inarray.h"
25#include "eina_list.h" 27#include "eina_list.h"
26#include "eina_hash.h" 28#include "eina_hash.h"
27#include <stdarg.h> 29
30/**
31 * @page eina_value_example_01_page Eina_Value usage
32 * @dontinclude eina_value_01.c
33 *
34 * This very simple example shows how to use some of the basic features of eina
35 * value: setting and getting values, converting between types and printing a
36 * value as a string.
37 *
38 * Our main function starts out with the basic, declaring some variables and
39 * initializing eina:
40 * @until eina_init
41 *
42 * Now we can jump into using eina value. We set a value, get this value and
43 * then print it:
44 * @until printf
45 *
46 * In the above snippet of code we printed an @c int value, we can however print
47 * the value as a string:
48 * @until free
49 *
50 * And once done with a value it's good practice to destroy it:
51 * @until eina_value_flush
52 *
53 * We now reuse @c v to store a string, get its value and print it:
54 * @until printf
55 * @note Since @c s is the value and not returned by @c eina_value_to_string()
56 * we don't need to free it.
57 *
58 * Just because we stored a string doesn't mean we can't use the @c
59 * eina_value_to_string() function, we can and it's important to note that it
60 * will return not the stored string but rather a copy of it(one we have to
61 * free):
62 * @until eina_value_flush
63 *
64 * And now to explore conversions between two type we'll create another value:
65 * @until eina_value_setup
66 *
67 * And make sure @c v and @c otherv have different types:
68 * @until eina_value_setup
69 *
70 * We then set a value to @c v and have it converted, to do this we don't need
71 * to tell to which type we want to convert, we just say were we want to store
72 * the converted value and eina value will figure out what to convert to, and
73 * how:
74 * @until eina_value_convert
75 *
76 * And now let's check the conversion worked:
77 * @until printf
78 *
79 * But converting to strings is not particularly exciting, @c
80 * eina_value_to_string() already did that, so now let's make the conversion the
81 * other way around, from string to @c int:
82 * @until printf
83 *
84 * And once done, destroy the values:
85 * @until }
86 *
87 * Full source code: @ref eina_value_01_c
88 */
89
90/**
91 * @page eina_value_01_c eina_value_01.c
92 * @include eina_value_01.c
93 * @example eina_value_01.c
94 */
95
96/**
97 * @page eina_value_example_02_page Eina_Value struct usage
98 * @dontinclude eina_value_02.c
99 *
100 * This example will examine a hypothetical situation in which we had a
101 * structure(which represented parameters) with two fields, and then need to add
102 * a third field to our structure. If using structs directly we'd need to
103 * rewrite every piece of code that touches the struct, by using eina value, and
104 * thus having the compiler not even know the struct, we can reduce the amount
105 * of changes needed and retain interoperability between the old and new format.
106 *
107 * Our example will start with a function that creates descriptions of both of
108 * our structs for eina value usage. The first step is to create a struct and
109 * describe its members:
110 * @until v1_members[1]
111 * @note We can't pass the types of the members to EINA_VALUE_STRUCT_MEMBER
112 * macro because they are not constant initializers.
113 *
114 * So far it should be pretty easy to understand, we said @c My_Struct_V1 has
115 * two members, one of type @c int and another of type @c char. We now create
116 * the description of the actual struct, again nothing overly complex, we signal
117 * which version of EINA_VALUE_STRUCT we're using, we declare no special
118 * operations, our members and our size:
119 * @until V1_DESC
120 *
121 * We now repeat the process for the second version of our struct, the only
122 * difference is the addition of a third parameter of type @c int :
123 * @until V2_DESC
124 * @until }
125 *
126 * We'll now look at a function that sets the values of our structs. For
127 * simplicity's sake we initialize it we random values, a real world case would
128 * read these values from a file, a database or even from the network. The
129 * fundamental detail here is that this function works for both V1 and V2
130 * structs, this is because setting a parameter that a struct that doesn't have
131 * does nothing without throwing any errors:
132 * @until }
133 * @note While using eina_value_struct_set() with an in-existing parameter
134 * causes no error, it does return #EINA_FALSE, to notify it was not possible
135 * to set the value. This could be used to determine that we're handling a V1
136 * struct and take some action based on that.
137 *
138 * The next thing is to do is see what a function that uses the values of the
139 * struct looks like. We'll again be very simplistic in our usage, we'll just
140 * print the values, but a real world case, might send these values to another
141 * process use them to open a network/database connection or anything else.
142 * Since all versions of the struct have @c param1 and @c param2 we'll
143 * unconditionally use them:
144 * @until printf
145 *
146 * The next step is to conditionally use @c param3, which can fortunately be
147 * done in the same step in which we get it's value:
148 * @until }
149 *
150 * There we've now got functions that can both populate and use values from both
151 * our structs, so now let's actually use them in our main function by creating
152 * a struct of each type, initializing them and them using them:
153 * @until }
154 *
155 * This concludes our example. For the full source code see @ref
156 * eina_value_02_c.
157 */
158
159/**
160 * @page eina_value_02_c eina_value_02.c
161 * @include eina_value_02.c
162 * @example eina_value_02.c
163 */
164
165/**
166 * @page eina_value_example_03_page Eina value custom type example
167 * @dontinclude eina_value_03.c
168 *
169 * For this example we'll be creating our own custom type of eina value. Eina
170 * value can already store struct timeval(man gettimeofday for more information)
171 * but it has no type to store struct timezone, so that's what this example will
172 * do.
173 * @note struct timezone is actually obsolete, so using it in real world
174 * programs is probably not a good idea, but this is an example so, bear with
175 * us.
176 *
177 * To create our own custom eina value type we need to define functions to
178 * do the following operations on it:
179 * @li Setup
180 * @li Flush
181 * @li Copy
182 * @li Compare
183 * @li Set
184 * @li Get
185 * @li Conversion
186 *
187 * Most of this functions are very simple, so let's look at them, starting with
188 * setup which only clear the memory so that we can be certain we won't be using
189 * stale data:
190 * @until }
191 *
192 * Now the flush function, which is even simpler, it does nothing, that's
193 * because there is nothing we need to do, all the necessary steps are taken by
194 * eina value itself:
195 * @until }
196 *
197 * Our next function, copy, is a bit more interesting, but not much, it just
198 * casts our void pointers to struct timezone pointers and does the copy:
199 * @until }
200 * @note By now you might be wondering why our functions receive void pointers
201 * instead of pointers to struct timezone, and this is a good point. The reason
202 * for this is that eina value doesn't know anything about our type so it must
203 * use a generic void pointer, casting that pointer into a proper value is the
204 * job of the implementor of the new type.
205 *
206 * Next we have the comparison function, which compares the @c tz_minuteswest
207 * field of struct timezone, we don't compare @c tz_dsttime because that field
208 * is not used in linux:
209 * @until }
210 *
211 * Next we have setting, this however requires not one but rather two functions,
212 * the reason for this is because to be able to receive arguments of any type
213 * eina value uses @ref https://wikipedia.org/wiki/Variadic_functions "variadic
214 * functions", so we need a function to get the argument from a va_list and
215 * another to actually to the setting.
216 *
217 * Lets first look at the pset function which sets the received value to a
218 * pointer:
219 * @until }
220 *
221 * Next we have the vset function which get the argument from the va_list and
222 * passes it to the pset function:
223 * @until }
224 *
225 * And now the function to get the value, a very simple copying of the value to
226 * the given pointer:
227 * @until }
228 *
229 * And finally our conversion function, this is our longest and most interesting
230 * one. For numeric type we simply assign the value of @c tz_minuteswest to the
231 * new type and call a set function using it:
232 * @until EINA_VALUE_TYPE_DOUBLE
233 * @until return
234 * @note It would be a good idea to add checks for over and underflow for these
235 * types and return #EINA_FALSE in thoses cases, we omit this here for brevity.
236 *
237 * For string types we use @c snprintf() to format our @c tz_minuteswest field
238 * and put it in a string(again @c tz_dsttime is ignored because it's not used):
239 * @until }
240 *
241 * Finally we handle any other types by returning an error in that case:
242 * @until }
243 *
244 * Now that we have all the functions, we can populate an @c Eina_Value_Type to
245 * later use it with @c eina_value_setup():
246 * @until }
247 *
248 * We can now finally use our new TZ_TYPE with eina value, so lets conclude our
249 * example by practicing that by setting its value and printing it:
250 * @until }
251 *
252 * For the full source code see @ref eina_value_03_c.
253 */
254
255/**
256 * @page eina_value_03_c eina_value_03.c
257 * @include eina_value_03.c
258 * @example eina_value_03.c
259 */
28 260
29/** 261/**
30 * @addtogroup Eina_Data_Types_Group Data Types 262 * @addtogroup Eina_Data_Types_Group Data Types
@@ -43,6 +275,24 @@
43/** 275/**
44 * @defgroup Eina_Value_Group Generic Value Storage 276 * @defgroup Eina_Value_Group Generic Value Storage
45 * 277 *
278 * Abstracts generic data storage and access to it in an extensible
279 * and efficient way.
280 *
281 * It comes with pre-defined types for numbers, array, list, hash,
282 * blob and structs. It is able to convert between data types,
283 * including to string.
284 *
285 * It is meant for simple data types, providing uniform access and
286 * release functions, useful to exchange data preserving their
287 * types. For more complex hierarchical data, with properties and
288 * children, reference counting, inheritance and interfaces, see @ref
289 * Eina_Model_Group.
290 *
291 * Examples of usage of the Eina_Value API:
292 * @li @ref eina_value_example_01_page
293 * @li @ref eina_value_example_02_page
294 * @li @ref eina_value_example_03_page
295 *
46 * @{ 296 * @{
47 */ 297 */
48 298
@@ -67,6 +317,9 @@ typedef struct _Eina_Value_Type Eina_Value_Type;
67 * @typedef Eina_Value_Union 317 * @typedef Eina_Value_Union
68 * Union of all known value types. 318 * Union of all known value types.
69 * 319 *
320 * This is only used to specify the minimum payload memory for #Eina_Value.
321 *
322 * @internal
70 * @since 1.2 323 * @since 1.2
71 */ 324 */
72typedef union _Eina_Value_Union Eina_Value_Union; 325typedef union _Eina_Value_Union Eina_Value_Union;
@@ -75,6 +328,9 @@ typedef union _Eina_Value_Union Eina_Value_Union;
75 * @union _Eina_Value_Union 328 * @union _Eina_Value_Union
76 * All possible value types. 329 * All possible value types.
77 * 330 *
331 * This is only used to specify the minimum payload memory for #Eina_Value.
332 *
333 * @internal
78 * @since 1.2 334 * @since 1.2
79 */ 335 */
80union _Eina_Value_Union 336union _Eina_Value_Union
@@ -117,6 +373,15 @@ EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_UINT;
117EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_ULONG; 373EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_ULONG;
118 374
119/** 375/**
376 * @var EINA_VALUE_TYPE_TIMESTAMP
377 * manages unsigned long type used for timestamps.
378 * @note this is identical in function to EINA_VALUE_TYPE_ULONG
379 *
380 * @since 1.2
381 */
382EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_TIMESTAMP;
383
384/**
120 * @var EINA_VALUE_TYPE_UINT64 385 * @var EINA_VALUE_TYPE_UINT64
121 * manages unsigned integer of 64 bits type. 386 * manages unsigned integer of 64 bits type.
122 * 387 *
@@ -206,10 +471,11 @@ EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_STRING;
206 * @li eina_value_array_pget() and eina_value_array_pset() 471 * @li eina_value_array_pget() and eina_value_array_pset()
207 * 472 *
208 * eina_value_set() takes an #Eina_Value_Array where just @c subtype 473 * eina_value_set() takes an #Eina_Value_Array where just @c subtype
209 * and @c step are used. If there is an @c array, it will be adopted 474 * and @c step are used. If there is an @c array, it will be copied
210 * and its contents must be properly configurable as @c subtype 475 * (including each item) and its contents must be properly
211 * expects. eina_value_pset() takes a pointer to an #Eina_Value_Array. 476 * configurable as @c subtype expects. eina_value_pset() takes a
212 * For your convenience, use eina_value_array_setup(). 477 * pointer to an #Eina_Value_Array. For your convenience, use
478 * eina_value_array_setup().
213 * 479 *
214 * eina_value_get() and eina_value_pget() takes a pointer to 480 * eina_value_get() and eina_value_pget() takes a pointer to
215 * #Eina_Value_Array, it's an exact copy of the current structure in 481 * #Eina_Value_Array, it's an exact copy of the current structure in
@@ -228,10 +494,11 @@ EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_ARRAY;
228 * @li eina_value_list_pget() and eina_value_list_pset() 494 * @li eina_value_list_pget() and eina_value_list_pset()
229 * 495 *
230 * eina_value_set() takes an #Eina_Value_List where just @c subtype is 496 * eina_value_set() takes an #Eina_Value_List where just @c subtype is
231 * used. If there is an @c list, it will be adopted and its contents 497 * used. If there is an @c list, it will be copied (including each
232 * must be properly configurable as @c subtype 498 * item) and its contents must be properly configurable as @c
233 * expects. eina_value_pset() takes a pointer to an #Eina_Value_List. 499 * subtype expects. eina_value_pset() takes a pointer to an
234 * For your convenience, use eina_value_list_setup(). 500 * #Eina_Value_List. For your convenience, use
501 * eina_value_list_setup().
235 * 502 *
236 * eina_value_get() and eina_value_pget() takes a pointer to 503 * eina_value_get() and eina_value_pget() takes a pointer to
237 * #Eina_Value_List, it's an exact copy of the current structure in 504 * #Eina_Value_List, it's an exact copy of the current structure in
@@ -251,9 +518,9 @@ EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_LIST;
251 * 518 *
252 * eina_value_set() takes an #Eina_Value_Hash where just @c subtype 519 * eina_value_set() takes an #Eina_Value_Hash where just @c subtype
253 * and @c buckets_power_size are used. If there is an @c hash, it will 520 * and @c buckets_power_size are used. If there is an @c hash, it will
254 * be adopted and its contents must be properly configurable as @c 521 * be copied (including each item) and its contents must be
255 * subtype expects. eina_value_pset() takes a pointer to an 522 * properly configurable as @c subtype expects. eina_value_pset()
256 * #Eina_Value_Hash. For your convenience, use 523 * takes a pointer to an #Eina_Value_Hash. For your convenience, use
257 * eina_value_hash_setup(). 524 * eina_value_hash_setup().
258 * 525 *
259 * eina_value_get() and eina_value_pget() takes a pointer to 526 * eina_value_get() and eina_value_pget() takes a pointer to
@@ -310,9 +577,10 @@ EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_BLOB;
310 * @li eina_value_struct_pget() and eina_value_struct_pset() 577 * @li eina_value_struct_pget() and eina_value_struct_pset()
311 * 578 *
312 * eina_value_set() takes an #Eina_Value_Struct where just @c desc is 579 * eina_value_set() takes an #Eina_Value_Struct where just @c desc is
313 * used. If there is an @c memory, it will be adopted and its contents 580 * used. If there is an @c memory, it will be copied (including each
314 * must be properly configurable as @c desc expects. eina_value_pset() 581 * member) and its contents must be properly configurable as @c desc
315 * takes a pointer to an #Eina_Value_Struct. For your convenience, use 582 * expects. eina_value_pset() takes a pointer to an
583 * #Eina_Value_Struct. For your convenience, use
316 * eina_value_struct_setup(). 584 * eina_value_struct_setup().
317 * 585 *
318 * eina_value_get() and eina_value_pget() takes a pointer to 586 * eina_value_get() and eina_value_pget() takes a pointer to
@@ -324,6 +592,23 @@ EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_BLOB;
324EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT; 592EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT;
325 593
326/** 594/**
595 * @var EINA_VALUE_TYPE_MODEL
596 *
597 * manages Eina_Model type. Use the value get/set to change the model
598 * in use, it will increase the reference while in use by the value.
599 *
600 * eina_value_set() takes a pointer to #Eina_Model, increasing the
601 * reference.
602 *
603 * eina_value_get() takes a pointer to pointer to #Eina_Model, it's an
604 * exact copy of the current model, no copies are done, no references
605 * are increased.
606 *
607 * @since 1.2
608 */
609EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_MODEL;
610
611/**
327 * @var EINA_ERROR_VALUE_FAILED 612 * @var EINA_ERROR_VALUE_FAILED
328 * Error identifier corresponding to value check failure. 613 * Error identifier corresponding to value check failure.
329 * 614 *
@@ -435,7 +720,7 @@ static inline void eina_value_flush(Eina_Value *value) EINA_ARG_NONNULL(1);
435 * @param copy destination value object 720 * @param copy destination value object
436 * @return #EINA_TRUE on success, #EINA_FALSE otherwise. 721 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
437 * 722 *
438 * The @a copy object is considered internalized and its existing 723 * The @a copy object is considered uninitialized and its existing
439 * contents are overwritten (just as if eina_value_flush() was called on 724 * contents are overwritten (just as if eina_value_flush() was called on
440 * it). 725 * it).
441 * 726 *
@@ -812,8 +1097,9 @@ static inline const Eina_Value_Type *eina_value_type_get(const Eina_Value *value
812 1097
813/** 1098/**
814 * @typedef Eina_Value_Array 1099 * @typedef Eina_Value_Array
815 * Value type for #EINA_VALUE_TYPE_ARRAY 1100 * Value type for #EINA_VALUE_TYPE_ARRAY.
816 * 1101 *
1102 * @see #_Eina_Value_Array explains fields.
817 * @since 1.2 1103 * @since 1.2
818 */ 1104 */
819typedef struct _Eina_Value_Array Eina_Value_Array; 1105typedef struct _Eina_Value_Array Eina_Value_Array;
@@ -821,6 +1107,7 @@ typedef struct _Eina_Value_Array Eina_Value_Array;
821/** 1107/**
822 * @struct _Eina_Value_Array 1108 * @struct _Eina_Value_Array
823 * Used to store the array and its subtype. 1109 * Used to store the array and its subtype.
1110 * @since 1.2
824 */ 1111 */
825struct _Eina_Value_Array 1112struct _Eina_Value_Array
826{ 1113{
@@ -1433,6 +1720,22 @@ static inline Eina_Bool eina_value_array_pappend(Eina_Value *value,
1433 const void *ptr) EINA_ARG_NONNULL(1); 1720 const void *ptr) EINA_ARG_NONNULL(1);
1434 1721
1435/** 1722/**
1723 * @brief Retrieves a value from the array as an Eina_Value copy.
1724 * @param value source value object
1725 * @param position index of the member
1726 * @param dst where to return the array member
1727 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
1728 *
1729 * The argument @a dst is considered uninitialized and it's setup to
1730 * the type of the member.
1731 *
1732 * @since 1.2
1733 */
1734static inline Eina_Bool eina_value_array_value_get(const Eina_Value *src,
1735 unsigned int position,
1736 Eina_Value *dst) EINA_ARG_NONNULL(1, 3);
1737
1738/**
1436 * @} 1739 * @}
1437 */ 1740 */
1438 1741
@@ -1446,8 +1749,9 @@ static inline Eina_Bool eina_value_array_pappend(Eina_Value *value,
1446 1749
1447/** 1750/**
1448 * @typedef Eina_Value_List 1751 * @typedef Eina_Value_List
1449 * Value type for #EINA_VALUE_TYPE_LIST 1752 * Value type for #EINA_VALUE_TYPE_LIST.
1450 * 1753 *
1754 * @see #_Eina_Value_List explains fields.
1451 * @since 1.2 1755 * @since 1.2
1452 */ 1756 */
1453typedef struct _Eina_Value_List Eina_Value_List; 1757typedef struct _Eina_Value_List Eina_Value_List;
@@ -1455,6 +1759,7 @@ typedef struct _Eina_Value_List Eina_Value_List;
1455/** 1759/**
1456 * @struct _Eina_Value_List 1760 * @struct _Eina_Value_List
1457 * Used to store the list and its subtype. 1761 * Used to store the list and its subtype.
1762 * @since 1.2
1458 */ 1763 */
1459struct _Eina_Value_List 1764struct _Eina_Value_List
1460{ 1765{
@@ -2067,8 +2372,9 @@ static inline Eina_Bool eina_value_list_pappend(Eina_Value *value,
2067 2372
2068/** 2373/**
2069 * @typedef Eina_Value_Hash 2374 * @typedef Eina_Value_Hash
2070 * Value type for #EINA_VALUE_TYPE_HASH 2375 * Value type for #EINA_VALUE_TYPE_HASH.
2071 * 2376 *
2377 * @see #_Eina_Value_Hash explains fields.
2072 * @since 1.2 2378 * @since 1.2
2073 */ 2379 */
2074typedef struct _Eina_Value_Hash Eina_Value_Hash; 2380typedef struct _Eina_Value_Hash Eina_Value_Hash;
@@ -2076,6 +2382,7 @@ typedef struct _Eina_Value_Hash Eina_Value_Hash;
2076/** 2382/**
2077 * @struct _Eina_Value_Hash 2383 * @struct _Eina_Value_Hash
2078 * Used to store the hash and its subtype. 2384 * Used to store the hash and its subtype.
2385 * @since 1.2
2079 */ 2386 */
2080struct _Eina_Value_Hash 2387struct _Eina_Value_Hash
2081{ 2388{
@@ -2409,19 +2716,25 @@ static inline Eina_Bool eina_value_hash_pget(const Eina_Value *value,
2409/** 2716/**
2410 * @typedef Eina_Value_Blob_Operations 2717 * @typedef Eina_Value_Blob_Operations
2411 * How to manage blob. Any @c NULL callback is ignored. 2718 * How to manage blob. Any @c NULL callback is ignored.
2719 * @see #_Eina_Value_Blob_Operations explains fields.
2412 * @since 1.2 2720 * @since 1.2
2413 */ 2721 */
2414typedef struct _Eina_Value_Blob_Operations Eina_Value_Blob_Operations; 2722typedef struct _Eina_Value_Blob_Operations Eina_Value_Blob_Operations;
2415 2723
2416/** 2724/**
2725 * @def EINA_VALUE_BLOB_OPERATIONS_VERSION
2726 * Current API version, used to validate #_Eina_Value_Blob_Operations.
2727 */
2728#define EINA_VALUE_BLOB_OPERATIONS_VERSION (1)
2729
2730/**
2417 * @struct _Eina_Value_Blob_Operations 2731 * @struct _Eina_Value_Blob_Operations
2418 * How to manage blob. Any @c NULL callback is ignored. 2732 * How to manage blob. Any @c NULL callback is ignored.
2419 * @since 1.2 2733 * @since 1.2
2420 */ 2734 */
2421struct _Eina_Value_Blob_Operations 2735struct _Eina_Value_Blob_Operations
2422{ 2736{
2423#define EINA_VALUE_BLOB_OPERATIONS_VERSION (1) 2737 unsigned int version; /**< must be #EINA_VALUE_BLOB_OPERATIONS_VERSION */
2424 unsigned int version; /**< must be EINA_VALUE_BLOB_OPERATIONS_VERSION */
2425 void (*free)(const Eina_Value_Blob_Operations *ops, void *memory, size_t size); 2738 void (*free)(const Eina_Value_Blob_Operations *ops, void *memory, size_t size);
2426 void *(*copy)(const Eina_Value_Blob_Operations *ops, const void *memory, size_t size); 2739 void *(*copy)(const Eina_Value_Blob_Operations *ops, const void *memory, size_t size);
2427 int (*compare)(const Eina_Value_Blob_Operations *ops, const void *data1, size_t size_data1, const void *data2, size_t size_data2); 2740 int (*compare)(const Eina_Value_Blob_Operations *ops, const void *data1, size_t size_data1, const void *data2, size_t size_data2);
@@ -2441,12 +2754,16 @@ EAPI extern const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC;
2441 2754
2442/** 2755/**
2443 * @typedef Eina_Value_Blob 2756 * @typedef Eina_Value_Blob
2757 * Value type for #EINA_VALUE_TYPE_BLOB.
2758 *
2759 * @see #_Eina_Value_Blob explains fields.
2444 * @since 1.2 2760 * @since 1.2
2445 */ 2761 */
2446typedef struct _Eina_Value_Blob Eina_Value_Blob; 2762typedef struct _Eina_Value_Blob Eina_Value_Blob;
2447 2763
2448/** 2764/**
2449 * @struct _Eina_Value_Blob 2765 * @struct _Eina_Value_Blob
2766 * Used to store the blob information and management operations.
2450 * @since 1.2 2767 * @since 1.2
2451 */ 2768 */
2452struct _Eina_Value_Blob 2769struct _Eina_Value_Blob
@@ -2469,6 +2786,11 @@ struct _Eina_Value_Blob
2469/** 2786/**
2470 * @typedef Eina_Value_Struct_Operations 2787 * @typedef Eina_Value_Struct_Operations
2471 * How to manage struct. Any @c NULL callback is ignored. 2788 * How to manage struct. Any @c NULL callback is ignored.
2789 *
2790 * A structure can specify alternative methods to allocate, free and
2791 * copy itself. See structure definition for all methods.
2792 *
2793 * @see #_Eina_Value_Struct_Operations explains fields.
2472 * @since 1.2 2794 * @since 1.2
2473 */ 2795 */
2474typedef struct _Eina_Value_Struct_Operations Eina_Value_Struct_Operations; 2796typedef struct _Eina_Value_Struct_Operations Eina_Value_Struct_Operations;
@@ -2476,6 +2798,12 @@ typedef struct _Eina_Value_Struct_Operations Eina_Value_Struct_Operations;
2476/** 2798/**
2477 * @typedef Eina_Value_Struct_Member 2799 * @typedef Eina_Value_Struct_Member
2478 * Describes a single member of struct. 2800 * Describes a single member of struct.
2801 *
2802 * The member holds a name, type and its byte offset within the struct
2803 * memory. Most Eina_Value_Struct functions takes the member name as
2804 * parameter, as in eina_value_struct_set().
2805 *
2806 * @see #_Eina_Value_Struct_Member explains fields.
2479 * @since 1.2 2807 * @since 1.2
2480 */ 2808 */
2481typedef struct _Eina_Value_Struct_Member Eina_Value_Struct_Member; 2809typedef struct _Eina_Value_Struct_Member Eina_Value_Struct_Member;
@@ -2483,30 +2811,39 @@ typedef struct _Eina_Value_Struct_Member Eina_Value_Struct_Member;
2483/** 2811/**
2484 * @typedef Eina_Value_Struct_Desc 2812 * @typedef Eina_Value_Struct_Desc
2485 * Describes the struct by listing its size, members and operations. 2813 * Describes the struct by listing its size, members and operations.
2814 * @see #_Eina_Value_Struct_Desc explains fields.
2486 * @since 1.2 2815 * @since 1.2
2487 */ 2816 */
2488typedef struct _Eina_Value_Struct_Desc Eina_Value_Struct_Desc; 2817typedef struct _Eina_Value_Struct_Desc Eina_Value_Struct_Desc;
2489 2818
2490/** 2819/**
2491 * @typedef Eina_Value_Struct 2820 * @typedef Eina_Value_Struct
2821 * Value type for #EINA_VALUE_TYPE_STRUCT.
2822 *
2823 * @see #_Eina_Value_Struct explains fields.
2492 * @since 1.2 2824 * @since 1.2
2493 */ 2825 */
2494typedef struct _Eina_Value_Struct Eina_Value_Struct; 2826typedef struct _Eina_Value_Struct Eina_Value_Struct;
2495 2827
2496/** 2828/**
2829 * @def EINA_VALUE_STRUCT_OPERATIONS_VERSION
2830 * Current API version, used to validate #_Eina_Value_Struct_Operations.
2831 */
2832#define EINA_VALUE_STRUCT_OPERATIONS_VERSION (1)
2833
2834/**
2497 * @struct _Eina_Value_Struct_Operations 2835 * @struct _Eina_Value_Struct_Operations
2498 * How to manage struct. Any @c NULL callback is ignored. 2836 * How to manage struct. Any @c NULL callback is ignored.
2499 * @since 1.2 2837 * @since 1.2
2500 */ 2838 */
2501struct _Eina_Value_Struct_Operations 2839struct _Eina_Value_Struct_Operations
2502{ 2840{
2503#define EINA_VALUE_STRUCT_OPERATIONS_VERSION (1) 2841 unsigned int version; /**< must be #EINA_VALUE_STRUCT_OPERATIONS_VERSION */
2504 unsigned int version; /**< must be EINA_VALUE_STRUCT_OPERATIONS_VERSION */ 2842 void *(*alloc)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc); /**< How to allocate struct memory to be managed by the Eina_Value */
2505 void *(*alloc)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc); 2843 void (*free)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, void *memory); /**< How to release memory managed by the Eina_Value */
2506 void (*free)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, void *memory); 2844 void *(*copy)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, const void *memory); /**< How to copy struct memory from an existing Eina_Value, if not provided alloc() will be used, then every member is copied using eina_value_type_copy() with member's type. */
2507 void *(*copy)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, const void *memory); 2845 int (*compare)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, const void *data1, const void *data2); /**< How to compare two struct memories */
2508 int (*compare)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, const void *data1, const void *data2); 2846 const Eina_Value_Struct_Member *(*find_member)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, const char *name); /**< How to find description for member. For huge structures consider using binary search, stringshared, hash or gperf. The default function does linear search using strcmp(). */
2509 const Eina_Value_Struct_Member *(*find_member)(const Eina_Value_Struct_Operations *ops, const Eina_Value_Struct_Desc *desc, const char *name); /**< replace the function to find description for member. For huge structures consider using binary search, stringshared, hash or gperf. The default function does linear search using strcmp(). */
2510}; 2847};
2511 2848
2512/** 2849/**
@@ -2539,23 +2876,48 @@ EAPI extern const Eina_Value_Struct_Operations *EINA_VALUE_STRUCT_OPERATIONS_STR
2539 2876
2540/** 2877/**
2541 * @struct _Eina_Value_Struct_Member 2878 * @struct _Eina_Value_Struct_Member
2879 * Describes a single member of struct.
2880 *
2881 * The name is used to lookup the member description. This is done as
2882 * specified as _Eina_Value_Struct_Operations::find_member(). For
2883 * structures with huge number of members, consider using a better
2884 * find_member function to quickly finding it! There are two helper
2885 * operations provided to help this:
2886 * #EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH and
2887 * #EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE, both depend on properly
2888 * set #_Eina_Value_Struct_Desc and #_Eina_Value_Struct_Member.
2889 *
2890 * @see #EINA_VALUE_STRUCT_MEMBER
2891 * @see #EINA_VALUE_STRUCT_MEMBER_SENTINEL
2892 *
2542 * @since 1.2 2893 * @since 1.2
2543 */ 2894 */
2544struct _Eina_Value_Struct_Member 2895struct _Eina_Value_Struct_Member
2545{ 2896{
2546 const char *name; 2897 const char *name; /**< member name, used in lookups such as eina_value_struct_get() */
2547 const Eina_Value_Type *type; 2898 const Eina_Value_Type *type; /**< how to use this member */
2548 unsigned int offset; 2899 unsigned int offset; /**< where this member is located within the structure memory */
2549}; 2900};
2550 2901
2551/** 2902/**
2903 * @def EINA_VALUE_STRUCT_DESC_VERSION
2904 * Current API version, used to validate #_Eina_Value_Struct_Desc.
2905 */
2906#define EINA_VALUE_STRUCT_DESC_VERSION (1)
2907
2908/**
2552 * @struct _Eina_Value_Struct_Desc 2909 * @struct _Eina_Value_Struct_Desc
2910 * Describes the struct by listing its size, members and operations.
2911 *
2912 * This is the root of Eina_Value knowledge about the memory it's
2913 * handling as a structure. It adds introspection, saying the byte
2914 * size of the structure, its members and how to manage such members.
2915 *
2553 * @since 1.2 2916 * @since 1.2
2554 */ 2917 */
2555struct _Eina_Value_Struct_Desc 2918struct _Eina_Value_Struct_Desc
2556{ 2919{
2557#define EINA_VALUE_STRUCT_DESC_VERSION (1) 2920 unsigned int version; /**< must be #EINA_VALUE_STRUCT_DESC_VERSION */
2558 unsigned int version; /**< must be EINA_VALUE_STRUCT_DESC_VERSION */
2559 const Eina_Value_Struct_Operations *ops; /**< operations, if @c NULL defaults will be used. You may use operations to optimize member lookup using binary search or gperf hash. */ 2921 const Eina_Value_Struct_Operations *ops; /**< operations, if @c NULL defaults will be used. You may use operations to optimize member lookup using binary search or gperf hash. */
2560 const Eina_Value_Struct_Member *members; /**< array of member descriptions, if @c member_count is zero, then it must be @c NULL terminated. */ 2922 const Eina_Value_Struct_Member *members; /**< array of member descriptions, if @c member_count is zero, then it must be @c NULL terminated. */
2561 unsigned int member_count; /**< if > 0, specifies number of members. If zero then @c members must be NULL terminated. */ 2923 unsigned int member_count; /**< if > 0, specifies number of members. If zero then @c members must be NULL terminated. */
@@ -2586,12 +2948,13 @@ struct _Eina_Value_Struct_Desc
2586 2948
2587/** 2949/**
2588 * @struct _Eina_Value_Struct 2950 * @struct _Eina_Value_Struct
2951 * Used to store the memory and its description.
2589 * @since 1.2 2952 * @since 1.2
2590 */ 2953 */
2591struct _Eina_Value_Struct 2954struct _Eina_Value_Struct
2592{ 2955{
2593 const Eina_Value_Struct_Desc *desc; 2956 const Eina_Value_Struct_Desc *desc; /**< How to manage the structure */
2594 void *memory; 2957 void *memory; /**< The managed structure memory */
2595}; 2958};
2596 2959
2597/** 2960/**
@@ -2702,7 +3065,7 @@ static inline Eina_Bool eina_value_struct_setup(Eina_Value *value,
2702 */ 3065 */
2703static inline Eina_Bool eina_value_struct_set(Eina_Value *value, 3066static inline Eina_Bool eina_value_struct_set(Eina_Value *value,
2704 const char *name, 3067 const char *name,
2705 ...) EINA_ARG_NONNULL(1); 3068 ...) EINA_ARG_NONNULL(1, 2);
2706 3069
2707/** 3070/**
2708 * @brief Get the generic value from an struct member. 3071 * @brief Get the generic value from an struct member.
@@ -2770,7 +3133,7 @@ static inline Eina_Bool eina_value_struct_set(Eina_Value *value,
2770 */ 3133 */
2771static inline Eina_Bool eina_value_struct_get(const Eina_Value *value, 3134static inline Eina_Bool eina_value_struct_get(const Eina_Value *value,
2772 const char *name, 3135 const char *name,
2773 ...) EINA_ARG_NONNULL(1); 3136 ...) EINA_ARG_NONNULL(1, 2);
2774 3137
2775/** 3138/**
2776 * @brief Set the generic value in an struct member. 3139 * @brief Set the generic value in an struct member.
@@ -2786,7 +3149,7 @@ static inline Eina_Bool eina_value_struct_get(const Eina_Value *value,
2786 */ 3149 */
2787static inline Eina_Bool eina_value_struct_vset(Eina_Value *value, 3150static inline Eina_Bool eina_value_struct_vset(Eina_Value *value,
2788 const char *name, 3151 const char *name,
2789 va_list args) EINA_ARG_NONNULL(1); 3152 va_list args) EINA_ARG_NONNULL(1, 2);
2790 3153
2791/** 3154/**
2792 * @brief Get the generic value from an struct member. 3155 * @brief Get the generic value from an struct member.
@@ -2808,7 +3171,7 @@ static inline Eina_Bool eina_value_struct_vset(Eina_Value *value,
2808 */ 3171 */
2809static inline Eina_Bool eina_value_struct_vget(const Eina_Value *value, 3172static inline Eina_Bool eina_value_struct_vget(const Eina_Value *value,
2810 const char *name, 3173 const char *name,
2811 va_list args) EINA_ARG_NONNULL(1); 3174 va_list args) EINA_ARG_NONNULL(1, 2);
2812 3175
2813/** 3176/**
2814 * @brief Set the generic value in an struct member from pointer. 3177 * @brief Set the generic value in an struct member from pointer.
@@ -2875,7 +3238,7 @@ static inline Eina_Bool eina_value_struct_vget(const Eina_Value *value,
2875 */ 3238 */
2876static inline Eina_Bool eina_value_struct_pset(Eina_Value *value, 3239static inline Eina_Bool eina_value_struct_pset(Eina_Value *value,
2877 const char *name, 3240 const char *name,
2878 const void *ptr) EINA_ARG_NONNULL(1, 3); 3241 const void *ptr) EINA_ARG_NONNULL(1, 2, 3);
2879 3242
2880/** 3243/**
2881 * @brief Get the generic value to pointer from an struct member. 3244 * @brief Get the generic value to pointer from an struct member.
@@ -2944,7 +3307,62 @@ static inline Eina_Bool eina_value_struct_pset(Eina_Value *value,
2944 */ 3307 */
2945static inline Eina_Bool eina_value_struct_pget(const Eina_Value *value, 3308static inline Eina_Bool eina_value_struct_pget(const Eina_Value *value,
2946 const char *name, 3309 const char *name,
2947 void *ptr) EINA_ARG_NONNULL(1, 3); 3310 void *ptr) EINA_ARG_NONNULL(1, 2, 3);
3311
3312/**
3313 * @brief Get the member as Eina_Value copy
3314 * @param src source value object
3315 * @param name name to find the member
3316 * @param dst where to return the member value.
3317 *
3318 * The argument @a dst is considered uninitialized and it's setup to
3319 * the type of the member.
3320 *
3321 * @since 1.2
3322 */
3323static inline Eina_Bool eina_value_struct_value_get(const Eina_Value *src,
3324 const char *name,
3325 Eina_Value *dst) EINA_ARG_NONNULL(1, 2, 3);
3326
3327/**
3328 * @brief Set the member from Eina_Value source
3329 * @param dst destination value object
3330 * @param name name to find the member
3331 * @param src source value
3332 *
3333 * @since 1.2
3334 */
3335static inline Eina_Bool eina_value_struct_value_set(Eina_Value *dst,
3336 const char *name,
3337 const Eina_Value *src) EINA_ARG_NONNULL(1, 2, 3);
3338
3339/**
3340 * @brief Get the member as Eina_Value copy given its member description.
3341 * @param src source value object
3342 * @param member the member description to use
3343 * @param dst where to return the member value.
3344 *
3345 * The argument @a dst is considered uninitialized and it's setup to
3346 * the type of the member.
3347 *
3348 * @since 1.2
3349 */
3350static inline Eina_Bool eina_value_struct_member_value_get(const Eina_Value *src,
3351 const Eina_Value_Struct_Member *member,
3352 Eina_Value *dst) EINA_ARG_NONNULL(1, 2, 3);
3353
3354/**
3355 * @brief Set the member from Eina_Value source
3356 * @param dst destination value object
3357 * @param member the member description to use
3358 * @param src source value
3359 *
3360 * @since 1.2
3361 */
3362static inline Eina_Bool eina_value_struct_member_value_set(Eina_Value *dst,
3363 const Eina_Value_Struct_Member *member,
3364 const Eina_Value *src) EINA_ARG_NONNULL(1, 2, 3);
3365
2948 3366
2949/** 3367/**
2950 * @} 3368 * @}
@@ -2958,6 +3376,12 @@ static inline Eina_Bool eina_value_struct_pget(const Eina_Value *value,
2958 */ 3376 */
2959 3377
2960/** 3378/**
3379 * @def EINA_VALUE_TYPE_VERSION
3380 * Current API version, used to validate type.
3381 */
3382#define EINA_VALUE_TYPE_VERSION (1)
3383
3384/**
2961 * @struct _Eina_Value_Type 3385 * @struct _Eina_Value_Type
2962 * API to access values. 3386 * API to access values.
2963 * 3387 *
@@ -2965,11 +3389,6 @@ static inline Eina_Bool eina_value_struct_pget(const Eina_Value *value,
2965 */ 3389 */
2966struct _Eina_Value_Type 3390struct _Eina_Value_Type
2967{ 3391{
2968 /**
2969 * @def EINA_VALUE_TYPE_VERSION
2970 * Current API version, used to validate type.
2971 */
2972#define EINA_VALUE_TYPE_VERSION (1)
2973 unsigned int version; /**< must be #EINA_VALUE_TYPE_VERSION */ 3392 unsigned int version; /**< must be #EINA_VALUE_TYPE_VERSION */
2974 unsigned int value_size; /**< byte size of value */ 3393 unsigned int value_size; /**< byte size of value */
2975 const char *name; /**< name for debug and introspection */ 3394 const char *name; /**< name for debug and introspection */