diff options
Diffstat (limited to 'libraries/eina/src/include/eina_model.h')
-rw-r--r-- | libraries/eina/src/include/eina_model.h | 3105 |
1 files changed, 0 insertions, 3105 deletions
diff --git a/libraries/eina/src/include/eina_model.h b/libraries/eina/src/include/eina_model.h deleted file mode 100644 index 0a1566e..0000000 --- a/libraries/eina/src/include/eina_model.h +++ /dev/null | |||
@@ -1,3105 +0,0 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2012 ProFUSION embedded systems | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef EINA_MODEL_H_ | ||
20 | #define EINA_MODEL_H_ | ||
21 | |||
22 | #include "eina_types.h" | ||
23 | #include "eina_value.h" | ||
24 | #include "eina_inlist.h" | ||
25 | #include <stdarg.h> | ||
26 | |||
27 | /** | ||
28 | * @page eina_model_01_c Eina_Model inheritance and function overriding | ||
29 | * @include eina_model_01.c | ||
30 | */ | ||
31 | |||
32 | /** | ||
33 | * @page eina_model_04_c Eina_Model inheritance, interfaces, and function overriding | ||
34 | * @include eina_model_04_main.c | ||
35 | * @include eina_model_04_animal.c | ||
36 | * @include eina_model_04_human.c | ||
37 | * @include eina_model_04_parrot.c | ||
38 | * @include eina_model_04_child.c | ||
39 | * @include eina_model_04_main.c | ||
40 | * @include eina_model_04_whistler.c | ||
41 | * @include eina_model_04_animal.h | ||
42 | * @include eina_model_04_human.h | ||
43 | * @include eina_model_04_whistler.h | ||
44 | * @include eina_model_04_child.h | ||
45 | * @include eina_model_04_parrot.h | ||
46 | */ | ||
47 | |||
48 | /** | ||
49 | * @page eina_model_02_example_page Creating a simple model | ||
50 | * @dontinclude eina_model_02.c | ||
51 | * | ||
52 | * This example shows the creation of a model with five properties, named: | ||
53 | * 'a', 'b', 'c', 'd' and 'e' with values 0, 1, 2, 3 and 4 | ||
54 | * respectively. In addition to the 5 properties our model also add 5 children, | ||
55 | * and to each child we give a property named 'x' with a value of 1, 2, 3, 4 and | ||
56 | * 5. | ||
57 | * | ||
58 | * In other words this piece of code shows how to use eina_model to store a list | ||
59 | * of elements, given that the list itself has some properties. | ||
60 | * | ||
61 | * Now let's walk through the code and examine the interesting bits. | ||
62 | * | ||
63 | * This is some pretty standard initialization code. | ||
64 | * @until eina_init | ||
65 | * | ||
66 | * We now create our eina_model, the important detail here is the type of the | ||
67 | * model being created, for this example we use the generic type provided by | ||
68 | * eina: | ||
69 | * @until model_new | ||
70 | * | ||
71 | * Once our model has been created we can add callbacks to be notified of events | ||
72 | * that happen to our model, for this example we are just going to add a | ||
73 | * callback for the "delete" event. To get a list of events a given eina model | ||
74 | * can emit see @ref eina_model_event_names_list_get(). | ||
75 | * @until callback_add | ||
76 | * | ||
77 | * Once we have a model, we need to populate it with information. There are two | ||
78 | * types of information we can store on an eina model: properties and eina | ||
79 | * models. We are going to start by looking at properties. | ||
80 | * | ||
81 | * Properties are, simply put, named values. They have a char* identifier and an | ||
82 | * Eina_Value value. This means you can store in a property almost any type of | ||
83 | * data. For this example we are going to add some very simple numeric | ||
84 | * properties which will have single letter identifiers. | ||
85 | * @until } | ||
86 | * @until } | ||
87 | * | ||
88 | * Despite being able to store almost any value properties the least flexible | ||
89 | * information unit we can put in an eina model. We can add eina models to our | ||
90 | * eina model, this allows us to represt complex information hierarchies. This | ||
91 | * example adds 5 models(with no children of their own) to our parent model @c | ||
92 | * m. | ||
93 | * @until } | ||
94 | * The code here should be pretty easy to understand, we create a model, much | ||
95 | * like we did before, and we then add a property to our model, again a task we | ||
96 | * have already done. | ||
97 | * | ||
98 | * The important issue to note here is that we could have given each of our @c c | ||
99 | * child models as complex an structure as we needed, they could each be a list | ||
100 | * or a tree on their own right. | ||
101 | * | ||
102 | * Now that we have a populated model we print a string representation of | ||
103 | * it(without forgetting to free the string): | ||
104 | * @until free | ||
105 | * | ||
106 | * And since we are done using our model we release our reference to it(and | ||
107 | * since no else holds references to it, it will be freed): | ||
108 | * @until } | ||
109 | * | ||
110 | * Note that we don't need to iterate over the children of @c m unrefing it, | ||
111 | * this is because we don't hold references to it, we freed our references right | ||
112 | * after we added them to their parent model, so when the parent model dies(and | ||
113 | * releases the references to it's children) they will be freed. | ||
114 | * | ||
115 | * The only thing we are going to look at is the callback we registered for | ||
116 | * whenever a model is deleted, since our models don't do anything fancy we are | ||
117 | * just going to print the memory address of the model being freed. | ||
118 | * @until } | ||
119 | * | ||
120 | * Note that this means the memory address is still valid, our callback is | ||
121 | * called just before the memory is freed so we could still access its | ||
122 | * information here. | ||
123 | * | ||
124 | * The full code can be seen in @ref eina_model_02_c | ||
125 | */ | ||
126 | |||
127 | /** | ||
128 | * @page eina_model_02_c eina_model_02.c | ||
129 | * @include eina_model_02.c | ||
130 | * @example eina_model_02.c | ||
131 | */ | ||
132 | |||
133 | /** | ||
134 | * @page eina_model_03_example_page Using Eina_Model and inheritance | ||
135 | * @dontinclude eina_model_03.c | ||
136 | * | ||
137 | * This example will use two custom defined eina model types: @c PERSON_TYPE to | ||
138 | * represent a person and @c ADDRESS_BOOK_TYPE to represent the an address book. | ||
139 | * Both our types inherit from EINA_MODEL_TYPE_STRUCT, and, therefore, | ||
140 | * store it's data on a struct. Our address book will be very simple it will | ||
141 | * only contain one property, the name of the file where we store our address | ||
142 | * book. The person type will contain two fields a name and en email. Let's look | ||
143 | * at the code. | ||
144 | * | ||
145 | * We'll start with declaring the variables and functions we'll need to define | ||
146 | * our custom type. This will all be explained when the variables get used. | ||
147 | * @until address_book_init | ||
148 | * | ||
149 | * We then jump into our @c main function, declare a couple of variables and | ||
150 | * initialize eina: | ||
151 | * @until eina_init | ||
152 | * | ||
153 | * After eina is initialized we'll @c address_book_init() which will initialize | ||
154 | * both our @c PERSON_TYPE and our @c ADDRESS_BOOK_TYPE. Details of this will be | ||
155 | * shown latter on: | ||
156 | * @until address_book_init | ||
157 | * | ||
158 | * Now that everything is correctly initialized we can create the model that | ||
159 | * will represent our address book's | ||
160 | * @until eina_model_new | ||
161 | * | ||
162 | * Before we can load data into our model we need to tell it where to load from, | ||
163 | * we do this by setting it's filename property: | ||
164 | * @until value_flush | ||
165 | * | ||
166 | * We then load data into our model and display it as a string: | ||
167 | * @until free | ||
168 | * | ||
169 | * While @c eina_model_to_string allows you to see the contents of the model, | ||
170 | * it's display format is not user friendly, it's best used for debugging. So | ||
171 | * let's now print our model in a user friendly way. | ||
172 | * | ||
173 | * First we see how many people are in our address book and print that: | ||
174 | * @until printf | ||
175 | * | ||
176 | * And now we iterate over every child of our address book model, which | ||
177 | * represents a person: | ||
178 | * @until person | ||
179 | * | ||
180 | * But again simply calling @c eina_model_to_string would result in not very | ||
181 | * user friendly output, so we'll need to get the properties of the person(name | ||
182 | * and email) and print them with some formatting: | ||
183 | * @until printf | ||
184 | * | ||
185 | * We then free the resources we allocated to print this person: | ||
186 | * @until } | ||
187 | * | ||
188 | * And that's it for our main function, now just freeing our resources: | ||
189 | * @until } | ||
190 | * | ||
191 | * This however obviously doesn't conclude our example we need to examine how | ||
192 | * the the loading of data works to really understand what is happening in the | ||
193 | * @c main function. | ||
194 | * | ||
195 | * Let's start with the constructors(and the variables they use). Both our | ||
196 | * constructors do two very important tasks: | ||
197 | * @li Calls our parent's constructor, and | ||
198 | * @li Sets the description of the struct on our model | ||
199 | * | ||
200 | * For these constructors that's all we need to do since most of our | ||
201 | * functionality is provided by @c EINA_MODEL_TYPE_STRUCT. | ||
202 | * @until } | ||
203 | * @until } | ||
204 | * | ||
205 | * And now we have our load function, it opens the file from which we'll | ||
206 | * read the address book: | ||
207 | * @until EINA_SAFETY_ON_NULL_RETURN_VAL | ||
208 | * | ||
209 | * Once the file has been opened we read from it line by line and for each | ||
210 | * non-blank line we get a name and an email: | ||
211 | * @until email | ||
212 | * @until email | ||
213 | * | ||
214 | * Once we have the name and email we create our person model, set it's | ||
215 | * properties and make our person a child of the address book: | ||
216 | * @until } | ||
217 | * | ||
218 | * And now that we're done reading the file we close it: | ||
219 | * @until } | ||
220 | * | ||
221 | * This next function is perphaps the most interesting one of our example, it's | ||
222 | * the one that creates the definition of our derived types. | ||
223 | * | ||
224 | * First thing we'll do is the description of the members of our person type. | ||
225 | * @until person_members[1].type | ||
226 | * Now the description of the struct itself(which uses the members): | ||
227 | * @until } | ||
228 | * And finally we define the person type itself: | ||
229 | * @until person_type.constructor | ||
230 | * | ||
231 | * With the person now described we'll do the same process for our address book | ||
232 | * type: | ||
233 | * @until address_book_type.load | ||
234 | * | ||
235 | * So far everything we created has been in the scope of our function to make | ||
236 | * this available outside(such as in the @c main function where we use @c | ||
237 | * ADDRESS_BOOK_TYPE and on @c _address_book_load function where we use @c | ||
238 | * PERSON_TYPE) we need to assign our descriptions and type to global variables: | ||
239 | * @until } | ||
240 | * | ||
241 | * This concludes this example. A good exercise for the reader is to extend this | ||
242 | * example to have the model save the addres book, for example once it's | ||
243 | * unloaded, this can be done by overriding the .unload property of @c | ||
244 | * ADDRESS_BOOK_TYPE. | ||
245 | * | ||
246 | * For the full code see: @ref eina_model_03_c | ||
247 | */ | ||
248 | |||
249 | /** | ||
250 | * @page eina_model_03_c eina_model_03.c | ||
251 | * @include eina_model_03.c | ||
252 | * @example eina_model_03.c | ||
253 | */ | ||
254 | |||
255 | /** | ||
256 | * @addtogroup Eina_Data_Types_Group Data Types | ||
257 | * | ||
258 | * @since 1.2 | ||
259 | * | ||
260 | * @{ | ||
261 | */ | ||
262 | |||
263 | /** | ||
264 | * @addtogroup Eina_Containers_Group Containers | ||
265 | * | ||
266 | * @{ | ||
267 | */ | ||
268 | |||
269 | /** | ||
270 | * @defgroup Eina_Model_Group Data Model API | ||
271 | * | ||
272 | * Abstracts data access to hierarchical data in an efficient way, | ||
273 | * extensible to different backing stores such as database or remote | ||
274 | * access. | ||
275 | * | ||
276 | * It is heavily based on #Eina_Value, as properties are exchanged | ||
277 | * using this data type as interface, although internally models may | ||
278 | * store them as they want. See @ref Eina_Value_Group. | ||
279 | * | ||
280 | * Although extensible and easy to optimize, a simple generic type is | ||
281 | * provided as #EINA_MODEL_TYPE_GENERIC. It is recommended that people | ||
282 | * use it during development, get the logic right and just then | ||
283 | * optimize what is needed (properties or children management). | ||
284 | * | ||
285 | * Not as generic as #EINA_MODEL_TYPE_GENERIC, but way more efficient | ||
286 | * is #EINA_MODEL_TYPE_STRUCT that instead of a hash of properties of | ||
287 | * any type, it uses a struct to map properties. Its properties are | ||
288 | * fixed set of names and they have fixed type, as defined by the | ||
289 | * #Eina_Value_Struct_Desc description used internally. | ||
290 | * | ||
291 | * Examples: | ||
292 | * @li @ref eina_model_01_c inheritance example, uses #EINA_MODEL_TYPE_GENERIC | ||
293 | * @li @ref eina_model_02_example_page contains an easy to follow | ||
294 | * example that demonstrates several of the important features of | ||
295 | * eina_model, uses #EINA_MODEL_TYPE_GENERIC. | ||
296 | * @li @ref eina_model_03_example_page walk-through example on how to | ||
297 | * inherit types, a suggestion of eina_model_load() usage and uses | ||
298 | * #EINA_MODEL_TYPE_STRUCT. | ||
299 | * @li @ref eina_model_04_c Advanced inheritance, interfaces and interface | ||
300 | * function overloading example. | ||
301 | * | ||
302 | * @{ | ||
303 | */ | ||
304 | |||
305 | /** | ||
306 | * @var EINA_ERROR_MODEL_FAILED | ||
307 | * Defined when model-specific errors happens. | ||
308 | */ | ||
309 | EAPI extern Eina_Error EINA_ERROR_MODEL_FAILED; | ||
310 | |||
311 | /** | ||
312 | * @var EINA_ERROR_MODEL_METHOD_MISSING | ||
313 | * Defined when model-specific errors happens. | ||
314 | */ | ||
315 | EAPI extern Eina_Error EINA_ERROR_MODEL_METHOD_MISSING; | ||
316 | |||
317 | /** | ||
318 | * @typedef Eina_Model | ||
319 | * Data Model Object. | ||
320 | * | ||
321 | * This is an opaque handle that is created with eina_model_new() and | ||
322 | * released with eina_model_unref(). | ||
323 | * | ||
324 | * It contains properties, children and may emit events. See | ||
325 | * respectively: | ||
326 | * @li eina_model_property_get() and eina_model_property_set() | ||
327 | * @li eina_model_child_get() and eina_model_child_set() | ||
328 | * @li eina_model_event_names_list_get(), eina_model_event_callback_add() and eina_model_event_callback_del() | ||
329 | * | ||
330 | * @see eina_model_new() | ||
331 | * @see eina_model_ref() and eina_model_xref() | ||
332 | * @see eina_model_unref(), eina_model_xunref() and eina_model_del() | ||
333 | * @see eina_model_type_get() and eina_model_interface_get() | ||
334 | * @since 1.2 | ||
335 | */ | ||
336 | typedef struct _Eina_Model Eina_Model; | ||
337 | |||
338 | /** | ||
339 | * @typedef Eina_Model_Type | ||
340 | * Data Model Type. | ||
341 | * | ||
342 | * @see #_Eina_Model_Type explains fields. | ||
343 | * @since 1.2 | ||
344 | */ | ||
345 | typedef struct _Eina_Model_Type Eina_Model_Type; | ||
346 | |||
347 | /** | ||
348 | * @typedef Eina_Model_Interface | ||
349 | * Data Model Interface. | ||
350 | * | ||
351 | * @see #_Eina_Model_Interface explains fields. | ||
352 | * @since 1.2 | ||
353 | */ | ||
354 | typedef struct _Eina_Model_Interface Eina_Model_Interface; | ||
355 | |||
356 | /** | ||
357 | * @typedef Eina_Model_Event_Description | ||
358 | * Data Model Event Description. | ||
359 | * | ||
360 | * This is used to declare events supported by types and interfaces | ||
361 | * and also to provide introspection to receivers of signals so they | ||
362 | * can know which data they are receiving as @c event_info. | ||
363 | * | ||
364 | * @see EINA_MODEL_EVENT_DESCRIPTION() | ||
365 | * @see #EINA_MODEL_EVENT_DESCRIPTION_SENTINEL | ||
366 | * @see #_Eina_Model_Event_Description explains fields. | ||
367 | * @since 1.2 | ||
368 | */ | ||
369 | typedef struct _Eina_Model_Event_Description Eina_Model_Event_Description; | ||
370 | |||
371 | /** | ||
372 | * @brief Creates a new model of type @a Type. | ||
373 | * @param type The type of the model to create. | ||
374 | * @return If successfull pointer to model, NULL otherwise. | ||
375 | * | ||
376 | * @see _Eina_Model_Type | ||
377 | * @see eina_model_del() | ||
378 | * @since 1.2 | ||
379 | */ | ||
380 | EAPI Eina_Model *eina_model_new(const Eina_Model_Type *type); | ||
381 | /** | ||
382 | * @brief Frees the memory associated with @a model | ||
383 | * @param model The model instance. | ||
384 | * | ||
385 | * @see eina_model_new() | ||
386 | * @since 1.2 | ||
387 | */ | ||
388 | EAPI void eina_model_del(Eina_Model *model) EINA_ARG_NONNULL(1); | ||
389 | |||
390 | /** | ||
391 | * @brief Returns the type of @a model. | ||
392 | * @param model The model instance. | ||
393 | * @return The type of @a model. | ||
394 | * | ||
395 | * @see eina_model_new() | ||
396 | * @see _Eina_Model_Type | ||
397 | * @since 1.2 | ||
398 | */ | ||
399 | EAPI const Eina_Model_Type *eina_model_type_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
400 | |||
401 | /** | ||
402 | * @brief Returns the interface named @a name of @a model. | ||
403 | * @param model The model instance. | ||
404 | * @param name Name of interface to get. | ||
405 | * @return If successfull requested interface, NULL otherwise. | ||
406 | * | ||
407 | * The name of every interface of @a model will be compared to @a name, the | ||
408 | * first one to match will be returned. | ||
409 | * | ||
410 | * @see eina_model_new() | ||
411 | * @see _Eina_Model_Interface | ||
412 | * @since 1.2 | ||
413 | */ | ||
414 | EAPI const Eina_Model_Interface *eina_model_interface_get(const Eina_Model *model, | ||
415 | const char *name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
416 | |||
417 | /** | ||
418 | * @brief Increases the refcount of @a model. | ||
419 | * @param model The model to increase reference. | ||
420 | * @return The @a model with reference increased. | ||
421 | * @return If successfull pointer to model, NULL otherwise. | ||
422 | * | ||
423 | * @see eina_model_new() | ||
424 | * @see eina_model_unref() | ||
425 | * @since 1.2 | ||
426 | */ | ||
427 | EAPI Eina_Model *eina_model_ref(Eina_Model *model) EINA_ARG_NONNULL(1); | ||
428 | |||
429 | /** | ||
430 | * @brief Increases the refcount of @a model, informs reference identifier. | ||
431 | * @param model The model to increase reference. | ||
432 | * @param id An identifier to mark this reference. | ||
433 | * @param label An optional label to help debug, may be @c NULL. | ||
434 | * @return The @a model with reference increased. | ||
435 | * | ||
436 | * This extended version of reference explicitly marks the origin of | ||
437 | * the reference and eina_model_xunref() should be used to check and | ||
438 | * remove it. | ||
439 | * | ||
440 | * Usually the @a id is another object, like a parent object, or some | ||
441 | * class/structure/file/function that is holding the reference for | ||
442 | * some reason. | ||
443 | * | ||
444 | * Its purpose is to help debuging if Eina was compiled with model | ||
445 | * usage debug enabled and environment variable @c EINA_MODEL_DEBUG=1 | ||
446 | * is set. | ||
447 | * | ||
448 | * It is recommended to use eina_model_xref() and eina_model_xunref() | ||
449 | * pair whenever you want to be sure you released your | ||
450 | * references. Both at your own type, or using applications. As an | ||
451 | * example #EINA_MODEL_INTERFACE_CHILDREN_INARRAY will use this to | ||
452 | * make sure it deleted every managed children. | ||
453 | * | ||
454 | * In order to debug leaks, consider using eina_model_xrefs_get() or | ||
455 | * eina_models_usage_dump() for a global picture. However, some | ||
456 | * references are not tracked, namely: | ||
457 | * | ||
458 | * @li eina_model_new() | ||
459 | * @li eina_model_child_get() | ||
460 | * @li eina_model_child_iterator_get() | ||
461 | * @li eina_model_child_reversed_iterator_get() | ||
462 | * @li eina_model_child_sorted_iterator_get() | ||
463 | * @li eina_model_child_filtered_iterator_get() | ||
464 | * @li eina_model_child_slice_iterator_get() | ||
465 | * @li eina_model_child_slice_reversed_iterator_get() | ||
466 | * @li eina_model_child_slice_sorted_iterator_get() | ||
467 | * @li eina_model_child_slice_filtered_iterator_get() | ||
468 | * | ||
469 | * @note this function is slower than eina_model_ref() if | ||
470 | * @c EINA_MODEL_DEBUG is set to "1" or "backtrace". Otherwise it | ||
471 | * should have the same performance cost. | ||
472 | * | ||
473 | * @see eina_model_ref() | ||
474 | * @see eina_model_xunref() | ||
475 | * @since 1.2 | ||
476 | */ | ||
477 | EAPI Eina_Model *eina_model_xref(Eina_Model *model, | ||
478 | const void *id, | ||
479 | const char *label) EINA_ARG_NONNULL(1, 2); | ||
480 | |||
481 | /** | ||
482 | * @brief Decreases the refcount of @a model. | ||
483 | * @param model The model to decrease reference. | ||
484 | * @return If successfull pointer to model, NULL otherwise. | ||
485 | * | ||
486 | * After this function returns, consider @a model pointer invalid. | ||
487 | * | ||
488 | * @see eina_model_ref() | ||
489 | * @see eina_model_del() | ||
490 | * @since 1.2 | ||
491 | */ | ||
492 | EAPI void eina_model_unref(Eina_Model *model) EINA_ARG_NONNULL(1); | ||
493 | |||
494 | /** | ||
495 | * @brief Decreases the refcount of @a model, informs reference identifier. | ||
496 | * @param model The model to decrease reference. | ||
497 | * @param id An identifier to mark this reference. | ||
498 | * @return If successfull pointer to model, NULL otherwise. | ||
499 | * | ||
500 | * This function will match eina_model_xref() and the @a id must match | ||
501 | * a previously call, otherwise it will produce an error if @c | ||
502 | * EINA_MODEL_DEBUG is set to "1" or "backtrace", and the reference is | ||
503 | * not decreased! | ||
504 | * | ||
505 | * After this function returns, consider @a model pointer invalid. | ||
506 | * | ||
507 | * @note this function is slower than eina_model_unref() if | ||
508 | * @c EINA_MODEL_DEBUG is set to "1" or "backtrace". Otherwise it | ||
509 | * should have the same performance cost. | ||
510 | * | ||
511 | * @see eina_model_xref() | ||
512 | * @since 1.2 | ||
513 | */ | ||
514 | EAPI void eina_model_xunref(Eina_Model *model, | ||
515 | const void *id) EINA_ARG_NONNULL(1, 2); | ||
516 | |||
517 | |||
518 | |||
519 | /** | ||
520 | * @defgroup Eina_Model_Event_Group Data Model Events | ||
521 | * Events and their usage with models. | ||
522 | * | ||
523 | * Events are specified by each type and interface level using | ||
524 | * #Eina_Model_Event_Description. One can know all events supported by | ||
525 | * a model with eina_model_event_names_list_get() and then | ||
526 | * eina_model_event_description_get() to retrieve details. | ||
527 | * | ||
528 | * By default the following events are supported in every object: | ||
529 | * @li deleted: last reference was released or eina_model_del() was called. | ||
530 | * @li freed: memory was destroyed, destructors were called. | ||
531 | * @li property,set: eina_model_property_set() was done. | ||
532 | * @li property,deleted: eina_model_property_del() was done. | ||
533 | * @li children,changed: children was changed somehow (added, modified, deleted) | ||
534 | * @li child,inserted: new child was added (eina_model_child_append() or eina_model_child_insert_at()) | ||
535 | * @li child,set: child was replaced (eina_model_child_set()) | ||
536 | * @li child,deleted: eina_model_child_del() was done. | ||
537 | * @li loaded: eina_model_load() was done. | ||
538 | * @li unloaded: eina_model_unload() was done. | ||
539 | * | ||
540 | * Mix-in interfaces may emit these: | ||
541 | * @li properties,loaded | ||
542 | * @li properties,unloaded | ||
543 | * @li children,loaded | ||
544 | * @li children,unloaded | ||
545 | * | ||
546 | * One can be notified of events with eina_model_event_callback_add(). | ||
547 | * | ||
548 | * Types emit these events with eina_model_event_callback_call(), | ||
549 | * these are handled asynchronously unless event is frozen with | ||
550 | * eina_model_event_callback_freeze() is blocking it. In this case the | ||
551 | * events are ignored. Usually this is used in some cases that want to | ||
552 | * avoid storm of events in batch operations. | ||
553 | * | ||
554 | * @{ | ||
555 | */ | ||
556 | |||
557 | /** | ||
558 | * @typedef Eina_Model_Event_Cb | ||
559 | * Notifies of events in this model. | ||
560 | * | ||
561 | * @since 1.2 | ||
562 | */ | ||
563 | typedef void (*Eina_Model_Event_Cb)(void *data, Eina_Model *model, const Eina_Model_Event_Description *desc, void *event_info); | ||
564 | |||
565 | /** | ||
566 | * @brief Add a callback to be called when @a event_name is emited. | ||
567 | * @param model The model instance. | ||
568 | * @param event_name The name of event for which @a cb will be called. | ||
569 | * @param cb The function to be called. | ||
570 | * @param data Data @a cb will be called with. May be NULL. | ||
571 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
572 | * | ||
573 | * @see eina_model_event_callback_del() | ||
574 | * @since 1.2 | ||
575 | */ | ||
576 | EAPI Eina_Bool eina_model_event_callback_add(Eina_Model *model, | ||
577 | const char *event_name, | ||
578 | Eina_Model_Event_Cb cb, | ||
579 | const void *data) EINA_ARG_NONNULL(1, 2, 3); | ||
580 | /** | ||
581 | * @brief Remove a callback that was to be called when @a event_name was emited. | ||
582 | * @param model The model instance. | ||
583 | * @param event_name The name of event for which to delete callback. | ||
584 | * @param cb The function given to eina_model_event_callback_add(). | ||
585 | * @param data Data given to eina_model_event_callback_add(). A NULL value means | ||
586 | * every @a data will not be compared. | ||
587 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
588 | * | ||
589 | * @see eina_model_event_callback_add() | ||
590 | * @since 1.2 | ||
591 | */ | ||
592 | EAPI Eina_Bool eina_model_event_callback_del(Eina_Model *model, | ||
593 | const char *event_name, | ||
594 | Eina_Model_Event_Cb cb, | ||
595 | const void *data) EINA_ARG_NONNULL(1, 2, 3); | ||
596 | |||
597 | /** | ||
598 | * @brief Returns a description of the event named @c event_name | ||
599 | * @param model The model instance. | ||
600 | * @param event_name Name of event whose description is wanted. | ||
601 | * @return Description of event. | ||
602 | * | ||
603 | * @see Eina_Model_Event_Description | ||
604 | * @since 1.2 | ||
605 | */ | ||
606 | EAPI const Eina_Model_Event_Description *eina_model_event_description_get(const Eina_Model *model, | ||
607 | const char *event_name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
608 | |||
609 | /** | ||
610 | * @brief Returns list of events this model may emit. | ||
611 | * @param model The model whose events are to be listed. | ||
612 | * @return An Eina_List of stringshares with the name of every event. Free the | ||
613 | * list with eina_model_event_names_list_free(). | ||
614 | * | ||
615 | * @since 1.2 | ||
616 | */ | ||
617 | EAPI Eina_List *eina_model_event_names_list_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
618 | /** | ||
619 | * @brief Frees the list of event's names gotten from | ||
620 | * eina_model_event_names_list_get(). | ||
621 | * @param list The list to free. | ||
622 | * | ||
623 | * @see eina_model_event_names_list_get() | ||
624 | * @since 1.2 | ||
625 | */ | ||
626 | EAPI void eina_model_event_names_list_free(Eina_List *list); | ||
627 | |||
628 | /** | ||
629 | * @brief Calls every callback associated to @a name on model @a model with @a | ||
630 | * event_info. | ||
631 | * @param model The model instance. | ||
632 | * @param name The event whose callbacks will be called. | ||
633 | * @param event_info The data given to the callback as event_info. May be NULL. | ||
634 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
635 | * | ||
636 | * @see eina_model_event_callback_add() | ||
637 | * @see eina_model_event_callback_del() | ||
638 | * @since 1.2 | ||
639 | */ | ||
640 | EAPI Eina_Bool eina_model_event_callback_call(Eina_Model *model, | ||
641 | const char *name, | ||
642 | const void *event_info) EINA_ARG_NONNULL(1, 2); | ||
643 | |||
644 | /** | ||
645 | * @brief Makes @a model not call the callbacks associated with @a name. | ||
646 | * @param model The model instance. | ||
647 | * @param name The event whose callbacks are to be frozen. | ||
648 | * @return Count of freezes called on this event. | ||
649 | * | ||
650 | * @see eina_model_event_callback_call() | ||
651 | * @see eina_model_event_callback_thaw() | ||
652 | * @since 1.2 | ||
653 | */ | ||
654 | EAPI int eina_model_event_callback_freeze(Eina_Model *model, | ||
655 | const char *name) EINA_ARG_NONNULL(1, 2); | ||
656 | /** | ||
657 | * @brief Makes @a model able to call the callbacks associated with @a name. | ||
658 | * @param model The model instance. | ||
659 | * @param name The event whose callbacks are to be frozen. | ||
660 | * @return Count of freezes still valid in this event. | ||
661 | * | ||
662 | * @warning Behavior is undefined if called on a @a model, @a name not frozen. | ||
663 | * | ||
664 | * @see eina_model_event_callback_call() | ||
665 | * @see eina_model_event_callback_freeze() | ||
666 | * @since 1.2 | ||
667 | */ | ||
668 | EAPI int eina_model_event_callback_thaw(Eina_Model *model, | ||
669 | const char *name) EINA_ARG_NONNULL(1, 2); | ||
670 | |||
671 | /** | ||
672 | * @} | ||
673 | */ | ||
674 | |||
675 | |||
676 | /** | ||
677 | * @brief Makes a shallow copy of @a model. | ||
678 | * @param model The model instance. | ||
679 | * @return Copied model. | ||
680 | * | ||
681 | * The returned model will have a copy of the properties of @a model and a | ||
682 | * reference to the children of @a model. | ||
683 | * | ||
684 | * @see eina_model_deep_copy() | ||
685 | * @since 1.2 | ||
686 | */ | ||
687 | EAPI Eina_Model *eina_model_copy(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
688 | /** | ||
689 | * @brief Makes a deep(complete) copy of @a model. | ||
690 | * @param model The model instance. | ||
691 | * @return Copied model. | ||
692 | * | ||
693 | * The returned model will have a copy of the properties of @a model, its | ||
694 | * children will be created by making a deep copy of the children of @a model. | ||
695 | * | ||
696 | * @see eina_model_copy() | ||
697 | * @since 1.2 | ||
698 | */ | ||
699 | EAPI Eina_Model *eina_model_deep_copy(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
700 | |||
701 | /** | ||
702 | * @brief Compares two models. | ||
703 | * @param a The first model to compare. | ||
704 | * @param b The second model to compare. | ||
705 | * @return Greater than zero if @a a > @a b, zero if @a a == @a b and less than | ||
706 | * zero if @a a < @a b | ||
707 | * | ||
708 | * The default comparison checks that the properties of @a a and @a b all have | ||
709 | * the same name and value, and then recursively compares all children. | ||
710 | * | ||
711 | * A model with less properties or children is considered smaller than one with | ||
712 | * more properties. | ||
713 | * | ||
714 | * @since 1.2 | ||
715 | */ | ||
716 | EAPI int eina_model_compare(const Eina_Model *a, const Eina_Model *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2); | ||
717 | |||
718 | /** | ||
719 | * @brief Loads the @a model's data. | ||
720 | * @param model The model instance. | ||
721 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
722 | * | ||
723 | * By convention this means loading data from an external source and populating | ||
724 | * the models properties and children with it. For example in the case of file | ||
725 | * system backed model, this means opening the relevant files and reading the | ||
726 | * data from them(creating the properties and children from it). | ||
727 | * @warning This convention should be followed, but no guarantees of behaviour | ||
728 | * by user defined types can be given. | ||
729 | * | ||
730 | * @note The types provided by Eina_Model don't implement this method. | ||
731 | * @note Calling this function on a model that doesn't implement it returns @c | ||
732 | * EINA_TRUE without any effect on @a model. | ||
733 | * | ||
734 | * @see eina_model_unload() | ||
735 | * @since 1.2 | ||
736 | */ | ||
737 | EAPI Eina_Bool eina_model_load(Eina_Model *model) EINA_ARG_NONNULL(1); | ||
738 | /** | ||
739 | * @brief Unloads the @a model's data. | ||
740 | * @param model The model instance. | ||
741 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
742 | * | ||
743 | * By convention this means releasing data gotten from an external source. For | ||
744 | * example of a database backed model this might mean releasing the iterator for | ||
745 | * the currently loaded data or deleting a temporary table. | ||
746 | * @warning This convention should be followed, but no guarantees of behaviour | ||
747 | * by user defined types can be given. | ||
748 | * | ||
749 | * @note The types provided by Eina_Model don't implement this method. | ||
750 | * @note Calling this function on a model that doesn't implement it returns @c | ||
751 | * EINA_TRUE without any effect on @a model. | ||
752 | * | ||
753 | * @see eina_model_load() | ||
754 | * @since 1.2 | ||
755 | */ | ||
756 | EAPI Eina_Bool eina_model_unload(Eina_Model *model) EINA_ARG_NONNULL(1); | ||
757 | |||
758 | |||
759 | /** | ||
760 | * @defgroup Eina_Model_Properties_Group Data Model Properties | ||
761 | * Properties and their usage with models. | ||
762 | * | ||
763 | * Properties are attributes of model. They have a name and contain a | ||
764 | * data value (@ref Eina_Value_Group). | ||
765 | * | ||
766 | * The actual values and their types, if it is possible to read and | ||
767 | * write them and if new properties can be created or deleted it is up | ||
768 | * to the type. | ||
769 | * | ||
770 | * @{ | ||
771 | */ | ||
772 | /** | ||
773 | * @brief Gets the value of @a model's property named @a name. | ||
774 | * @param[in] model The model from which to get the property. | ||
775 | * @param[in] name The name of the property whose value is wanted. | ||
776 | * @param[out] value A pointer to an Eina_Value to receive the property's value. | ||
777 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
778 | * | ||
779 | * @return EINA_TRUE if @a model has a property named @a name, EINA_FALSE | ||
780 | * otherwise. | ||
781 | * | ||
782 | * @see eina_model_property_set() | ||
783 | * @see eina_model_property_del() | ||
784 | * @since 1.2 | ||
785 | */ | ||
786 | EAPI Eina_Bool eina_model_property_get(const Eina_Model *model, | ||
787 | const char *name, | ||
788 | Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3); | ||
789 | /** | ||
790 | * @brief Sets the value of @a model's property named @a name to @a value. | ||
791 | * @param model The model in which to set the property. | ||
792 | * @param name The name of the property whose value is to set. | ||
793 | * @param value A pointer to a const Eina_Value to containing the property's | ||
794 | * value. | ||
795 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
796 | * | ||
797 | * @see eina_model_property_get() | ||
798 | * @see eina_model_property_del() | ||
799 | * @since 1.2 | ||
800 | */ | ||
801 | EAPI Eina_Bool eina_model_property_set(Eina_Model *model, | ||
802 | const char *name, | ||
803 | const Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3); | ||
804 | /** | ||
805 | * @brief Deletes @a model's property named @a name. | ||
806 | * @param model The model from which to delete the property. | ||
807 | * @param name The name of the property to delete. | ||
808 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
809 | * | ||
810 | * @see eina_model_property_set() | ||
811 | * @see eina_model_property_get() | ||
812 | * @since 1.2 | ||
813 | */ | ||
814 | EAPI Eina_Bool eina_model_property_del(Eina_Model *model, | ||
815 | const char *name) EINA_ARG_NONNULL(1, 2); | ||
816 | |||
817 | /** | ||
818 | * @brief Gets a list of the names of every property of @a model. | ||
819 | * @param model The model instance. | ||
820 | * @return #Eina_List of names. | ||
821 | * | ||
822 | * @note The returned list should be freed with @c | ||
823 | * eina_model_properties_names_list_free(). | ||
824 | * | ||
825 | * @see eina_model_properties_names_list_free() | ||
826 | * @see eina_model_property_get() | ||
827 | * @since 1.2 | ||
828 | */ | ||
829 | EAPI Eina_List *eina_model_properties_names_list_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
830 | /** | ||
831 | * @brief Frees a list of names of properties gotten with @c | ||
832 | * eina_model_properties_names_list_get(). | ||
833 | * @param list The list to free. | ||
834 | * | ||
835 | * @warning Behavior is undefined if called on a list not gotten from @c | ||
836 | * eina_model_properties_names_list_get(). | ||
837 | * | ||
838 | * @see eina_model_properties_names_list_get() | ||
839 | * @see eina_model_property_get() | ||
840 | * @since 1.2 | ||
841 | */ | ||
842 | EAPI void eina_model_properties_names_list_free(Eina_List *list); | ||
843 | |||
844 | /** | ||
845 | * @} | ||
846 | */ | ||
847 | |||
848 | /** | ||
849 | * @defgroup Eina_Model_Children_Group Data Model Children | ||
850 | * Children and their usage with models. | ||
851 | * | ||
852 | * Children are other model instances that are kept sequentially in | ||
853 | * the model. They are accessed by their integer index within the | ||
854 | * model. Their index may change if child are inserted or deleted | ||
855 | * before them, as in an array. | ||
856 | * | ||
857 | * @{ | ||
858 | */ | ||
859 | |||
860 | /** | ||
861 | * @brief Returns the number of child models in @a model. | ||
862 | * @param model The model instance. | ||
863 | * @return Number of children in @a model. | ||
864 | * | ||
865 | * @see eina_model_child_append() | ||
866 | * @see eina_model_child_get() | ||
867 | * @see eina_model_child_del() | ||
868 | * @since 1.2 | ||
869 | */ | ||
870 | EAPI int eina_model_child_count(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
871 | |||
872 | /** | ||
873 | * @brief Get the child at a given position from a model. | ||
874 | * @param model the model instance. | ||
875 | * @param position index of child to get. | ||
876 | * @return child instance with reference @b increased, or @c NULL on error. | ||
877 | * | ||
878 | * The given @a position must be valid, otherwise it may fail and | ||
879 | * return @c NULL, one should check for a valid position with | ||
880 | * eina_model_child_count(). | ||
881 | * | ||
882 | * @warning The returned model has its reference increased, you must release it | ||
883 | * with eina_model_unref(). This convention is imposed to avoid the | ||
884 | * object being removed before the caller function has time to use it. | ||
885 | */ | ||
886 | EAPI Eina_Model *eina_model_child_get(const Eina_Model *model, | ||
887 | unsigned int position) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
888 | |||
889 | /** | ||
890 | * @brief Set the child at a given position from a model. | ||
891 | * @param model the model instance. | ||
892 | * @param position index of child to set. | ||
893 | * @param child the child to use at given position. | ||
894 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
895 | * | ||
896 | * The given @a position must be valid, otherwise it may fail and | ||
897 | * return #EINA_FALSE, one should check for a valid position with | ||
898 | * eina_model_child_count(). | ||
899 | * | ||
900 | * The existing child is replaced. Its reference will be decreased | ||
901 | * automatically. To insert a new item instead of replacing, use | ||
902 | * eina_model_child_insert_at() or eina_model_child_append(). | ||
903 | * | ||
904 | * The given model will be adopted by @a model, that is, the @a child | ||
905 | * will have its reference increased if this call succeeds. | ||
906 | * | ||
907 | * @see eina_model_child_append() | ||
908 | * @see eina_model_child_insert_at() | ||
909 | * @since 1.2 | ||
910 | */ | ||
911 | EAPI Eina_Bool eina_model_child_set(Eina_Model *model, | ||
912 | unsigned int position, | ||
913 | Eina_Model *child) EINA_ARG_NONNULL(1, 3); | ||
914 | |||
915 | /** | ||
916 | * @brief Deletes the child model in @a position-th of @a model. | ||
917 | * @param model The model instance. | ||
918 | * @param position The position of the child to be deleted. | ||
919 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
920 | * | ||
921 | * @warning This decrements the reference count of the child being deleted, | ||
922 | * which may, or not, cause it to be deconstructed and freed. | ||
923 | * | ||
924 | * @see eina_model_child_append() | ||
925 | * @see eina_model_child_get() | ||
926 | * @since 1.2 | ||
927 | */ | ||
928 | EAPI Eina_Bool eina_model_child_del(Eina_Model *model, | ||
929 | unsigned int position) EINA_ARG_NONNULL(1); | ||
930 | |||
931 | /** | ||
932 | * @brief Insert @a child in the @a position-th of the list of children of @a | ||
933 | * model. | ||
934 | * @param model The model instance. | ||
935 | * @param position Position in which to insert child. | ||
936 | * @param child The child to be inserted. | ||
937 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
938 | * | ||
939 | * @warning This increments the reference count of the child being inserted, if | ||
940 | * it will no longer be used by the inserting code it should call | ||
941 | * eina_model_unref() on it. | ||
942 | * | ||
943 | * @see eina_model_child_append() | ||
944 | * @see eina_model_child_set() | ||
945 | * @since 1.2 | ||
946 | */ | ||
947 | EAPI Eina_Bool eina_model_child_insert_at(Eina_Model *model, | ||
948 | unsigned int position, | ||
949 | Eina_Model *child) EINA_ARG_NONNULL(1, 3); | ||
950 | |||
951 | /** | ||
952 | * @brief Appends @a child in @a model. | ||
953 | * @param model The model instance. | ||
954 | * @param child The child to be appended. | ||
955 | * @return The position of the added child, or -1 on failure. | ||
956 | * | ||
957 | * @warning This increments the reference count of the child being inserted, if | ||
958 | * it will no longer be used by the inserting code it should call | ||
959 | * eina_model_unref() on it. | ||
960 | * | ||
961 | * @see eina_model_child_insert_at() | ||
962 | * @see eina_model_child_set() | ||
963 | * @since 1.2 | ||
964 | */ | ||
965 | EAPI int eina_model_child_append(Eina_Model *model, | ||
966 | Eina_Model *child) EINA_ARG_NONNULL(1, 2); | ||
967 | |||
968 | /** | ||
969 | * @brief Returns the position of @a other amongst the children of @a model. | ||
970 | * @param model The parent model whose children will be searched. | ||
971 | * @param start_position The first children to be compared with @a other. | ||
972 | * @param other The model whose position is desired. | ||
973 | * @return The position of the searched for child, or -1 if not found. | ||
974 | * | ||
975 | * @since 1.2 | ||
976 | */ | ||
977 | EAPI int eina_model_child_find(const Eina_Model *model, | ||
978 | unsigned int start_position, | ||
979 | const Eina_Model *other) EINA_ARG_NONNULL(1, 3) EINA_WARN_UNUSED_RESULT; | ||
980 | |||
981 | /** | ||
982 | * @brief Returns the position of a child of @a model that mathes the criteria. | ||
983 | * @param model The model whose children will be searched. | ||
984 | * @param start_position The position of the first child to be checked. | ||
985 | * @param match The function used to check if a child matches the criteria. | ||
986 | * @param data Data given the to the @a match function. | ||
987 | * @return The position of the first child to match the criteria or -1 if no | ||
988 | * child matches it. | ||
989 | * | ||
990 | * Returns the position of the first(from @a start_position) child of @a model | ||
991 | * to which @a match returns EINA_TRUE. | ||
992 | * | ||
993 | * @since 1.2 | ||
994 | */ | ||
995 | EAPI int eina_model_child_criteria_match(const Eina_Model *model, | ||
996 | unsigned int start_position, | ||
997 | Eina_Each_Cb match, | ||
998 | const void *data) EINA_ARG_NONNULL(1, 3) EINA_WARN_UNUSED_RESULT; | ||
999 | |||
1000 | /** | ||
1001 | * @brief Sorts the children of @a model according to @a compare. | ||
1002 | * @param model The model instance. | ||
1003 | * @param compare The function to be used in the comparison. | ||
1004 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1005 | * | ||
1006 | * The @a compare function receives to const pointer to eina models(const | ||
1007 | * *Eina_Model). | ||
1008 | * | ||
1009 | * @since 1.2 | ||
1010 | */ | ||
1011 | EAPI Eina_Bool eina_model_child_sort(Eina_Model *model, | ||
1012 | Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2); | ||
1013 | |||
1014 | /** | ||
1015 | * @} | ||
1016 | */ | ||
1017 | |||
1018 | /** | ||
1019 | * @defgroup Eina_Model_Iterators_Group Data Model Iterators | ||
1020 | * Iterators and their usage with models. | ||
1021 | * | ||
1022 | * One of the most common tasks of models is to iterate over their | ||
1023 | * children, either forwards or backwards, filtering by some criteria | ||
1024 | * or a different ordering function. | ||
1025 | * | ||
1026 | * @{ | ||
1027 | */ | ||
1028 | |||
1029 | /** | ||
1030 | * @brief create an iterator that outputs a child model on each iteration. | ||
1031 | * @param model the model instance. | ||
1032 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1033 | * | ||
1034 | * @code | ||
1035 | * Eina_Model *child; | ||
1036 | * Eina_Iterator *it = eina_model_child_iterator_get(model); | ||
1037 | * EINA_ITERATOR_FOREACH(it, child) | ||
1038 | * { | ||
1039 | * use_child(child); | ||
1040 | * eina_model_unref(child); | ||
1041 | * } | ||
1042 | * eina_iterator_free(it); | ||
1043 | * @endcode | ||
1044 | * This code shows how to use iterators to do something (in this example call | ||
1045 | * use_child()) on every child element. | ||
1046 | * | ||
1047 | * @warning Each iteration(call to eina_iterator_next()) gives a child model | ||
1048 | * with reference @b increased! You must call eina_model_unref() after you're | ||
1049 | * done with it. | ||
1050 | * | ||
1051 | * @see eina_model_child_slice_iterator_get() | ||
1052 | * @see eina_model_child_reversed_iterator_get() | ||
1053 | * @see eina_model_child_sorted_iterator_get() | ||
1054 | * @see eina_model_child_filtered_iterator_get() | ||
1055 | * @since 1.2 | ||
1056 | */ | ||
1057 | EAPI Eina_Iterator *eina_model_child_iterator_get(Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
1058 | /** | ||
1059 | * @brief Gets an iterator to a slice of @a model's children. | ||
1060 | * @param model The model whose children to iterate over. | ||
1061 | * @param start The first child included in the iterator. | ||
1062 | * @param count The number of children included in the iterator. | ||
1063 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1064 | * | ||
1065 | * @warning Each iteration(call to eina_iterator_next()) gives a child model | ||
1066 | * with reference @b increased! You must call eina_model_unref() after you're | ||
1067 | * done with it. | ||
1068 | * | ||
1069 | * @see eina_model_child_iterator_get() | ||
1070 | * @see eina_model_child_slice_reversed_iterator_get() | ||
1071 | * @since 1.2 | ||
1072 | */ | ||
1073 | EAPI Eina_Iterator *eina_model_child_slice_iterator_get(Eina_Model *model, | ||
1074 | unsigned int start, | ||
1075 | unsigned int count) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
1076 | |||
1077 | /** | ||
1078 | * @brief create an iterator that outputs a child model in reversed order. | ||
1079 | * @param model the model instance. | ||
1080 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1081 | * | ||
1082 | * Each iteration output a child model with reference @b increased! | ||
1083 | * You must call eina_model_unref() after you're done with it. | ||
1084 | * | ||
1085 | * The order is reversed, that is, the last element is outputted first. | ||
1086 | * | ||
1087 | * @code | ||
1088 | * Eina_Model *child; | ||
1089 | * Eina_Iterator *it = eina_model_child_reversed_iterator_get(model); | ||
1090 | * EINA_ITERATOR_FOREACH(it, child) | ||
1091 | * { | ||
1092 | * use_child(child); | ||
1093 | * eina_model_unref(child); | ||
1094 | * } | ||
1095 | * eina_iterator_free(it); | ||
1096 | * @endcode | ||
1097 | * This code shows how to use iterators to do something (in this example call | ||
1098 | * use_child()) on every child element starting from last to first. | ||
1099 | * | ||
1100 | * @warning Each iteration(call to eina_iterator_next()) gives a child model | ||
1101 | * with reference @b increased! You must call eina_model_unref() after you're | ||
1102 | * done with it. | ||
1103 | * | ||
1104 | * @see eina_model_child_slice_iterator_get() | ||
1105 | * @see eina_model_child_reversed_iterator_get() | ||
1106 | * @see eina_model_child_sorted_iterator_get() | ||
1107 | * @see eina_model_child_filtered_iterator_get() | ||
1108 | * @since 1.2 | ||
1109 | */ | ||
1110 | EAPI Eina_Iterator *eina_model_child_reversed_iterator_get(Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
1111 | |||
1112 | /** | ||
1113 | * @brief Gets a reversed iterator to a slice of @a model's children. | ||
1114 | * @param model The model whose children to iterate over. | ||
1115 | * @param start The first child included in the iterator. | ||
1116 | * @param count The number of children included in the iterator. | ||
1117 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1118 | * | ||
1119 | * @warning Each iteration(call to eina_iterator_next()) gives a child model | ||
1120 | * with reference @b increased! You must call eina_model_unref() after you're | ||
1121 | * done with it. | ||
1122 | * | ||
1123 | * @see eina_model_child_reversed_iterator_get() | ||
1124 | * @see eina_model_child_slice_iterator_get() | ||
1125 | * @since 1.2 | ||
1126 | */ | ||
1127 | EAPI Eina_Iterator *eina_model_child_slice_reversed_iterator_get(Eina_Model *model, | ||
1128 | unsigned int start, | ||
1129 | unsigned int count) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; | ||
1130 | |||
1131 | /** | ||
1132 | * @brief create an iterator that outputs a child model using sort criteria. | ||
1133 | * @param model the model instance. | ||
1134 | * @param compare compare function to use as sort criteria. | ||
1135 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1136 | * | ||
1137 | * Each iteration output a child model with reference @b increased! | ||
1138 | * You must call eina_model_unref() after you're done with it. | ||
1139 | * | ||
1140 | * The sort will not affect the main object @a model, it's just a view | ||
1141 | * of it. | ||
1142 | * | ||
1143 | * @code | ||
1144 | * Eina_Model *child; | ||
1145 | * Eina_Iterator *it = eina_model_child_sorted_iterator_get(model, EINA_COMPARE_CB(eina_model_compare)); | ||
1146 | * EINA_ITERATOR_FOREACH(it, child) | ||
1147 | * { | ||
1148 | * use_child(child); | ||
1149 | * eina_model_unref(child); | ||
1150 | * } | ||
1151 | * eina_iterator_free(it); | ||
1152 | * @endcode | ||
1153 | * This bit of code shows how to use iterators to do something (in this example | ||
1154 | * call use_child()) on every child element in the order given by the @a compare | ||
1155 | * function. | ||
1156 | * | ||
1157 | * @warning Each iteration(call to eina_iterator_next()) gives a child model | ||
1158 | * with reference @b increased! You must call eina_model_unref() after you're | ||
1159 | * done with it. | ||
1160 | * | ||
1161 | * @see eina_model_child_slice_iterator_get() | ||
1162 | * @see eina_model_child_reversed_iterator_get() | ||
1163 | * @see eina_model_child_sorted_iterator_get() | ||
1164 | * @see eina_model_child_filtered_iterator_get() | ||
1165 | * @since 1.2 | ||
1166 | */ | ||
1167 | EAPI Eina_Iterator *eina_model_child_sorted_iterator_get(Eina_Model *model, | ||
1168 | Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; | ||
1169 | |||
1170 | /** | ||
1171 | * @brief Returns a sorted iterator to a slice of @a model's children. | ||
1172 | * @param model The model whose children to iterate over. | ||
1173 | * @param start The position(before sorting) of the first child included in | ||
1174 | * the iterator. | ||
1175 | * @param count The number of children included in the iterator. | ||
1176 | * @param compare The function used to sort the children. | ||
1177 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1178 | * | ||
1179 | * @warning Each iteration(call to eina_iterator_next()) gives a child model | ||
1180 | * with reference @b increased! You must call eina_model_unref() after you're | ||
1181 | * done with it. | ||
1182 | * | ||
1183 | * @see eina_model_child_slice_iterator_get() | ||
1184 | * @see eina_model_child_reversed_iterator_get() | ||
1185 | * @see eina_model_child_sorted_iterator_get() | ||
1186 | * @see eina_model_child_filtered_iterator_get() | ||
1187 | * @since 1.2 | ||
1188 | */ | ||
1189 | EAPI Eina_Iterator *eina_model_child_slice_sorted_iterator_get(Eina_Model *model, | ||
1190 | unsigned int start, | ||
1191 | unsigned int count, | ||
1192 | Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 4) EINA_WARN_UNUSED_RESULT; | ||
1193 | |||
1194 | /** | ||
1195 | * @brief create an iterator that indexes of children that matches. | ||
1196 | * @param model the model instance. | ||
1197 | * @param match function to select children. | ||
1198 | * @param data extra context given to @a match function. | ||
1199 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1200 | * | ||
1201 | * Unlike other iterators, each iteration output an integer index! | ||
1202 | * This is useful if you want to highlight the matching model | ||
1203 | * somewhere else. | ||
1204 | * | ||
1205 | * If no child element matches a valid, and empty, iterator will be returned. | ||
1206 | * Indexes returned by this iterator are guaranteed to exists. | ||
1207 | * | ||
1208 | * @code | ||
1209 | * unsigned int idx; | ||
1210 | * Eina_Iterator *it = eina_model_child_filtered_iterator_get(model, filter, ctx); | ||
1211 | * EINA_ITERATOR_FOREACH(it, idx) | ||
1212 | * { | ||
1213 | * Eina_Model *child = eina_model_child_get(model, idx); | ||
1214 | * printf("matches at %u %p\n", idx, child); | ||
1215 | * eina_model_unref(child); | ||
1216 | * } | ||
1217 | * eina_iterator_free(it); | ||
1218 | * @endcode | ||
1219 | * This bit of code shows how to use iterators to do something (in this example | ||
1220 | * print the address) on child elements that match the criteria given of @a match. | ||
1221 | * | ||
1222 | * @see eina_model_child_slice_iterator_get() | ||
1223 | * @see eina_model_child_reversed_iterator_get() | ||
1224 | * @see eina_model_child_sorted_iterator_get() | ||
1225 | * @see eina_model_child_filtered_iterator_get() | ||
1226 | * @since 1.2 | ||
1227 | */ | ||
1228 | EAPI Eina_Iterator *eina_model_child_filtered_iterator_get(Eina_Model *model, | ||
1229 | Eina_Each_Cb match, | ||
1230 | const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; | ||
1231 | |||
1232 | /** | ||
1233 | * @brief Returns a filtered slice of the @a model's children. | ||
1234 | * @param model The model whose children to iterate over. | ||
1235 | * @param start The position of the first child to be tested for inclusion in | ||
1236 | * the iterator. | ||
1237 | * @param count The number of children to be tested for inclusion in the | ||
1238 | * iterator. | ||
1239 | * @param match The function used to decide which children will be included in | ||
1240 | * the iterator. | ||
1241 | * @param data Data passed to the @a match function. | ||
1242 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1243 | * | ||
1244 | * @note Only children for whom @a match returns EINA_TRUE will be included in | ||
1245 | * the iterator. | ||
1246 | * | ||
1247 | * @note Each iteration(call to eina_iterator_next()) gives an integer index! | ||
1248 | * | ||
1249 | * @warning The iterator may have less than @a count children, but not more. | ||
1250 | * | ||
1251 | * @see eina_model_child_slice_iterator_get() | ||
1252 | * @see eina_model_child_reversed_iterator_get() | ||
1253 | * @see eina_model_child_sorted_iterator_get() | ||
1254 | * @see eina_model_child_filtered_iterator_get() | ||
1255 | * @since 1.2 | ||
1256 | */ | ||
1257 | EAPI Eina_Iterator *eina_model_child_slice_filtered_iterator_get(Eina_Model *model, | ||
1258 | unsigned int start, | ||
1259 | unsigned int count, | ||
1260 | Eina_Each_Cb match, | ||
1261 | const void *data) EINA_ARG_NONNULL(1, 4) EINA_WARN_UNUSED_RESULT; | ||
1262 | |||
1263 | |||
1264 | /** | ||
1265 | * @} | ||
1266 | */ | ||
1267 | |||
1268 | /** | ||
1269 | * @brief Convert model to string. | ||
1270 | * @param model the model instance. | ||
1271 | * @return Newly allocated memory or @c NULL on failure. | ||
1272 | * | ||
1273 | * The default format of the ouput is: | ||
1274 | * Type_Name({Property_Name: Property_Value, ...}, [Child0, Child1, ...]) | ||
1275 | * | ||
1276 | * Where: | ||
1277 | * @li Type_Name: eina_model_type_name_get(eina_model_type_get(model)) | ||
1278 | * @li Properties are sorted alphabetically. | ||
1279 | * @li Property_Value is created using eina_value_to_string(). | ||
1280 | * @li Children are converted using eina_model_to_string() | ||
1281 | * | ||
1282 | * @since 1.2 | ||
1283 | */ | ||
1284 | EAPI char *eina_model_to_string(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
1285 | |||
1286 | /** | ||
1287 | * @defgroup Eina_Model_Type_Group Data Model Type management | ||
1288 | * | ||
1289 | * Functions and structures related to implementing new types or | ||
1290 | * extending existing ones. | ||
1291 | * | ||
1292 | * All eina_model_type functions takes an Eina_Model_Type or | ||
1293 | * Eina_Model_Interface as parameter and may be used to validate or | ||
1294 | * query information about them. | ||
1295 | * | ||
1296 | * The functions with prefix eina_model_type that matches eina_model | ||
1297 | * counterparts, such as eina_model_type_compare() and | ||
1298 | * eina_model_compare() are used as "super", that is, calls the @c | ||
1299 | * compare() method of the given type (or its parent) instead of the | ||
1300 | * most specific type of provided Eina_Model. | ||
1301 | * | ||
1302 | * Examples: | ||
1303 | * @li @ref eina_model_02_example_page contains an easy to follow | ||
1304 | * example that demonstrates several of the important features of | ||
1305 | * eina_model, uses #EINA_MODEL_TYPE_GENERIC. | ||
1306 | * @li @ref eina_model_03_example_page walk-through example on how to | ||
1307 | * inherit types, a suggestion of eina_model_load() usage and uses | ||
1308 | * #EINA_MODEL_TYPE_STRUCT. | ||
1309 | * | ||
1310 | * @{ | ||
1311 | */ | ||
1312 | |||
1313 | /** | ||
1314 | * @def EINA_MODEL_TYPE_VERSION | ||
1315 | * Current API version, used to validate #_Eina_Model_Type. | ||
1316 | */ | ||
1317 | #define EINA_MODEL_TYPE_VERSION (1) | ||
1318 | |||
1319 | /** | ||
1320 | * @struct _Eina_Model_Type | ||
1321 | * API to access models. | ||
1322 | * | ||
1323 | * Each type of the hierarchy and each interface will get its own | ||
1324 | * private data of size @c private_size (defined at each subtype or | ||
1325 | * interface), this can be retrieved with | ||
1326 | * eina_model_type_private_data_get() and | ||
1327 | * eina_model_interface_private_data_get(). | ||
1328 | * | ||
1329 | * Private are created @b automatically and should be setup with @c | ||
1330 | * setup and flushed with @c flush. All types (or interfaces) | ||
1331 | * functions that exist are called! Don't call your parent's @c setup or | ||
1332 | * @c flush! The setup is done from parent to child. Flush is done from | ||
1333 | * child to parent. | ||
1334 | * | ||
1335 | * After memory setup was done, @c constructor of the toplevel type | ||
1336 | * defining it is called. If desired it may call parent's constructor | ||
1337 | * in whatever order is desired. This may be used to create | ||
1338 | * properties, children and may use parent's data if needed. The only | ||
1339 | * constructor caled is that of the most specialized type, if interface | ||
1340 | * constructors should be called, do them in the desired order from the type | ||
1341 | * constructor. | ||
1342 | * | ||
1343 | * When the model is deleted, explicitly with eina_model_del() or | ||
1344 | * implicitly with eina_model_unref() on the last reference, the @c | ||
1345 | * destructor is called. It must release references to other | ||
1346 | * models. When the last reference is dropped, every @c flush is | ||
1347 | * called from child to parent, then memory is freed. The only | ||
1348 | * destructor caled is that of the most specialized type, if interface | ||
1349 | * destructors should be called, do them in the desired order from the type | ||
1350 | * destructor. | ||
1351 | * | ||
1352 | * | ||
1353 | * @note The methods @c setup and @c flush should exist if there is | ||
1354 | * private data, otherwise memory may be uninitialized or leaks. | ||
1355 | * @note It is recommended that @c constructor and @c destructor exist | ||
1356 | * to correctly do their roles and call parents in the correct | ||
1357 | * order. Whenever they do not exist, their parent pointer is | ||
1358 | * called. | ||
1359 | * @note a runtime check will enforce just types with ABI version | ||
1360 | * #EINA_MODEL_TYPE_VERSION are used by comparing with the @c version | ||
1361 | * member. | ||
1362 | * | ||
1363 | * @since 1.2 | ||
1364 | */ | ||
1365 | struct _Eina_Model_Type | ||
1366 | { | ||
1367 | unsigned int version; /**< must be #EINA_MODEL_TYPE_VERSION */ | ||
1368 | unsigned int private_size; /**< used to allocate type private data */ | ||
1369 | unsigned int type_size; /**< used to know sizeof(Eina_Model_Type) or subtypes (which may be bigger, by including Eina_Model_Type as a header */ | ||
1370 | const char *name; /**< name for debug and introspection */ | ||
1371 | const Eina_Model_Type *parent; /**< parent type, must be EINA_MODEL_TYPE_BASE or a child of */ | ||
1372 | const Eina_Model_Interface **interfaces; /**< null terminated array of interfaces */ | ||
1373 | const Eina_Model_Event_Description *events; /**< null terminated array of events */ | ||
1374 | Eina_Bool (*setup)(Eina_Model *model); /**< setup type private data, do @b not call parent type setup! */ | ||
1375 | Eina_Bool (*flush)(Eina_Model *model); /**< flush type private data, do @b not call parent type flush! */ | ||
1376 | Eina_Bool (*constructor)(Eina_Model *model); /**< construct type instance, setup was already called. Should call parent's or interfaces' constructor if needed */ | ||
1377 | Eina_Bool (*destructor)(Eina_Model *model); /**< destruct type instance, flush will be called after it. Should call parent's or interfaces' destructor if needed. Release reference to other models here. */ | ||
1378 | Eina_Bool (*copy)(const Eina_Model *src, Eina_Model *dst); /**< copy type private data, do @b not call parent type copy! */ | ||
1379 | Eina_Bool (*deep_copy)(const Eina_Model *src, Eina_Model *dst); /**< deep copy type private data, do @b not call parent type deep copy! */ | ||
1380 | Eina_Bool (*compare)(const Eina_Model *a, const Eina_Model *b, int *cmp); | ||
1381 | Eina_Bool (*load)(Eina_Model *model); | ||
1382 | Eina_Bool (*unload)(Eina_Model *model); | ||
1383 | Eina_Bool (*property_get)(const Eina_Model *model, const char *name, Eina_Value *value); | ||
1384 | Eina_Bool (*property_set)(Eina_Model *model, const char *name, const Eina_Value *value); | ||
1385 | Eina_Bool (*property_del)(Eina_Model *model, const char *name); | ||
1386 | Eina_List *(*properties_names_list_get)(const Eina_Model *model); /**< list of stringshare */ | ||
1387 | int (*child_count)(const Eina_Model *model); | ||
1388 | Eina_Model *(*child_get)(const Eina_Model *model, unsigned int position); | ||
1389 | Eina_Bool (*child_set)(Eina_Model *model, unsigned int position, Eina_Model *child); | ||
1390 | Eina_Bool (*child_del)(Eina_Model *model, unsigned int position); | ||
1391 | Eina_Bool (*child_insert_at)(Eina_Model *model, unsigned int position, Eina_Model *child); | ||
1392 | int (*child_find)(const Eina_Model *model, unsigned int start_position, const Eina_Model *other); | ||
1393 | int (*child_criteria_match)(const Eina_Model *model, unsigned int start_position, Eina_Each_Cb match, const void *data); | ||
1394 | void (*child_sort)(Eina_Model *model, Eina_Compare_Cb compare); | ||
1395 | Eina_Iterator *(*child_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count); | ||
1396 | Eina_Iterator *(*child_reversed_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count); | ||
1397 | Eina_Iterator *(*child_sorted_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count, Eina_Compare_Cb compare); | ||
1398 | Eina_Iterator *(*child_filtered_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count, Eina_Each_Cb match, const void *data); | ||
1399 | char *(*to_string)(const Eina_Model *model); /**< used to represent model as string, usually for debug purposes or user convenience */ | ||
1400 | void *__extension_ptr0; /**< not to be used */ | ||
1401 | void *__extension_ptr1; /**< not to be used */ | ||
1402 | void *__extension_ptr2; /**< not to be used */ | ||
1403 | void *__extension_ptr3; /**< not to be used */ | ||
1404 | }; | ||
1405 | |||
1406 | #define EINA_MODEL_TYPE_INIT(name, type, private_type, parent, interfaces, events) \ | ||
1407 | {EINA_MODEL_TYPE_VERSION, \ | ||
1408 | sizeof(private_type), \ | ||
1409 | sizeof(type), \ | ||
1410 | name, \ | ||
1411 | parent, \ | ||
1412 | interfaces, \ | ||
1413 | events, \ | ||
1414 | NULL, \ | ||
1415 | NULL, \ | ||
1416 | NULL, \ | ||
1417 | NULL, \ | ||
1418 | NULL, \ | ||
1419 | NULL, \ | ||
1420 | NULL, \ | ||
1421 | NULL, \ | ||
1422 | NULL, \ | ||
1423 | NULL, \ | ||
1424 | NULL, \ | ||
1425 | NULL, \ | ||
1426 | NULL, \ | ||
1427 | NULL, \ | ||
1428 | NULL, \ | ||
1429 | NULL, \ | ||
1430 | NULL, \ | ||
1431 | NULL, \ | ||
1432 | NULL, \ | ||
1433 | NULL, \ | ||
1434 | NULL, \ | ||
1435 | NULL, \ | ||
1436 | NULL, \ | ||
1437 | NULL, \ | ||
1438 | NULL, \ | ||
1439 | NULL, \ | ||
1440 | NULL, \ | ||
1441 | NULL, \ | ||
1442 | NULL, \ | ||
1443 | NULL \ | ||
1444 | } | ||
1445 | |||
1446 | #define EINA_MODEL_TYPE_INIT_NOPRIVATE(name, type, parent, interfaces, events) \ | ||
1447 | {EINA_MODEL_TYPE_VERSION, \ | ||
1448 | 0, \ | ||
1449 | sizeof(type), \ | ||
1450 | name, \ | ||
1451 | parent, \ | ||
1452 | interfaces, \ | ||
1453 | events, \ | ||
1454 | NULL, \ | ||
1455 | NULL, \ | ||
1456 | NULL, \ | ||
1457 | NULL, \ | ||
1458 | NULL, \ | ||
1459 | NULL, \ | ||
1460 | NULL, \ | ||
1461 | NULL, \ | ||
1462 | NULL, \ | ||
1463 | NULL, \ | ||
1464 | NULL, \ | ||
1465 | NULL, \ | ||
1466 | NULL, \ | ||
1467 | NULL, \ | ||
1468 | NULL, \ | ||
1469 | NULL, \ | ||
1470 | NULL, \ | ||
1471 | NULL, \ | ||
1472 | NULL, \ | ||
1473 | NULL, \ | ||
1474 | NULL, \ | ||
1475 | NULL, \ | ||
1476 | NULL, \ | ||
1477 | NULL, \ | ||
1478 | NULL, \ | ||
1479 | NULL, \ | ||
1480 | NULL, \ | ||
1481 | NULL, \ | ||
1482 | NULL, \ | ||
1483 | NULL \ | ||
1484 | } | ||
1485 | |||
1486 | #define EINA_MODEL_TYPE_INIT_NULL \ | ||
1487 | {0, \ | ||
1488 | 0, \ | ||
1489 | 0, \ | ||
1490 | NULL, \ | ||
1491 | NULL, \ | ||
1492 | NULL, \ | ||
1493 | NULL, \ | ||
1494 | NULL, \ | ||
1495 | NULL, \ | ||
1496 | NULL, \ | ||
1497 | NULL, \ | ||
1498 | NULL, \ | ||
1499 | NULL, \ | ||
1500 | NULL, \ | ||
1501 | NULL, \ | ||
1502 | NULL, \ | ||
1503 | NULL, \ | ||
1504 | NULL, \ | ||
1505 | NULL, \ | ||
1506 | NULL, \ | ||
1507 | NULL, \ | ||
1508 | NULL, \ | ||
1509 | NULL, \ | ||
1510 | NULL, \ | ||
1511 | NULL, \ | ||
1512 | NULL, \ | ||
1513 | NULL, \ | ||
1514 | NULL, \ | ||
1515 | NULL, \ | ||
1516 | NULL, \ | ||
1517 | NULL, \ | ||
1518 | NULL, \ | ||
1519 | NULL, \ | ||
1520 | NULL, \ | ||
1521 | NULL, \ | ||
1522 | NULL, \ | ||
1523 | NULL \ | ||
1524 | } | ||
1525 | |||
1526 | /** | ||
1527 | * @brief Calls the constructor of @a type for @a model. | ||
1528 | * @param type The type whose constructor will be called. | ||
1529 | * @param model The model instance. | ||
1530 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1531 | * | ||
1532 | * This should be used to call the parent's type constructor, something like: | ||
1533 | * @code | ||
1534 | * static Eina_Bool my_type_constructor(Eina_Model *m) | ||
1535 | * { | ||
1536 | * // call parents constructor: | ||
1537 | * if (!eina_model_type_constructor(MY_TYPE->parent, m)) | ||
1538 | * return EINA_FALSE; | ||
1539 | * // do my stuff | ||
1540 | * return EINA_TRUE; | ||
1541 | * } | ||
1542 | * @endcode | ||
1543 | * @note You should only do your type's initialization after the parent type has | ||
1544 | * done his own(this is as to ensure you can call on your parent's methods). | ||
1545 | * | ||
1546 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1547 | * returns EINA_FALSE. | ||
1548 | * | ||
1549 | * @see eina_model_new() | ||
1550 | * @see _Eina_Model_Type | ||
1551 | * @since 1.2 | ||
1552 | */ | ||
1553 | EAPI Eina_Bool eina_model_type_constructor(const Eina_Model_Type *type, | ||
1554 | Eina_Model *model) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; | ||
1555 | /** | ||
1556 | * @brief Calls the destructor of @a type for @a model. | ||
1557 | * @param type The type whose destructor will be called. | ||
1558 | * @param model The model instance. | ||
1559 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1560 | * | ||
1561 | * This should be used to call the parent's type destructor, something like: | ||
1562 | * @code | ||
1563 | * static Eina_Bool my_type_destructor(Eina_Model *m) | ||
1564 | * { | ||
1565 | * // do my stuff | ||
1566 | * // call parents destructor: | ||
1567 | * if (!eina_model_type_destructor(MY_TYPE->parent, m)) | ||
1568 | * return EINA_FALSE; | ||
1569 | * return EINA_TRUE; | ||
1570 | * } | ||
1571 | * @endcode | ||
1572 | * @note It's considered good practice to free your type's resources before | ||
1573 | * calling the parent's destructor. | ||
1574 | * | ||
1575 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1576 | * returns EINA_FALSE. | ||
1577 | * | ||
1578 | * @see eina_model_del() | ||
1579 | * @see _Eina_Model_Type | ||
1580 | * @since 1.2 | ||
1581 | */ | ||
1582 | EAPI Eina_Bool eina_model_type_destructor(const Eina_Model_Type *type, | ||
1583 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
1584 | /** | ||
1585 | * @brief Calls the copy method of @a type for @a model. | ||
1586 | * @param type The type whose copy method will be called. | ||
1587 | * @param src Pointer to the model to be copied. | ||
1588 | * @param dst Pointer to where copy will be put. | ||
1589 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1590 | * | ||
1591 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1592 | * returns EINA_FALSE. | ||
1593 | * | ||
1594 | * @see eina_model_copy() | ||
1595 | * @see _Eina_Model_Type | ||
1596 | * @since 1.2 | ||
1597 | */ | ||
1598 | EAPI Eina_Bool eina_model_type_copy(const Eina_Model_Type *type, | ||
1599 | const Eina_Model *src, | ||
1600 | Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3); | ||
1601 | /** | ||
1602 | * @brief Calls the deep copy method of @a type for @a model. | ||
1603 | * @param type The type whose copy method will be called. | ||
1604 | * @param src Pointer to the model to be copied. | ||
1605 | * @param dst Pointer to where copy will be put. | ||
1606 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1607 | * | ||
1608 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1609 | * returns EINA_FALSE. | ||
1610 | * | ||
1611 | * @see eina_model_deep_copy() | ||
1612 | * @see _Eina_Model_Type | ||
1613 | * @since 1.2 | ||
1614 | */ | ||
1615 | EAPI Eina_Bool eina_model_type_deep_copy(const Eina_Model_Type *type, | ||
1616 | const Eina_Model *src, | ||
1617 | Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3); | ||
1618 | /** | ||
1619 | * @brief Calls the compare method of @a type for @a model. | ||
1620 | * @param[in] type The type whose compare method will be called. | ||
1621 | * @param[in] a Pointer to the first model to be compared. | ||
1622 | * @param[in] b Pointer to the second model to be compared. | ||
1623 | * @param[out] cmp The value of the comparison, 1 if @a b is greater than @a a, | ||
1624 | * -1 if @a b is smaller than @a a, 0 if @a a and @a b are equal. | ||
1625 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1626 | * | ||
1627 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1628 | * returns EINA_FALSE. | ||
1629 | * | ||
1630 | * @see eina_model_compare() | ||
1631 | * @see _Eina_Model_Type | ||
1632 | * @since 1.2 | ||
1633 | */ | ||
1634 | EAPI Eina_Bool eina_model_type_compare(const Eina_Model_Type *type, | ||
1635 | const Eina_Model *a, | ||
1636 | const Eina_Model *b, | ||
1637 | int *cmp) EINA_ARG_NONNULL(1, 2, 3, 4); | ||
1638 | /** | ||
1639 | * @brief Calls the load method of @a type for @a model. | ||
1640 | * @param type The type whose load method will be called. | ||
1641 | * @param model The model instance. | ||
1642 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1643 | * | ||
1644 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1645 | * returns EINA_FALSE. | ||
1646 | * | ||
1647 | * @see eina_model_load() | ||
1648 | * @see _Eina_Model_Type | ||
1649 | * @since 1.2 | ||
1650 | */ | ||
1651 | EAPI Eina_Bool eina_model_type_load(const Eina_Model_Type *type, | ||
1652 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
1653 | /** | ||
1654 | * @brief Calls the unload method of @a type for @a model. | ||
1655 | * @param type The type whose unload method will be called. | ||
1656 | * @param model The model instance. | ||
1657 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1658 | * | ||
1659 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1660 | * returns EINA_FALSE. | ||
1661 | * | ||
1662 | * @see eina_model_unload() | ||
1663 | * @see _Eina_Model_Type | ||
1664 | * @since 1.2 | ||
1665 | */ | ||
1666 | EAPI Eina_Bool eina_model_type_unload(const Eina_Model_Type *type, | ||
1667 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
1668 | /** | ||
1669 | * @brief Calls the property get method of @a type for @a model. | ||
1670 | * @param[in] type The type whose property get method will be called. | ||
1671 | * @param[in] model The model instance. | ||
1672 | * @param[in] name Name of property to get. | ||
1673 | * @param[out] value Pointer to where value of property will be placed. | ||
1674 | * @return EINA_TRUE if able to get property, EINA_FALSE otherwise. | ||
1675 | * | ||
1676 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1677 | * returns EINA_FALSE. | ||
1678 | * | ||
1679 | * @see eina_model_property_get() | ||
1680 | * @see _Eina_Model_Type | ||
1681 | * @since 1.2 | ||
1682 | */ | ||
1683 | EAPI Eina_Bool eina_model_type_property_get(const Eina_Model_Type *type, | ||
1684 | const Eina_Model *model, | ||
1685 | const char *name, | ||
1686 | Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4); | ||
1687 | /** | ||
1688 | * @brief Calls the property set method of @a type for @a model. | ||
1689 | * @param type The type whose property set method will be called. | ||
1690 | * @param model The model instance. | ||
1691 | * @param name Name of property whose value will be set. | ||
1692 | * @param value The value to be set. | ||
1693 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1694 | * | ||
1695 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1696 | * returns EINA_FALSE. | ||
1697 | * | ||
1698 | * @see eina_model_property_set() | ||
1699 | * @see _Eina_Model_Type | ||
1700 | * @since 1.2 | ||
1701 | */ | ||
1702 | EAPI Eina_Bool eina_model_type_property_set(const Eina_Model_Type *type, | ||
1703 | Eina_Model *model, | ||
1704 | const char *name, | ||
1705 | const Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4); | ||
1706 | /** | ||
1707 | * @brief Calls the property del method of @a type for @a model. | ||
1708 | * @param type The type whose property delete method will be called. | ||
1709 | * @param model The model instance. | ||
1710 | * @param name The name of the property to be deleted. | ||
1711 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1712 | * | ||
1713 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1714 | * returns EINA_FALSE. | ||
1715 | * | ||
1716 | * @see eina_model_property_del() | ||
1717 | * @see _Eina_Model_Type | ||
1718 | * @since 1.2 | ||
1719 | */ | ||
1720 | EAPI Eina_Bool eina_model_type_property_del(const Eina_Model_Type *type, | ||
1721 | Eina_Model *model, | ||
1722 | const char *name) EINA_ARG_NONNULL(1, 2, 3); | ||
1723 | /** | ||
1724 | * @brief Calls the properties name list method of @a type for @a model. | ||
1725 | * @param type The type whose property name list get method will be called. | ||
1726 | * @param model The model instance. | ||
1727 | * @return #Eina_List of properties' names. | ||
1728 | * | ||
1729 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1730 | * returns EINA_FALSE. | ||
1731 | * | ||
1732 | * @see eina_model_properties_names_list_get() | ||
1733 | * @see _Eina_Model_Type | ||
1734 | * @since 1.2 | ||
1735 | */ | ||
1736 | EAPI Eina_List *eina_model_type_properties_names_list_get(const Eina_Model_Type *type, | ||
1737 | const Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
1738 | /** | ||
1739 | * @brief Calls the child count method of @a type for @a model. | ||
1740 | * @param type The type whose child count method will be called. | ||
1741 | * @param model The model instance. | ||
1742 | * @return Number of children in @a model. | ||
1743 | * | ||
1744 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1745 | * returns EINA_FALSE. | ||
1746 | * | ||
1747 | * @see eina_model_child_count() | ||
1748 | * @see _Eina_Model_Type | ||
1749 | * @since 1.2 | ||
1750 | */ | ||
1751 | EAPI int eina_model_type_child_count(const Eina_Model_Type *type, | ||
1752 | const Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
1753 | /** | ||
1754 | * @brief Calls the child get method of @a type for @a model. | ||
1755 | * @param type The type whose child get method will be called. | ||
1756 | * @param model The model instance. | ||
1757 | * @param position The position of the child to get. | ||
1758 | * @return The child model, or NULL on failure. | ||
1759 | * | ||
1760 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1761 | * returns EINA_FALSE. | ||
1762 | * | ||
1763 | * @see eina_model_child_get() | ||
1764 | * @see _Eina_Model_Type | ||
1765 | * @since 1.2 | ||
1766 | */ | ||
1767 | EAPI Eina_Model *eina_model_type_child_get(const Eina_Model_Type *type, | ||
1768 | const Eina_Model *model, | ||
1769 | unsigned int position) EINA_ARG_NONNULL(1, 2); | ||
1770 | /** | ||
1771 | * @brief Calls the child set method of @a type for @a model. | ||
1772 | * @param type The type whose child set method will be called. | ||
1773 | * @param model The model instance. | ||
1774 | * @param position The position of the child to be set. | ||
1775 | * @param child Pointer to value(child) to be set. | ||
1776 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1777 | * | ||
1778 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1779 | * returns EINA_FALSE. | ||
1780 | * | ||
1781 | * @see eina_model_child_set() | ||
1782 | * @see _Eina_Model_Type | ||
1783 | * @since 1.2 | ||
1784 | */ | ||
1785 | EAPI Eina_Bool eina_model_type_child_set(const Eina_Model_Type *type, | ||
1786 | Eina_Model *model, | ||
1787 | unsigned int position, | ||
1788 | Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4); | ||
1789 | /** | ||
1790 | * @brief Calls the child del method of @a type for @a model. | ||
1791 | * @param type The type whose child delete method will be called. | ||
1792 | * @param model The model instance. | ||
1793 | * @param position Position of child to be deleted. | ||
1794 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1795 | * | ||
1796 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1797 | * returns EINA_FALSE. | ||
1798 | * | ||
1799 | * @see eina_model_child_del() | ||
1800 | * @see _Eina_Model_Type | ||
1801 | * @since 1.2 | ||
1802 | */ | ||
1803 | EAPI Eina_Bool eina_model_type_child_del(const Eina_Model_Type *type, | ||
1804 | Eina_Model *model, | ||
1805 | unsigned int position) EINA_ARG_NONNULL(1, 2); | ||
1806 | /** | ||
1807 | * @brief Calls the child insert at method of @a type for @a model. | ||
1808 | * @param type The type whose child insert method will be called. | ||
1809 | * @param model The model instance. | ||
1810 | * @param position Position in which @a child will be inserted. | ||
1811 | * @param child The child to be inserted. | ||
1812 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
1813 | * | ||
1814 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1815 | * returns EINA_FALSE. | ||
1816 | * | ||
1817 | * @see eina_model_child_insert_at() | ||
1818 | * @see _Eina_Model_Type | ||
1819 | * @since 1.2 | ||
1820 | */ | ||
1821 | EAPI Eina_Bool eina_model_type_child_insert_at(const Eina_Model_Type *type, | ||
1822 | Eina_Model *model, | ||
1823 | unsigned int position, | ||
1824 | Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4); | ||
1825 | /** | ||
1826 | * @brief Calls the child find method of @a type for @a model. | ||
1827 | * @param type The type whose find method will be called. | ||
1828 | * @param model The model instance. | ||
1829 | * @param start_position The first position to search for. | ||
1830 | * @param other The child being searched for. | ||
1831 | * @return The index of the searched child, or -1 if not found. | ||
1832 | * | ||
1833 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1834 | * returns EINA_FALSE. | ||
1835 | * | ||
1836 | * @see eina_model_child_find() | ||
1837 | * @see _Eina_Model_Type | ||
1838 | * @since 1.2 | ||
1839 | */ | ||
1840 | EAPI int eina_model_type_child_find(const Eina_Model_Type *type, | ||
1841 | const Eina_Model *model, | ||
1842 | unsigned int start_position, | ||
1843 | const Eina_Model *other) EINA_ARG_NONNULL(1, 2, 4); | ||
1844 | /** | ||
1845 | * @brief Calls the child criteria match method of @a type for @a model. | ||
1846 | * @param type The type whose child criteria match method will be called. | ||
1847 | * @param model The model instance. | ||
1848 | * @param start_position The first position to be checked. | ||
1849 | * @param match The function used to determine if a child matches the criteria. | ||
1850 | * @param data Data given to the @a match function. May be NULL. | ||
1851 | * @return The position of the first child to match the criteria or -1 if no | ||
1852 | * child matches it. | ||
1853 | * | ||
1854 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1855 | * returns EINA_FALSE. | ||
1856 | * | ||
1857 | * @see eina_model_child_criteria_match() | ||
1858 | * @see _Eina_Model_Type | ||
1859 | * @since 1.2 | ||
1860 | */ | ||
1861 | EAPI int eina_model_type_child_criteria_match(const Eina_Model_Type *type, | ||
1862 | const Eina_Model *model, | ||
1863 | unsigned int start_position, | ||
1864 | Eina_Each_Cb match, | ||
1865 | const void *data) EINA_ARG_NONNULL(1, 2, 4); | ||
1866 | /** | ||
1867 | * @brief Calls the child sort method of @a type for @a model. | ||
1868 | * @param type The type whose child sort method will be called. | ||
1869 | * @param model The model instance. | ||
1870 | * @param compare Function used to compare children. | ||
1871 | * | ||
1872 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1873 | * returns EINA_FALSE. | ||
1874 | * | ||
1875 | * @see eina_model_child_sort() | ||
1876 | * @see _Eina_Model_Type | ||
1877 | * @since 1.2 | ||
1878 | */ | ||
1879 | EAPI void eina_model_type_child_sort(const Eina_Model_Type *type, | ||
1880 | Eina_Model *model, | ||
1881 | Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3); | ||
1882 | /** | ||
1883 | * @brief Calls the child iterator get method of @a type for @a model. | ||
1884 | * @param type The type whose child iterator get method will be called. | ||
1885 | * @param model The model instance. | ||
1886 | * @param start The first child to be a part of the iterator. | ||
1887 | * @param count The number of children included in the iterator. | ||
1888 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1889 | * | ||
1890 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1891 | * returns EINA_FALSE. | ||
1892 | * | ||
1893 | * @see eina_model_child_iterator_get() | ||
1894 | * @see _Eina_Model_Type | ||
1895 | * @since 1.2 | ||
1896 | */ | ||
1897 | EAPI Eina_Iterator *eina_model_type_child_iterator_get(const Eina_Model_Type *type, | ||
1898 | Eina_Model *model, | ||
1899 | unsigned int start, | ||
1900 | unsigned int count) EINA_ARG_NONNULL(1, 2); | ||
1901 | /** | ||
1902 | * @brief Calls the child reversed iterator get method of @a type for @a model. | ||
1903 | * @param type The type whose child reversed iterator get method will be called. | ||
1904 | * @param model The model instance. | ||
1905 | * @param start The first child to be a part of the iterator. | ||
1906 | * @param count The number of children included in the iterator. | ||
1907 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1908 | * | ||
1909 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1910 | * returns EINA_FALSE. | ||
1911 | * | ||
1912 | * @see eina_model_child_reversed_iterator_get() | ||
1913 | * @see _Eina_Model_Type | ||
1914 | * @since 1.2 | ||
1915 | */ | ||
1916 | EAPI Eina_Iterator *eina_model_type_child_reversed_iterator_get(const Eina_Model_Type *type, | ||
1917 | Eina_Model *model, | ||
1918 | unsigned int start, | ||
1919 | unsigned int count) EINA_ARG_NONNULL(1, 2); | ||
1920 | /** | ||
1921 | * @brief Calls the child sorted iterator get method of @a type for @a model. | ||
1922 | * @param type The type whose child sorted iterator get method will be called. | ||
1923 | * @param model The model instance. | ||
1924 | * @param start The first child to be a part of the iterator. | ||
1925 | * @param count The number of children included in the iterator. | ||
1926 | * @param compare Function used to compare children. | ||
1927 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1928 | * | ||
1929 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1930 | * returns EINA_FALSE. | ||
1931 | * | ||
1932 | * @see eina_model_child_sorted_iterator_get() | ||
1933 | * @see _Eina_Model_Type | ||
1934 | * @since 1.2 | ||
1935 | */ | ||
1936 | EAPI Eina_Iterator *eina_model_type_child_sorted_iterator_get(const Eina_Model_Type *type, | ||
1937 | Eina_Model *model, | ||
1938 | unsigned int start, | ||
1939 | unsigned int count, | ||
1940 | Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 5); | ||
1941 | /** | ||
1942 | * @brief Calls the child filtered get method of @a type for @a model. | ||
1943 | * @param type The type whose child filtered iterator get method will be called. | ||
1944 | * @param model The model instance. | ||
1945 | * @param start The first child to be a part of the iterator. | ||
1946 | * @param count Number of children to be checked for inclusion in the iterator. | ||
1947 | * @param match Function used to check if child will be included in the iterator. | ||
1948 | * @param data Data given to the @a match function. May be NULL. | ||
1949 | * @return Newly created iterator instance on success or @c NULL on failure. | ||
1950 | * | ||
1951 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1952 | * returns EINA_FALSE. | ||
1953 | * | ||
1954 | * @see eina_model_child_filtered_iterator_get() | ||
1955 | * @see _Eina_Model_Type | ||
1956 | * @since 1.2 | ||
1957 | */ | ||
1958 | EAPI Eina_Iterator *eina_model_type_child_filtered_iterator_get(const Eina_Model_Type *type, | ||
1959 | Eina_Model *model, | ||
1960 | unsigned int start, | ||
1961 | unsigned int count, | ||
1962 | Eina_Each_Cb match, | ||
1963 | const void *data) EINA_ARG_NONNULL(1, 2, 5); | ||
1964 | /** | ||
1965 | * @brief Calls the to string method of @a type for @a model. | ||
1966 | * @param type The type whose to string method will be called. | ||
1967 | * @param model The model instance. | ||
1968 | * @return String representationof @a model. | ||
1969 | * | ||
1970 | * @warning If model doesn't inherit from(or is of) @a type does nothing and | ||
1971 | * returns EINA_FALSE. | ||
1972 | * | ||
1973 | * @see eina_model_to_string() | ||
1974 | * @see _Eina_Model_Type | ||
1975 | * @since 1.2 | ||
1976 | */ | ||
1977 | EAPI char *eina_model_type_to_string(const Eina_Model_Type *type, | ||
1978 | const Eina_Model *model) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
1979 | |||
1980 | |||
1981 | /** | ||
1982 | * @brief Get resolved method from types that extend Eina_Model_Type given @a offset. | ||
1983 | * @param model the model to query the method | ||
1984 | * @param offset the byte offset in the structure given as type, it | ||
1985 | * must be bigger than Eina_Model_Type itself. | ||
1986 | * @return Address to resolved method, or @c NULL if method is not implemented. | ||
1987 | * | ||
1988 | * The use of this function is discouraged, you should use | ||
1989 | * eina_model_method_resolve() instead. | ||
1990 | * | ||
1991 | * When implementing new types that augments the basic methods from | ||
1992 | * Eina_Model_Type, the recommended structure layout is as follow: | ||
1993 | * @code | ||
1994 | * typedef struct _My_Type My_Type; | ||
1995 | * struct _My_Type { | ||
1996 | * Eina_Model_Type base; | ||
1997 | * int (*my_method)(Eina_Model *model); | ||
1998 | * }; | ||
1999 | * | ||
2000 | * int my_type_my_method(Eina_Model *model); | ||
2001 | * @endcode | ||
2002 | * | ||
2003 | * Then the implementation of @c my_type_my_method() needs to get the | ||
2004 | * most specific @c my_method that is not @c NULL from type hierarchy, | ||
2005 | * also called "resolve the method". | ||
2006 | * | ||
2007 | * To do this in an efficient way, Eina_Model infrastructure | ||
2008 | * pre-resolves all methods and provides this function for efficient | ||
2009 | * query. The recommended implementation of my_type_my_method() would | ||
2010 | * be: | ||
2011 | * @code | ||
2012 | * int my_type_my_method(Eina_Model *model) | ||
2013 | * { | ||
2014 | * int (*meth)(Eina_Model *); | ||
2015 | * | ||
2016 | * EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(model, MY_TYPE), -1); | ||
2017 | * | ||
2018 | * meth = eina_model_method_offset_resolve(model, offsetof(My_Type, my_method)); | ||
2019 | * EINA_SAFETY_ON_NULL_RETURN(meth, -1); | ||
2020 | * return meth(model); | ||
2021 | * } | ||
2022 | * @endcode | ||
2023 | * | ||
2024 | * @note offset must be bigger than Eina_Model_Type, otherwise use | ||
2025 | * specific functions such as eina_model_property_get(). | ||
2026 | * | ||
2027 | * @see eina_model_method_resolve | ||
2028 | * @see eina_model_type_method_resolve | ||
2029 | * @since 1.2 | ||
2030 | */ | ||
2031 | EAPI const void *eina_model_method_offset_resolve(const Eina_Model *model, unsigned int offset) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2032 | |||
2033 | /** | ||
2034 | * @brief Gets resolved method from @a type of @a model given @a offset. | ||
2035 | * @param type The type whose method offset resolve method will be called. | ||
2036 | * @param model The model instance. | ||
2037 | * @param offset The offset of the wanted method. | ||
2038 | * @return Address to resolved method, or @c NULL if method is not implemented. | ||
2039 | * | ||
2040 | * @see eina_model_method_offset_resolve() | ||
2041 | * @since 1.2 | ||
2042 | */ | ||
2043 | EAPI const void *eina_model_type_method_offset_resolve(const Eina_Model_Type *type, const Eina_Model *model, unsigned int offset) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2044 | |||
2045 | #define eina_model_method_resolve(model, struct_type, method) eina_model_method_offset_resolve((model), offsetof(struct_type, method)) | ||
2046 | |||
2047 | #define eina_model_type_method_resolve(type, model, struct_type, method) eina_model_type_method_offset_resolve((type), (model), offsetof(struct_type, method)) | ||
2048 | |||
2049 | /** | ||
2050 | * @def EINA_MODEL_INTERFACE_VERSION | ||
2051 | * Current API version, used to validate #_Eina_Model_Interface. | ||
2052 | */ | ||
2053 | #define EINA_MODEL_INTERFACE_VERSION (1) | ||
2054 | |||
2055 | /** | ||
2056 | * @struct _Eina_Model_Interface | ||
2057 | * API to access models. | ||
2058 | * | ||
2059 | * Interfaces are managed by name, then multiple Eina_Model_Interface | ||
2060 | * may have the same name meaning it implements that name. | ||
2061 | * | ||
2062 | * Each interface will get its own private data of size @c | ||
2063 | * private_size (defined at each sub interface), this can be retrieved | ||
2064 | * with eina_model_interface_private_data_get(). | ||
2065 | * | ||
2066 | * Private are created @b automatically and should be setup with @c | ||
2067 | * setup and flushed with @c flush. All interfaces functions that | ||
2068 | * exist are called! Don't call your parent's @c setup or @c flush! | ||
2069 | * The setup is done from parent to child. Flush is done from child to | ||
2070 | * parent (topological sort is applied to interface graph). | ||
2071 | * | ||
2072 | * @note The methods @c setup and @c flush should exist if there is | ||
2073 | * private data, otherwise memory may be uninitialized or leaks. | ||
2074 | * @note It is recommended that @c constructor and @c destructor exist | ||
2075 | * to correctly do their roles and call parents in the correct | ||
2076 | * order. Whenever they do not exist, their parent pointer is | ||
2077 | * called. | ||
2078 | * @note Interface's constructor and destructor are only called by | ||
2079 | * type counterparts. Unlike setup and flush, they are not | ||
2080 | * guaranteed to be called. | ||
2081 | * @note use the same name pointer on queries to speed up the lookups! | ||
2082 | * @note a runtime check will enforce just types with ABI version | ||
2083 | * #EINA_MODEL_INTERFACE_VERSION are used by comparing with the | ||
2084 | * @c version member. | ||
2085 | * | ||
2086 | * @since 1.2 | ||
2087 | */ | ||
2088 | struct _Eina_Model_Interface | ||
2089 | { | ||
2090 | unsigned int version; /**< must be #EINA_MODEL_INTERFACE_VERSION */ | ||
2091 | unsigned int private_size; /**< used to allocate interface private data */ | ||
2092 | unsigned int interface_size; /**< used to know sizeof(Eina_Model_Interface) or subtypes (which may be bigger, by including Eina_Model_Interface as header */ | ||
2093 | const char *name; /**< name for debug and introspection */ | ||
2094 | const Eina_Model_Interface **interfaces; /**< null terminated array of parent interfaces */ | ||
2095 | const Eina_Model_Event_Description *events; /**< null terminated array of events */ | ||
2096 | Eina_Bool (*setup)(Eina_Model *model); /**< setup interface private data, do @b not call parent interface setup! */ | ||
2097 | Eina_Bool (*flush)(Eina_Model *model); /**< flush interface private data, do @b not call parent interface flush! */ | ||
2098 | Eina_Bool (*constructor)(Eina_Model *model); /**< construct interface instance, setup was already called. Should call parent's constructor if needed */ | ||
2099 | Eina_Bool (*destructor)(Eina_Model *model); /**< destruct interface instance, flush will be called after it. Should call parent's destructor if needed. Release reference to other models here. */ | ||
2100 | Eina_Bool (*copy)(const Eina_Model *src, Eina_Model *dst); /**< copy interface private data, do @b not call parent interface copy! */ | ||
2101 | Eina_Bool (*deep_copy)(const Eina_Model *src, Eina_Model *dst); /**< deep copy interface private data, do @b not call parent interface deep copy! */ | ||
2102 | void *__extension_ptr0; /**< not to be used @internal */ | ||
2103 | void *__extension_ptr1; /**< not to be used @internal */ | ||
2104 | void *__extension_ptr2; /**< not to be used @internal */ | ||
2105 | void *__extension_ptr3; /**< not to be used @internal */ | ||
2106 | }; | ||
2107 | |||
2108 | #define EINA_MODEL_INTERFACE_INIT(name, iface, private_type, parent, events) \ | ||
2109 | {EINA_MODEL_INTERFACE_VERSION, \ | ||
2110 | sizeof(private_type), \ | ||
2111 | sizeof(iface), \ | ||
2112 | name, \ | ||
2113 | parent, \ | ||
2114 | events, \ | ||
2115 | NULL, \ | ||
2116 | NULL, \ | ||
2117 | NULL, \ | ||
2118 | NULL, \ | ||
2119 | NULL, \ | ||
2120 | NULL, \ | ||
2121 | NULL, \ | ||
2122 | NULL, \ | ||
2123 | NULL, \ | ||
2124 | NULL \ | ||
2125 | } | ||
2126 | |||
2127 | #define EINA_MODEL_INTERFACE_INIT_NOPRIVATE(name, iface, parent, events) \ | ||
2128 | {EINA_MODEL_INTERFACE_VERSION, \ | ||
2129 | 0, \ | ||
2130 | sizeof(iface), \ | ||
2131 | name, \ | ||
2132 | parent, \ | ||
2133 | events, \ | ||
2134 | NULL, \ | ||
2135 | NULL, \ | ||
2136 | NULL, \ | ||
2137 | NULL, \ | ||
2138 | NULL, \ | ||
2139 | NULL, \ | ||
2140 | NULL, \ | ||
2141 | NULL, \ | ||
2142 | NULL, \ | ||
2143 | NULL \ | ||
2144 | } | ||
2145 | |||
2146 | #define EINA_MODEL_INTERFACE_INIT_NULL \ | ||
2147 | {0, \ | ||
2148 | 0, \ | ||
2149 | 0, \ | ||
2150 | NULL, \ | ||
2151 | NULL, \ | ||
2152 | NULL, \ | ||
2153 | NULL, \ | ||
2154 | NULL, \ | ||
2155 | NULL, \ | ||
2156 | NULL, \ | ||
2157 | NULL, \ | ||
2158 | NULL, \ | ||
2159 | NULL, \ | ||
2160 | NULL, \ | ||
2161 | NULL, \ | ||
2162 | NULL \ | ||
2163 | } | ||
2164 | |||
2165 | /** | ||
2166 | * @brief Calls the constructor of @a iface on @a model. | ||
2167 | * @param iface The interface whose constructor will be called. | ||
2168 | * @param model The model instance. | ||
2169 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2170 | * | ||
2171 | * @warning If @a model doesn't implement @a iface does nothing and returns | ||
2172 | * EINA_FALSE. | ||
2173 | * | ||
2174 | * @see eina_model_new() | ||
2175 | * @see _Eina_Model_Interface | ||
2176 | * @since 1.2 | ||
2177 | */ | ||
2178 | EAPI Eina_Bool eina_model_interface_constructor(const Eina_Model_Interface *iface, | ||
2179 | Eina_Model *model) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; | ||
2180 | /** | ||
2181 | * @brief Calls the destructor of @a iface on @a model. | ||
2182 | * @param iface The interface whose destructor will be called. | ||
2183 | * @param model The model instance. | ||
2184 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2185 | * | ||
2186 | * @warning If @a model doesn't implement @a iface does nothing and returns | ||
2187 | * EINA_FALSE. | ||
2188 | * | ||
2189 | * @see eina_model_del() | ||
2190 | * @see _Eina_Model_Interface | ||
2191 | * @since 1.2 | ||
2192 | */ | ||
2193 | EAPI Eina_Bool eina_model_interface_destructor(const Eina_Model_Interface *iface, | ||
2194 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
2195 | /** | ||
2196 | * @brief Calls the copy method of @a iface on @a model. | ||
2197 | * @param iface The interface whose copy method will be called. | ||
2198 | * @param src Pointer to the model to be copied. | ||
2199 | * @param dst Pointer to where copy will be put. | ||
2200 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2201 | * | ||
2202 | * @warning If @a model doesn't implement @a iface does nothing and returns | ||
2203 | * EINA_FALSE. | ||
2204 | * | ||
2205 | * @see eina_model_copy() | ||
2206 | * @see _Eina_Model_Interface | ||
2207 | * @since 1.2 | ||
2208 | */ | ||
2209 | EAPI Eina_Bool eina_model_interface_copy(const Eina_Model_Interface *iface, | ||
2210 | const Eina_Model *src, | ||
2211 | Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3); | ||
2212 | /** | ||
2213 | * @brief Calls the deep copy method of @a iface on @a model. | ||
2214 | * @param iface The interface whose deep copy method will be called. | ||
2215 | * @param src Pointer to the model to be copied. | ||
2216 | * @param dst Pointer to where copy will be put. | ||
2217 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2218 | * | ||
2219 | * @warning If @a model doesn't implement @a iface does nothing and returns | ||
2220 | * EINA_FALSE. | ||
2221 | * | ||
2222 | * @see eina_model_deep_copy() | ||
2223 | * @see _Eina_Model_Interface | ||
2224 | * @since 1.2 | ||
2225 | */ | ||
2226 | EAPI Eina_Bool eina_model_interface_deep_copy(const Eina_Model_Interface *iface, | ||
2227 | const Eina_Model *src, | ||
2228 | Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3); | ||
2229 | |||
2230 | #define eina_model_interface_method_resolve(iface, model, struct_type, method) eina_model_interface_method_offset_resolve((iface), (model), offsetof(struct_type, method)) | ||
2231 | |||
2232 | /** | ||
2233 | * @brief Gets the @a iface's method for @a model at @a offset. | ||
2234 | * @param iface The interface whose method offset resolve method will be called. | ||
2235 | * @param model The model instance. | ||
2236 | * @param offset The offset of the wanted method. | ||
2237 | * @return Address to resolved method, or @c NULL if method is not implemented. | ||
2238 | * | ||
2239 | * @see eina_model_method_offset_resolve() | ||
2240 | * @since 1.2 | ||
2241 | */ | ||
2242 | EAPI const void *eina_model_interface_method_offset_resolve(const Eina_Model_Interface *iface, const Eina_Model *model, unsigned int offset) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2243 | |||
2244 | |||
2245 | /** | ||
2246 | * @struct _Eina_Model_Event_Description | ||
2247 | * Data Model Event Description. | ||
2248 | * | ||
2249 | * @see EINA_MODEL_EVENT_DESCRIPTION() | ||
2250 | * @see #EINA_MODEL_EVENT_DESCRIPTION_SENTINEL | ||
2251 | * @since 1.2 | ||
2252 | */ | ||
2253 | struct _Eina_Model_Event_Description | ||
2254 | { | ||
2255 | const char *name; /**< name used for lookups */ | ||
2256 | const char *type; /**< used for introspection purposes, documents what goes as callback event information (@c event_info) */ | ||
2257 | const char *doc; /**< documentation for introspection purposes */ | ||
2258 | }; | ||
2259 | |||
2260 | /** | ||
2261 | * @def EINA_MODEL_EVENT_DESCRIPTION | ||
2262 | * | ||
2263 | * Helper to define Eina_Model_Event_Description fields. | ||
2264 | * | ||
2265 | * @since 1.2 | ||
2266 | */ | ||
2267 | #define EINA_MODEL_EVENT_DESCRIPTION(name, type, doc) {name, type, doc} | ||
2268 | |||
2269 | /** | ||
2270 | * @def EINA_MODEL_EVENT_DESCRIPTION_SENTINEL | ||
2271 | * | ||
2272 | * Helper to define Eina_Model_Event_Description fields for sentinel (last | ||
2273 | * item). | ||
2274 | * | ||
2275 | * @since 1.2 | ||
2276 | */ | ||
2277 | #define EINA_MODEL_EVENT_DESCRIPTION_SENTINEL {NULL, NULL, NULL} | ||
2278 | |||
2279 | /** | ||
2280 | * @brief Check @a type is valid. | ||
2281 | * @param type The type to be checked. | ||
2282 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. | ||
2283 | * | ||
2284 | * @since 1.2 | ||
2285 | */ | ||
2286 | EAPI Eina_Bool eina_model_type_check(const Eina_Model_Type *type) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2287 | /** | ||
2288 | * @brief Gets the name @a type. | ||
2289 | * @param type The type whose name is wanted. | ||
2290 | * @return Name of @a type. | ||
2291 | * | ||
2292 | * @since 1.2 | ||
2293 | */ | ||
2294 | EAPI const char *eina_model_type_name_get(const Eina_Model_Type *type) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2295 | /** | ||
2296 | * @brief Gets the parent type of @a type. | ||
2297 | * @param type The type whose parent is wanted. | ||
2298 | * @return Type of parent. | ||
2299 | * | ||
2300 | * @since 1.2 | ||
2301 | */ | ||
2302 | EAPI const Eina_Model_Type *eina_model_type_parent_get(const Eina_Model_Type *type) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2303 | |||
2304 | /** | ||
2305 | * @brief Setup the type to be a subclass of another parent type. | ||
2306 | * @param type type to be modified | ||
2307 | * @param parent type to be used as parent | ||
2308 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. | ||
2309 | * | ||
2310 | * Although @a type is modified, the following properties are not | ||
2311 | * touched or they are actually used for validation: | ||
2312 | * | ||
2313 | * @li @c type->version must be #EINA_MODEL_TYPE_VERSION; | ||
2314 | * @li @c type->private_size unmodified, should be set to type's size; | ||
2315 | * @li @c type->name unmodified, should be set to type's name. | ||
2316 | * | ||
2317 | * | ||
2318 | * All other fields are modified as follow: | ||
2319 | * | ||
2320 | * @li @c type->type_size initiated to parent->type_size | ||
2321 | * @li @c type->interfaces = NULL; | ||
2322 | * @li @c type->events = NULL; | ||
2323 | * @li @c type->setup = NULL; | ||
2324 | * @li @c type->flush = NULL; | ||
2325 | * @li @c type->constructor = NULL; | ||
2326 | * @li @c type->destructor = NULL; | ||
2327 | * @li @c type->copy = NULL; | ||
2328 | * @li @c type->deep_copy = NULL; | ||
2329 | * @li @c type->compare = NULL; | ||
2330 | * @li @c type->load = NULL; | ||
2331 | * @li @c type->unload = NULL; | ||
2332 | * @li @c type->property_get = NULL; | ||
2333 | * @li @c type->property_set = NULL; | ||
2334 | * @li @c type->property_del = NULL; | ||
2335 | * @li @c type->properties_names_list_get = NULL; | ||
2336 | * @li @c type->child_count = NULL; | ||
2337 | * @li @c type->child_get = NULL; | ||
2338 | * @li @c type->child_set = NULL; | ||
2339 | * @li @c type->child_del = NULL; | ||
2340 | * @li @c type->child_insert_at = NULL; | ||
2341 | * @li @c type->child_find = NULL; | ||
2342 | * @li @c type->child_criteria_match = NULL; | ||
2343 | * @li @c type->child_sort = NULL; | ||
2344 | * @li @c type->child_iterator_get = NULL; | ||
2345 | * @li @c type->child_reversed_iterator_get = NULL; | ||
2346 | * @li @c type->child_sorted_iterator_get = NULL; | ||
2347 | * @li @c type->child_filtered_iterator_get = NULL; | ||
2348 | * @li @c type->to_string = NULL; | ||
2349 | * | ||
2350 | * If you have custom methods, overload them afterwards | ||
2351 | * eina_model_type_subclass_setup() returns with #EINA_TRUE. | ||
2352 | * | ||
2353 | * @since 1.2 | ||
2354 | */ | ||
2355 | EAPI Eina_Bool eina_model_type_subclass_setup(Eina_Model_Type *type, | ||
2356 | const Eina_Model_Type *parent) EINA_ARG_NONNULL(1, 2); | ||
2357 | |||
2358 | /** | ||
2359 | * @brief Checks if @a type is a subclass of(or the same as) @a self_or_parent. | ||
2360 | * @param type The type to be checked. | ||
2361 | * @param self_or_parent The type being checked for. | ||
2362 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2363 | * | ||
2364 | * @since 1.2 | ||
2365 | */ | ||
2366 | EAPI Eina_Bool eina_model_type_subclass_check(const Eina_Model_Type *type, | ||
2367 | const Eina_Model_Type *self_or_parent) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2368 | |||
2369 | |||
2370 | /** | ||
2371 | * @brief Gets a interface with name @a name from @a type. | ||
2372 | * @param type The type instance. | ||
2373 | * @param name The name of the desired interface. | ||
2374 | * @return The interface implemented by @a type with name @a name, or null if | ||
2375 | * this type doesn't implement any interface with name @a name. | ||
2376 | * | ||
2377 | * @since 1.2 | ||
2378 | */ | ||
2379 | EAPI const Eina_Model_Interface *eina_model_type_interface_get(const Eina_Model_Type *type, | ||
2380 | const char *name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2381 | |||
2382 | /** | ||
2383 | * @brief Gets the private date of @a model for type @a type. | ||
2384 | * @param model The model instance. | ||
2385 | * @param type The type whose private data will be gotten. | ||
2386 | * @return Pointer to type's private data. | ||
2387 | * | ||
2388 | * @since 1.2 | ||
2389 | */ | ||
2390 | EAPI void *eina_model_type_private_data_get(const Eina_Model *model, | ||
2391 | const Eina_Model_Type *type) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE; | ||
2392 | |||
2393 | /** | ||
2394 | * @brief Checks if @a iface is a valid interface. | ||
2395 | * @param iface The interface instance. | ||
2396 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2397 | * | ||
2398 | * @since 1.2 | ||
2399 | */ | ||
2400 | EAPI Eina_Bool eina_model_interface_check(const Eina_Model_Interface *iface) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2401 | |||
2402 | /** | ||
2403 | * @brief Gets the private date of @a model for interface @a iface. | ||
2404 | * @param model The model instance. | ||
2405 | * @param iface The interface whose private data will be gotten. | ||
2406 | * @return Pointer to interface's private data. | ||
2407 | * | ||
2408 | * @since 1.2 | ||
2409 | */ | ||
2410 | EAPI void *eina_model_interface_private_data_get(const Eina_Model *model, | ||
2411 | const Eina_Model_Interface *iface) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE; | ||
2412 | |||
2413 | /** | ||
2414 | * @def EINA_MODEL_INTERFACE_PROPERTIES_VERSION | ||
2415 | * Current API version, used to validate #_Eina_Model_Interface_Properties. | ||
2416 | */ | ||
2417 | #define EINA_MODEL_INTERFACE_PROPERTIES_VERSION (1) | ||
2418 | |||
2419 | /** | ||
2420 | * @typedef Eina_Model_Interface_Properties | ||
2421 | * Interface to manage model's properties. | ||
2422 | * | ||
2423 | * This extends #Eina_Model_Interface as expected by interface name | ||
2424 | * #EINA_MODEL_INTERFACE_NAME_PROPERTIES. | ||
2425 | * | ||
2426 | * This interface is meant to help managing properties of a model, it | ||
2427 | * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for | ||
2428 | * children independently from properties. | ||
2429 | * | ||
2430 | * @see #_Eina_Model_Interface_Properties explains fields. | ||
2431 | * @since 1.2 | ||
2432 | */ | ||
2433 | typedef struct _Eina_Model_Interface_Properties Eina_Model_Interface_Properties; | ||
2434 | |||
2435 | /** | ||
2436 | * @struct _Eina_Model_Interface_Properties | ||
2437 | * Interface to manage model's properties. | ||
2438 | * | ||
2439 | * This extends #Eina_Model_Interface as expected by interface name | ||
2440 | * #EINA_MODEL_INTERFACE_NAME_PROPERTIES. | ||
2441 | * | ||
2442 | * This interface is meant to help managing properties of a model, it | ||
2443 | * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for | ||
2444 | * children independently from properties. | ||
2445 | * | ||
2446 | * @since 1.2 | ||
2447 | */ | ||
2448 | struct _Eina_Model_Interface_Properties | ||
2449 | { | ||
2450 | Eina_Model_Interface base; /**< common interface methods */ | ||
2451 | unsigned int version; /**< must be #EINA_MODEL_INTERFACE_PROPERTIES_VERSION */ | ||
2452 | Eina_Bool (*compare)(const Eina_Model *a, const Eina_Model *b, int *cmp); /**< How to compare properties of this model */ | ||
2453 | Eina_Bool (*load)(Eina_Model *model); /**< How to load properties of this model */ | ||
2454 | Eina_Bool (*unload)(Eina_Model *model); /**< How to unload properties of this model */ | ||
2455 | Eina_Bool (*get)(const Eina_Model *model, const char *name, Eina_Value *value); /**< Retrieve a property of this model given its name. The value will be returned as a copy and must be flushed with eina_value_flush(). The previous contents of value is ignored. */ | ||
2456 | Eina_Bool (*set)(Eina_Model *model, const char *name, const Eina_Value *value); /**< Set a property of this model given its name. The value is assumed to be valied and is copied internally, thus it can be safely cleared with eina_value_flush() after this function returns. */ | ||
2457 | Eina_Bool (*del)(Eina_Model *model, const char *name); /**< Delete a property given its name */ | ||
2458 | Eina_List *(*names_list_get)(const Eina_Model *model); /**< List of stringshare with known property names */ | ||
2459 | }; | ||
2460 | |||
2461 | /** | ||
2462 | * @brief Compares properties using @a iface's comparing function. | ||
2463 | * | ||
2464 | * @param[in] iface The interface used to compare the properties. | ||
2465 | * @param[in] a The first model whose properties will be compared. | ||
2466 | * @param[in] b The second model whose properties will be compared. | ||
2467 | * @param[out] cmp A pointer to an integer which will contain the result of the | ||
2468 | * comparison. | ||
2469 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2470 | * | ||
2471 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2472 | * return EINA_FALSE. | ||
2473 | * | ||
2474 | * @see eina_model_compare() | ||
2475 | * @since 1.2 | ||
2476 | */ | ||
2477 | EAPI Eina_Bool eina_model_interface_properties_compare(const Eina_Model_Interface *iface, | ||
2478 | const Eina_Model *a, | ||
2479 | const Eina_Model *b, | ||
2480 | int *cmp) EINA_ARG_NONNULL(1, 2, 3, 4) EINA_WARN_UNUSED_RESULT; | ||
2481 | |||
2482 | /** | ||
2483 | * @brief Loads properties using @a iface's loading function. | ||
2484 | * @param iface The properties interface whose load method will be called. | ||
2485 | * @param model The model instance. | ||
2486 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2487 | * | ||
2488 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2489 | * return EINA_FALSE. | ||
2490 | * | ||
2491 | * @see eina_model_load() | ||
2492 | * @since 1.2 | ||
2493 | */ | ||
2494 | EAPI Eina_Bool eina_model_interface_properties_load(const Eina_Model_Interface *iface, | ||
2495 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
2496 | /** | ||
2497 | * @brief Unloads properties using @a iface's unloading function. | ||
2498 | * @param iface The properties interface whose unload method will be called. | ||
2499 | * @param model The model instance. | ||
2500 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2501 | * | ||
2502 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2503 | * return EINA_FALSE. | ||
2504 | * | ||
2505 | * @see eina_model_unload() | ||
2506 | * @since 1.2 | ||
2507 | */ | ||
2508 | EAPI Eina_Bool eina_model_interface_properties_unload(const Eina_Model_Interface *iface, | ||
2509 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
2510 | /** | ||
2511 | * @brief Gets property named @a name using @a iface's function to get properties. | ||
2512 | * @param iface The properties interface whose property get method will be called. | ||
2513 | * @param model The model instance. | ||
2514 | * @param name The name of the property to get. | ||
2515 | * @param value Pointer to where value will be stored. | ||
2516 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2517 | * | ||
2518 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2519 | * return EINA_FALSE. | ||
2520 | * | ||
2521 | * @see eina_model_property_get() | ||
2522 | * @since 1.2 | ||
2523 | */ | ||
2524 | EAPI Eina_Bool eina_model_interface_properties_get(const Eina_Model_Interface *iface, | ||
2525 | const Eina_Model *model, | ||
2526 | const char *name, | ||
2527 | Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4); | ||
2528 | /** | ||
2529 | * @brief Sets property named @a name using @a iface's function to set properties. | ||
2530 | * @param iface The properties interface whose property set method will be called. | ||
2531 | * @param model The model instance. | ||
2532 | * @param name The name of the property to set. | ||
2533 | * @param value The value to be set. | ||
2534 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2535 | * | ||
2536 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2537 | * return EINA_FALSE. | ||
2538 | * | ||
2539 | * @see eina_model_property_set() | ||
2540 | * @since 1.2 | ||
2541 | */ | ||
2542 | EAPI Eina_Bool eina_model_interface_properties_set(const Eina_Model_Interface *iface, | ||
2543 | Eina_Model *model, | ||
2544 | const char *name, | ||
2545 | const Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4); | ||
2546 | /** | ||
2547 | * @brief Deletes property named @a name using @a iface's function to delete properties. | ||
2548 | * @param iface The properties interface whose property delete method will be called. | ||
2549 | * @param model The model instance. | ||
2550 | * @param name The name of the property to delete. | ||
2551 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2552 | * | ||
2553 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2554 | * return EINA_FALSE. | ||
2555 | * | ||
2556 | * @see eina_model_property_del() | ||
2557 | * @since 1.2 | ||
2558 | */ | ||
2559 | EAPI Eina_Bool eina_model_interface_properties_del(const Eina_Model_Interface *iface, | ||
2560 | Eina_Model *model, | ||
2561 | const char *name) EINA_ARG_NONNULL(1, 2, 3); | ||
2562 | /** | ||
2563 | * @brief Gets properties name list using @a iface's function to get properties | ||
2564 | * name list. | ||
2565 | * @param iface The properties interface whose property name list get method | ||
2566 | * will be called. | ||
2567 | * @param model The model instance. | ||
2568 | * @return #Eina_List of properties' names. | ||
2569 | * | ||
2570 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2571 | * return EINA_FALSE. | ||
2572 | * | ||
2573 | * @see eina_model_properties_names_list_get() | ||
2574 | * @since 1.2 | ||
2575 | */ | ||
2576 | EAPI Eina_List *eina_model_interface_properties_names_list_get(const Eina_Model_Interface *iface, | ||
2577 | const Eina_Model *model) EINA_ARG_NONNULL(1, 2); /**< list of stringshare */ | ||
2578 | |||
2579 | /** | ||
2580 | * @typedef Eina_Model_Interface_Children | ||
2581 | * Interface to manage model's children. | ||
2582 | * | ||
2583 | * This extends #Eina_Model_Interface as expected by interface name | ||
2584 | * #EINA_MODEL_INTERFACE_NAME_CHILDREN. | ||
2585 | * | ||
2586 | * This interface is meant to help managing properties of a model, it | ||
2587 | * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for | ||
2588 | * children independently from properties. | ||
2589 | * | ||
2590 | * @see #_Eina_Model_Interface_Children explains fields. | ||
2591 | * @since 1.2 | ||
2592 | */ | ||
2593 | typedef struct _Eina_Model_Interface_Children Eina_Model_Interface_Children; | ||
2594 | |||
2595 | /** | ||
2596 | * @def EINA_MODEL_INTERFACE_CHILDREN_VERSION | ||
2597 | * Current API version, used to validate #_Eina_Model_Interface_Children. | ||
2598 | */ | ||
2599 | #define EINA_MODEL_INTERFACE_CHILDREN_VERSION (1) | ||
2600 | |||
2601 | /** | ||
2602 | * @struct _Eina_Model_Interface_Children | ||
2603 | * Interface to manage model's children. | ||
2604 | * | ||
2605 | * This extends #Eina_Model_Interface as expected by interface name | ||
2606 | * #EINA_MODEL_INTERFACE_NAME_CHILDREN. | ||
2607 | * | ||
2608 | * This interface is meant to help managing properties of a model, it | ||
2609 | * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for | ||
2610 | * children independently from properties. | ||
2611 | * | ||
2612 | * @since 1.2 | ||
2613 | */ | ||
2614 | struct _Eina_Model_Interface_Children | ||
2615 | { | ||
2616 | Eina_Model_Interface base; /**< common interface methods */ | ||
2617 | unsigned int version; /**< must be #EINA_MODEL_INTERFACE_CHILDREN_VERSION */ | ||
2618 | Eina_Bool (*compare)(const Eina_Model *a, const Eina_Model *b, int *cmp); /**< How to compare children of this model */ | ||
2619 | Eina_Bool (*load)(Eina_Model *model); /**< How to load children of this model */ | ||
2620 | Eina_Bool (*unload)(Eina_Model *model); /**< How to unload children of this model */ | ||
2621 | int (*count)(const Eina_Model *model); /**< How many children of this model */ | ||
2622 | Eina_Model *(*get)(const Eina_Model *model, unsigned int position); /**< Retrieve a child of this model, returned child must have reference increased! */ | ||
2623 | Eina_Bool (*set)(Eina_Model *model, unsigned int position, Eina_Model *child); /**< Set (replace) a child of this model, given child will have reference increased! */ | ||
2624 | Eina_Bool (*del)(Eina_Model *model, unsigned int position); /**< Delete a child of this model. Existing child will have reference decreased! */ | ||
2625 | Eina_Bool (*insert_at)(Eina_Model *model, unsigned int position, Eina_Model *child); /**< Insert a child into this model, given child will have reference increased! All elements towards the end of the internal list will be shifted to the end to make room for the new child. */ | ||
2626 | void (*sort)(Eina_Model *model, Eina_Compare_Cb compare); /**< Reorder children to be sorted respecting comparison function @c compare() */ | ||
2627 | }; | ||
2628 | |||
2629 | /** | ||
2630 | * @brief Compares children using @a iface's comparing function. | ||
2631 | * | ||
2632 | * @param[in] iface The interface used to compare the properties. | ||
2633 | * @param[in] a The first model whose properties will be compared. | ||
2634 | * @param[in] b The second model whose properties will be compared. | ||
2635 | * @param[out] cmp A pointer to an integer which will contain the result of the | ||
2636 | * comparison. | ||
2637 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2638 | * | ||
2639 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2640 | * return EINA_FALSE. | ||
2641 | * | ||
2642 | * @see eina_model_compare() | ||
2643 | * @since 1.2 | ||
2644 | */ | ||
2645 | EAPI Eina_Bool eina_model_interface_children_compare(const Eina_Model_Interface *iface, | ||
2646 | const Eina_Model *a, | ||
2647 | const Eina_Model *b, | ||
2648 | int *cmp) EINA_ARG_NONNULL(1, 2, 3, 4) EINA_WARN_UNUSED_RESULT; | ||
2649 | /** | ||
2650 | * @brief Loads children using @a iface's loading function. | ||
2651 | * @param iface The children interface whose load method will be called. | ||
2652 | * @param model The model instance. | ||
2653 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2654 | * | ||
2655 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2656 | * return EINA_FALSE. | ||
2657 | * | ||
2658 | * @see eina_model_load() | ||
2659 | * @since 1.2 | ||
2660 | */ | ||
2661 | EAPI Eina_Bool eina_model_interface_children_load(const Eina_Model_Interface *iface, | ||
2662 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
2663 | /** | ||
2664 | * @brief Unloads children using @a iface's unloading function. | ||
2665 | * @param iface The children interface whose unload method will be called. | ||
2666 | * @param model The model instance. | ||
2667 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2668 | * | ||
2669 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2670 | * return EINA_FALSE. | ||
2671 | * | ||
2672 | * @see eina_model_unload() | ||
2673 | * @since 1.2 | ||
2674 | */ | ||
2675 | EAPI Eina_Bool eina_model_interface_children_unload(const Eina_Model_Interface *iface, | ||
2676 | Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
2677 | /** | ||
2678 | * @brief Count children using @a iface's counting function. | ||
2679 | * @param iface The children interface whose count method will be called. | ||
2680 | * @param model The model instance. | ||
2681 | * @return Number of children in @a model. | ||
2682 | * | ||
2683 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2684 | * return -1. | ||
2685 | * | ||
2686 | * @see eina_model_child_count() | ||
2687 | * @since 1.2 | ||
2688 | */ | ||
2689 | EAPI int eina_model_interface_children_count(const Eina_Model_Interface *iface, | ||
2690 | const Eina_Model *model) EINA_ARG_NONNULL(1, 2); | ||
2691 | /** | ||
2692 | * @brief Get child using @a iface's function to get children. | ||
2693 | * @param iface The children interface whose get method will be called. | ||
2694 | * @param model The model instance. | ||
2695 | * @param position Position of child to be retrieved. | ||
2696 | * @return The requested child. | ||
2697 | * | ||
2698 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2699 | * return -1. | ||
2700 | * | ||
2701 | * @see eina_model_child_get() | ||
2702 | * @since 1.2 | ||
2703 | */ | ||
2704 | EAPI Eina_Model *eina_model_interface_children_get(const Eina_Model_Interface *iface, | ||
2705 | const Eina_Model *model, | ||
2706 | unsigned int position) EINA_ARG_NONNULL(1, 2); | ||
2707 | /** | ||
2708 | * @brief Set child using @a iface's function to set children. | ||
2709 | * @param iface The children interface whose set method will be called. | ||
2710 | * @param model The model instance. | ||
2711 | * @param position Position of child to be set. | ||
2712 | * @param child Value(child) to be set. | ||
2713 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2714 | * | ||
2715 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2716 | * return -1. | ||
2717 | * | ||
2718 | * @see eina_model_child_set() | ||
2719 | * @since 1.2 | ||
2720 | */ | ||
2721 | EAPI Eina_Bool eina_model_interface_children_set(const Eina_Model_Interface *iface, | ||
2722 | Eina_Model *model, | ||
2723 | unsigned int position, | ||
2724 | Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4); | ||
2725 | /** | ||
2726 | * @brief Delete child using @a iface's function to delete children. | ||
2727 | * @param iface The children interface whose delete method will be called. | ||
2728 | * @param model The model instance. | ||
2729 | * @param position Position of child to be deleted. | ||
2730 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2731 | * | ||
2732 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2733 | * return -1. | ||
2734 | * | ||
2735 | * @see eina_model_child_del() | ||
2736 | * @since 1.2 | ||
2737 | */ | ||
2738 | EAPI Eina_Bool eina_model_interface_children_del(const Eina_Model_Interface *iface, | ||
2739 | Eina_Model *model, | ||
2740 | unsigned int position) EINA_ARG_NONNULL(1, 2); | ||
2741 | /** | ||
2742 | * @brief Insert child using @a iface's function to insert children. | ||
2743 | * @param iface The children interface whose insert method will be called. | ||
2744 | * @param model The model instance. | ||
2745 | * @param position Position in which to insert @a child. | ||
2746 | * @param child Value(child) to be inserted. | ||
2747 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2748 | * | ||
2749 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2750 | * return -1. | ||
2751 | * | ||
2752 | * @see eina_model_child_insert_at() | ||
2753 | * @since 1.2 | ||
2754 | */ | ||
2755 | EAPI Eina_Bool eina_model_interface_children_insert_at(const Eina_Model_Interface *iface, | ||
2756 | Eina_Model *model, | ||
2757 | unsigned int position, | ||
2758 | Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4); | ||
2759 | /** | ||
2760 | * @brief Sort children using @a iface's function to sort children. | ||
2761 | * @param iface The children interface whose sort method will be called. | ||
2762 | * @param model The model instance. | ||
2763 | * @param compare Function used to compare children. | ||
2764 | * | ||
2765 | * @warning If either model doesn't implement @a iface will do nothing and | ||
2766 | * return -1. | ||
2767 | * | ||
2768 | * @see eina_model_child_sort(). | ||
2769 | * @since 1.2 | ||
2770 | */ | ||
2771 | EAPI void eina_model_interface_children_sort(const Eina_Model_Interface *iface, | ||
2772 | Eina_Model *model, | ||
2773 | Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3); | ||
2774 | |||
2775 | |||
2776 | /** | ||
2777 | * @} | ||
2778 | */ | ||
2779 | |||
2780 | /** | ||
2781 | * @defgroup Eina_Model_Utils_Group Data Model Utilities | ||
2782 | * | ||
2783 | * Miscellaneous utilities to help usage or debug of @ref Eina_Model_Group. | ||
2784 | * | ||
2785 | * @{ | ||
2786 | */ | ||
2787 | |||
2788 | /** | ||
2789 | * @brief Checks if @a model is an instance of @a type. | ||
2790 | * @param model The model instance. | ||
2791 | * @param type The type being checked for. | ||
2792 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2793 | * | ||
2794 | * @see eina_model_new() | ||
2795 | * @see _Eina_Model_Type | ||
2796 | * @since 1.2 | ||
2797 | */ | ||
2798 | EAPI Eina_Bool eina_model_instance_check(const Eina_Model *model, | ||
2799 | const Eina_Model_Type *type) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2800 | |||
2801 | /** | ||
2802 | * @brief Checks if @a model implements @a iface. | ||
2803 | * @param model The model instance. | ||
2804 | * @param iface The interface being checked for. | ||
2805 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
2806 | * | ||
2807 | * @see _Eina_Model_Interface | ||
2808 | * @since 1.2 | ||
2809 | */ | ||
2810 | EAPI Eina_Bool eina_model_interface_implemented(const Eina_Model *model, const Eina_Model_Interface *iface) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
2811 | |||
2812 | /** | ||
2813 | * @brief Returns the number of references to @a model. | ||
2814 | * @param model The model to query number of references. | ||
2815 | * @return Number of references to model. | ||
2816 | * | ||
2817 | * @see eina_model_ref() | ||
2818 | * @see eina_model_unref() | ||
2819 | * @see eina_model_xref() | ||
2820 | * @see eina_model_xunref() | ||
2821 | * @see eina_model_xrefs_get() | ||
2822 | * @since 1.2 | ||
2823 | */ | ||
2824 | EAPI int eina_model_refcount(const Eina_Model *model) EINA_ARG_NONNULL(1); | ||
2825 | |||
2826 | /** | ||
2827 | * @typedef Eina_Model_XRef | ||
2828 | * Extended reference to model. | ||
2829 | * | ||
2830 | * This is returned by eina_model_xrefs_get() and should never be | ||
2831 | * modified. It is managed by eina_model_xref() and | ||
2832 | * eina_model_xunref() when @c EINA_MODEL_DEBUG is set to "1" or | ||
2833 | * "backtrace". | ||
2834 | * | ||
2835 | * @see #_Eina_Model_XRef explains fields. | ||
2836 | * @since 1.2 | ||
2837 | */ | ||
2838 | typedef struct _Eina_Model_XRef Eina_Model_XRef; | ||
2839 | |||
2840 | /** | ||
2841 | * @struct _Eina_Model_XRef | ||
2842 | * Extended reference to model. | ||
2843 | * | ||
2844 | * This is returned by eina_model_xrefs_get() and should never be | ||
2845 | * modified. It is managed by eina_model_xref() and | ||
2846 | * eina_model_xunref() when @c EINA_MODEL_DEBUG is set to "1" or | ||
2847 | * "backtrace". | ||
2848 | * | ||
2849 | * @see eina_model_xrefs_get() | ||
2850 | * @see eina_models_usage_dump() | ||
2851 | * @since 1.2 | ||
2852 | */ | ||
2853 | struct _Eina_Model_XRef | ||
2854 | { | ||
2855 | EINA_INLIST; | ||
2856 | const void *id; /**< as given to eina_model_xref() */ | ||
2857 | struct { | ||
2858 | const void * const *symbols; /**< only if @c EINA_MODEL_DEBUG=backtrace is set, otherwise is @c NULL */ | ||
2859 | unsigned int count; /**< only if @c EINA_MODEL_DEBUG=backtrace is set, otherwise is 0 */ | ||
2860 | } backtrace; | ||
2861 | char label[]; /**< Any given label given to eina_model_xref(). */ | ||
2862 | }; | ||
2863 | |||
2864 | /** | ||
2865 | * @brief Returns the current references of this model. | ||
2866 | * @param model The model to query references. | ||
2867 | * @return List of reference holders as Eina_Model_XRef. This is the internal | ||
2868 | * list for speed purposes, do not modify or free it in anyway! | ||
2869 | * | ||
2870 | * @note This list only exist if environment variable | ||
2871 | * @c EINA_MODEL_DEBUG is set to "1" or "backtrace". | ||
2872 | * | ||
2873 | * @note The backtrace information is only available if environment | ||
2874 | * variable @c EINA_MODEL_DEBUG=backtrace is set. | ||
2875 | * @since 1.2 | ||
2876 | */ | ||
2877 | EAPI const Eina_Inlist *eina_model_xrefs_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
2878 | |||
2879 | /** | ||
2880 | * @brief Dump usage of all existing modules. | ||
2881 | * @since 1.2 | ||
2882 | */ | ||
2883 | EAPI void eina_models_usage_dump(void); | ||
2884 | |||
2885 | /** | ||
2886 | * @brief Return a list of all live models. | ||
2887 | * @return a newly allocated list of Eina_Model. Free using | ||
2888 | * eina_models_list_free() | ||
2889 | * | ||
2890 | * @note this is meant to debug purposes, do not modify the models in | ||
2891 | * any way! | ||
2892 | * | ||
2893 | * @note due performance reasons, this is only @b enabled when | ||
2894 | * @c EINA_MODEL_DEBUG is set to "1" or "backtrace". | ||
2895 | * | ||
2896 | * @since 1.2 | ||
2897 | */ | ||
2898 | EAPI Eina_List *eina_models_list_get(void); | ||
2899 | |||
2900 | /** | ||
2901 | * @brief Release list returned by eina_models_list_get() | ||
2902 | * @param list the list to release. | ||
2903 | */ | ||
2904 | EAPI void eina_models_list_free(Eina_List *list); | ||
2905 | |||
2906 | /** | ||
2907 | * @} | ||
2908 | */ | ||
2909 | |||
2910 | /** | ||
2911 | * @var EINA_MODEL_INTERFACE_CHILDREN_INARRAY | ||
2912 | * | ||
2913 | * Implements #Eina_Model_Interface_Children | ||
2914 | * (#EINA_MODEL_INTERFACE_NAME_CHILDREN) using #Eina_Inarray. It | ||
2915 | * should be efficient in space and time for most operations. | ||
2916 | * | ||
2917 | * @note it may become slow if eina_model_child_insert_at() is used at(or near) | ||
2918 | * the beginning of the array as the members from that position | ||
2919 | * to the end must be memmove()d. | ||
2920 | * | ||
2921 | * @since 1.2 | ||
2922 | */ | ||
2923 | EAPI extern const Eina_Model_Interface *EINA_MODEL_INTERFACE_CHILDREN_INARRAY; | ||
2924 | |||
2925 | |||
2926 | /** | ||
2927 | * @var EINA_MODEL_TYPE_BASE | ||
2928 | * Base type for all eina model types. | ||
2929 | * | ||
2930 | * @since 1.2 | ||
2931 | */ | ||
2932 | EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_BASE; | ||
2933 | |||
2934 | /** | ||
2935 | * @var EINA_MODEL_TYPE_MIXIN | ||
2936 | * | ||
2937 | * Type that uses #EINA_MODEL_INTERFACE_NAME_PROPERTIES and | ||
2938 | * #EINA_MODEL_INTERFACE_NAME_CHILDREN to manage the model. | ||
2939 | * | ||
2940 | * This is an abstract type, it does not work out of the box as one | ||
2941 | * needs to subclass it and define the interface implementations for | ||
2942 | * properties and children, as done by #EINA_MODEL_TYPE_GENERIC | ||
2943 | * | ||
2944 | * @see EINA_MODEL_TYPE_GENERIC | ||
2945 | * | ||
2946 | * @since 1.2 | ||
2947 | */ | ||
2948 | EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_MIXIN; | ||
2949 | |||
2950 | /** | ||
2951 | * @var EINA_MODEL_TYPE_GENERIC | ||
2952 | * | ||
2953 | * Subclass of #EINA_MODEL_TYPE_MIXIN that uses | ||
2954 | * #EINA_MODEL_INTERFACE_PROPERTIES_HASH and | ||
2955 | * #EINA_MODEL_INTERFACE_CHILDREN_INARRAY. | ||
2956 | * | ||
2957 | * Should be generic enough to hold lots of items with runtime | ||
2958 | * configurable properties of any type. | ||
2959 | * | ||
2960 | * @see #EINA_MODEL_TYPE_STRUCT | ||
2961 | * | ||
2962 | * @since 1.2 | ||
2963 | */ | ||
2964 | EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_GENERIC; | ||
2965 | |||
2966 | /** | ||
2967 | * @var EINA_MODEL_TYPE_STRUCT | ||
2968 | * | ||
2969 | * Subclass of #EINA_MODEL_TYPE_MIXIN that uses | ||
2970 | * #EINA_MODEL_INTERFACE_PROPERTIES_STRUCT and | ||
2971 | * #EINA_MODEL_INTERFACE_CHILDREN_INARRAY. | ||
2972 | * | ||
2973 | * Should be struct enough to hold lots of items with compile time | ||
2974 | * configurable properties of any type. | ||
2975 | * | ||
2976 | * @see #EINA_MODEL_TYPE_GENERIC | ||
2977 | * | ||
2978 | * @since 1.2 | ||
2979 | */ | ||
2980 | EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_STRUCT; | ||
2981 | |||
2982 | /** | ||
2983 | * @brief Create and setup an instance of #EINA_MODEL_TYPE_STRUCT. | ||
2984 | * @param desc struct description to use for properties. | ||
2985 | * @return newly created and set model, or @c NULL on errors. | ||
2986 | * | ||
2987 | * @see eina_model_type_struct_new() | ||
2988 | * @since 1.2 | ||
2989 | */ | ||
2990 | EAPI Eina_Model *eina_model_struct_new(const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
2991 | |||
2992 | /** | ||
2993 | * @brief Create and setup an instance of type subclass of #EINA_MODEL_TYPE_STRUCT. | ||
2994 | * @param type a type which is subclass of #EINA_MODEL_TYPE_STRUCT. | ||
2995 | * @param desc struct description to use for properties. | ||
2996 | * @return newly created and set model, or @c NULL on errors. | ||
2997 | * | ||
2998 | * @see eina_model_struct_new() | ||
2999 | * @since 1.2 | ||
3000 | */ | ||
3001 | EAPI Eina_Model *eina_model_type_struct_new(const Eina_Model_Type *type, | ||
3002 | const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_MALLOC; | ||
3003 | |||
3004 | |||
3005 | /** | ||
3006 | * @brief Configure the internal properties of model implementing #EINA_MODEL_INTERFACE_PROPERTIES_STRUCT. | ||
3007 | * @param model The model instance to configure. | ||
3008 | * @param desc The structure description to use. | ||
3009 | * @param memory If not @c NULL, will be copied by model. | ||
3010 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
3011 | * | ||
3012 | * This will setup the internal pointers so that the given @a desc is | ||
3013 | * used to manage the properties of this struct. | ||
3014 | * | ||
3015 | * If a given memory is provided, it will be copied (including | ||
3016 | * members) and no references are taken after this function returns. | ||
3017 | * | ||
3018 | * @see #EINA_VALUE_TYPE_STRUCT | ||
3019 | * | ||
3020 | * @since 1.2 | ||
3021 | */ | ||
3022 | EAPI Eina_Bool eina_model_struct_set(Eina_Model *model, | ||
3023 | const Eina_Value_Struct_Desc *desc, | ||
3024 | void *memory) EINA_ARG_NONNULL(1, 2); | ||
3025 | /** | ||
3026 | * @brief Get the internal properties of model implementing #EINA_MODEL_INTERFACE_PROPERTIES_STRUCT. | ||
3027 | * @param model the model instance. | ||
3028 | * @param p_desc where to return the structure description in use. | ||
3029 | * @param p_memory where to return the structure memory in use. | ||
3030 | * @return #EINA_TRUE on success, #EINA_FALSE on failure. | ||
3031 | * | ||
3032 | * No copies are made! The memory and description may be invalidaded | ||
3033 | * by calls to eina_model_struct_set() or eina_model_del(). | ||
3034 | * | ||
3035 | * @since 1.2 | ||
3036 | */ | ||
3037 | EAPI Eina_Bool eina_model_struct_get(const Eina_Model *model, | ||
3038 | const Eina_Value_Struct_Desc **p_desc, | ||
3039 | void **p_memory) EINA_ARG_NONNULL(1, 2); | ||
3040 | |||
3041 | /** | ||
3042 | * @var EINA_MODEL_INTERFACE_NAME_PROPERTIES | ||
3043 | * | ||
3044 | * Interface that uses #Eina_Model_Interface_Properties as | ||
3045 | * #Eina_Model_Interface and can manage the model properties. | ||
3046 | * | ||
3047 | * @since 1.2 | ||
3048 | */ | ||
3049 | EAPI extern const char *EINA_MODEL_INTERFACE_NAME_PROPERTIES; | ||
3050 | |||
3051 | /** | ||
3052 | * @var EINA_MODEL_INTERFACE_PROPERTIES_HASH | ||
3053 | * | ||
3054 | * Implements #Eina_Model_Interface_Properties | ||
3055 | * (#EINA_MODEL_INTERFACE_NAME_PROPERTIES) using #Eina_Hash. | ||
3056 | * | ||
3057 | * @note This function is generic but uses too much space given the | ||
3058 | * hash data type. For huge number of elements it's better to | ||
3059 | * use custom implementation instead. | ||
3060 | * | ||
3061 | * @see EINA_MODEL_INTERFACE_PROPERTIES_STRUCT | ||
3062 | * | ||
3063 | * @since 1.2 | ||
3064 | */ | ||
3065 | EAPI extern const Eina_Model_Interface *EINA_MODEL_INTERFACE_PROPERTIES_HASH; | ||
3066 | |||
3067 | /** | ||
3068 | * @var EINA_MODEL_INTERFACE_PROPERTIES_STRUCT | ||
3069 | * | ||
3070 | * Implements #Eina_Model_Interface_Properties | ||
3071 | * (#EINA_MODEL_INTERFACE_NAME_PROPERTIES) using #Eina_Value_Struct. | ||
3072 | * | ||
3073 | * The interface private data is #Eina_Value of type | ||
3074 | * #EINA_VALUE_TYPE_STRUCT. Properties will be accessed using | ||
3075 | * Eina_Value_Struct::desc information that can be set by types such | ||
3076 | * as #EINA_MODEL_TYPE_STRUCT | ||
3077 | * | ||
3078 | * @see EINA_MODEL_INTERFACE_PROPERTIES_HASH | ||
3079 | * | ||
3080 | * @since 1.2 | ||
3081 | */ | ||
3082 | EAPI extern const Eina_Model_Interface *EINA_MODEL_INTERFACE_PROPERTIES_STRUCT; | ||
3083 | |||
3084 | /** | ||
3085 | * @var EINA_MODEL_INTERFACE_NAME_CHILDREN | ||
3086 | * | ||
3087 | * Interface that uses #Eina_Model_Interface_Children as | ||
3088 | * #Eina_Model_Interface and can manage the model children. | ||
3089 | * | ||
3090 | * @since 1.2 | ||
3091 | */ | ||
3092 | EAPI extern const char *EINA_MODEL_INTERFACE_NAME_CHILDREN; | ||
3093 | |||
3094 | /** | ||
3095 | * @} | ||
3096 | */ | ||
3097 | |||
3098 | /** | ||
3099 | * @} | ||
3100 | */ | ||
3101 | |||
3102 | /** | ||
3103 | * @} | ||
3104 | */ | ||
3105 | #endif | ||