summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_model.h
blob: b6229c1ce5692c0d4f7eab6d3b6aad56469762cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
/* EINA - EFL data type library
 * Copyright (C) 2012 ProFUSION embedded systems
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_MODEL_H_
#define EINA_MODEL_H_

#include "eina_types.h"
#include "eina_value.h"
#include "eina_inlist.h"
#include <stdarg.h>

/**
 * @page eina_model_01_c Eina_Model inheritance and function overriding
 * @include eina_model_01.c
 */

/**
 * @page eina_model_04_c Eina_Model inheritance, interfaces, and function overriding
 * @include eina_model_04_main.c
 * @include eina_model_04_animal.c
 * @include eina_model_04_human.c
 * @include eina_model_04_parrot.c
 * @include eina_model_04_child.c
 * @include eina_model_04_main.c
 * @include eina_model_04_whistler.c
 * @include eina_model_04_animal.h
 * @include eina_model_04_human.h
 * @include eina_model_04_whistler.h
 * @include eina_model_04_child.h
 * @include eina_model_04_parrot.h
 */

/**
 * @page eina_model_02_example_page Creating a simple model
 * @dontinclude eina_model_02.c
 *
 * This example shows the creation of a model with five properties, named:
 * 'a', 'b', 'c', 'd' and 'e' with values 0, 1, 2, 3 and 4
 * respectively. In addition to the 5 properties our model also add 5 children,
 * and to each child we give a property named 'x' with a value of 1, 2, 3, 4 and
 * 5.
 *
 * In other words this piece of code shows how to use eina_model to store a list
 * of elements, given that the list itself has some properties.
 *
 * Now let's walk through the code and examine the interesting bits.
 *
 * This is some pretty standard initialization code.
 * @until eina_init
 *
 * We now create our eina_model, the important detail here is the type of the
 * model being created, for this example we use the generic type provided by
 * eina:
 * @until model_new
 *
 * Once our model has been created we can add callbacks to be notified of events
 * that happen to our model, for this example we are just going to add a
 * callback for the "delete" event. To get a list of events a given eina model
 * can emit see @ref eina_model_event_names_list_get().
 * @until callback_add
 *
 * Once we have a model, we need to populate it with information. There are two
 * types of information we can store on an eina model: properties and eina
 * models. We are going to start by looking at properties.
 *
 * Properties are, simply put, named values. They have a char* identifier and an
 * Eina_Value value. This means you can store in a property almost any type of
 * data. For this example we are going to add some very simple numeric
 * properties which will have single letter identifiers.
 * @until }
 * @until }
 *
 * Despite being able to store almost any value properties the least flexible
 * information unit we can put in an eina model. We can add eina models to our
 * eina model, this allows us to represt complex information hierarchies. This
 * example adds 5 models(with no children of their own) to our parent model @c
 * m.
 * @until }
 * The code here should be pretty easy to understand, we create a model, much
 * like we did before, and we then add a property to our model, again a task we
 * have already done.
 *
 * The important issue to note here is that we could have given each of our @c c
 * child models as complex an structure as we needed, they could each be a list
 * or a tree on their own right.
 *
 * Now that we have a populated model we print a string representation of
 * it(without forgetting to free the string):
 * @until free
 *
 * And since we are done using our model we release our reference to it(and
 * since no else holds references to it, it will be freed):
 * @until }
 *
 * Note that we don't need to iterate over the children of @c m unrefing it,
 * this is because we don't hold references to it, we freed our references right
 * after we added them to their parent model, so when the parent model dies(and
 * releases the references to it's children) they will be freed.
 *
 * The only thing we are going to look at is the callback we registered for
 * whenever a model is deleted, since our models don't do anything fancy we are
 * just going to print the memory address of the model being freed.
 * @until }
 *
 * Note that this means the memory address is still valid, our callback is
 * called just before the memory is freed so we could still access its
 * information here.
 *
 * The full code can be seen in @ref eina_model_02_c
 */

/**
 * @page eina_model_02_c eina_model_02.c
 * @include eina_model_02.c
 * @example eina_model_02.c
 */

/**
 * @page eina_model_03_example_page Using Eina_Model and inheritance
 * @dontinclude eina_model_03.c
 *
 * This example will use two custom defined eina model types: @c PERSON_TYPE to
 * represent a person and @c ADDRESS_BOOK_TYPE to represent the an address book.
 * Both our types inherit from EINA_MODEL_TYPE_STRUCT, and, therefore,
 * store it's data on a struct. Our address book will be very simple it will
 * only contain one property, the name of the file where we store our address
 * book. The person type will contain two fields a name and en email. Let's look
 * at the code.
 *
 * We'll start with declaring the variables and functions we'll need to define
 * our custom type. This will all be explained when the variables get used.
 * @until address_book_init
 *
 * We then jump into our @c main function, declare a couple of variables and
 * initialize eina:
 * @until eina_init
 *
 * After eina is initialized we'll @c address_book_init() which will initialize
 * both our @c PERSON_TYPE and our @c ADDRESS_BOOK_TYPE. Details of this will be
 * shown latter on:
 * @until address_book_init
 *
 * Now that everything is correctly initialized we can create the model that
 * will represent our address book's
 * @until eina_model_new
 *
 * Before we can load data into our model we need to tell it where to load from,
 * we do this by setting it's filename property:
 * @until value_flush
 *
 * We then load data into our model and display it as a string:
 * @until free
 *
 * While @c eina_model_to_string allows you to see the contents of the model,
 * it's display format is not user friendly, it's best used for debugging. So
 * let's now print our model in a user friendly way.
 *
 * First we see how many people are in our address book and print that:
 * @until printf
 *
 * And now we iterate over every child of our address book model, which
 * represents a person:
 * @until person
 *
 * But again simply calling @c eina_model_to_string would result in not very
 * user friendly output, so we'll need to get the properties of the person(name
 * and email) and print them with some formatting:
 * @until printf
 *
 * We then free the resources we allocated to print this person:
 * @until }
 *
 * And that's it for our main function, now just freeing our resources:
 * @until }
 *
 * This however obviously doesn't conclude our example we need to examine how
 * the the loading of data works to really understand what is happening in the
 * @c main function.
 *
 * Let's start with the constructors(and the variables they use). Both our
 * constructors do two very important tasks:
 * @li Calls our parent's constructor, and
 * @li Sets the description of the struct on our model
 *
 * For these constructors that's all we need to do since most of our
 * functionality is provided by @c EINA_MODEL_TYPE_STRUCT.
 * @until }
 * @until }
 *
 * And now we have our load function, it opens the file from which we'll
 * read the address book:
 * @until EINA_SAFETY_ON_NULL_RETURN_VAL
 *
 * Once the file has been opened we read from it line by line and for each
 * non-blank line we get a name and an email:
 * @until email
 * @until email
 *
 * Once we have the name and email we create our person model, set it's
 * properties and make our person a child of the address book:
 * @until }
 *
 * And now that we're done reading the file we close it:
 * @until }
 *
 * This next function is perphaps the most interesting one of our example, it's
 * the one that creates the definition of our derived types.
 *
 * First thing we'll do is the description of the members of our person type.
 * @until person_members[1].type
 * Now the description of the struct itself(which uses the members):
 * @until }
 * And finally we define the person type itself:
 * @until person_type.constructor
 *
 * With the person now described we'll do the same process for our address book
 * type:
 * @until address_book_type.load
 *
 * So far everything we created has been in the scope of our function to make
 * this available outside(such as in the @c main function where we use @c
 * ADDRESS_BOOK_TYPE and on @c _address_book_load function where we use @c
 * PERSON_TYPE) we need to assign our descriptions and type to global variables:
 * @until }
 *
 * This concludes this example. A good exercise for the reader is to extend this
 * example to have the model save the addres book, for example once it's
 * unloaded, this can be done by overriding the .unload property of @c
 * ADDRESS_BOOK_TYPE.
 *
 * For the full code see: @ref eina_model_03_c
 */

/**
 * @page eina_model_03_c eina_model_03.c
 * @include eina_model_03.c
 * @example eina_model_03.c
 */

/**
 * @addtogroup Eina_Data_Types_Group Data Types
 *
 * @since 1.2
 *
 * @{
 */

/**
 * @addtogroup Eina_Containers_Group Containers
 *
 * @{
 */

/**
 * @defgroup Eina_Model_Group Data Model API
 *
 * Abstracts data access to hierarchical data in an efficient way,
 * extensible to different backing stores such as database or remote
 * access.
 *
 * It is heavily based on #Eina_Value, as properties are exchanged
 * using this data type as interface, although internally models may
 * store them as they want. See @ref Eina_Value_Group.
 *
 * Although extensible and easy to optimize, a simple generic type is
 * provided as #EINA_MODEL_TYPE_GENERIC. It is recommended that people
 * use it during development, get the logic right and just then
 * optimize what is needed (properties or children management).
 *
 * Not as generic as #EINA_MODEL_TYPE_GENERIC, but way more efficient
 * is #EINA_MODEL_TYPE_STRUCT that instead of a hash of properties of
 * any type, it uses a struct to map properties. Its properties are
 * fixed set of names and they have fixed type, as defined by
 * the #Eina_Value_Struct_Desc description used internally.
 *
 * Examples:
 * @li @ref eina_model_01_c inheritance example, uses #EINA_MODEL_TYPE_GENERIC
 * @li @ref eina_model_02_example_page contains an easy to follow
 *     example that demonstrates several of the important features of
 *     eina_model, uses #EINA_MODEL_TYPE_GENERIC.
 * @li @ref eina_model_03_example_page walk-through example on how to
 *     inherit types, a suggestion of eina_model_load() usage and
 *     uses #EINA_MODEL_TYPE_STRUCT.
 * @li @ref eina_model_04_c Advanced inheritance, interfaces and interface
 *     function overloading example.
 *
 * @{
 */

EAPI extern Eina_Error EINA_ERROR_MODEL_FAILED;
EAPI extern Eina_Error EINA_ERROR_MODEL_METHOD_MISSING;

/**
 * @typedef Eina_Model
 * Data Model Object.
 *
 * This is an opaque handle that is created with eina_model_new() and
 * released with eina_model_unref().
 *
 * It contains properties, children and may emit events. See
 * respectively:
 * @li eina_model_property_get() and eina_model_property_set()
 * @li eina_model_child_get() and eina_model_child_set()
 * @li eina_model_event_names_list_get(), eina_model_event_callback_add() and eina_model_event_callback_del()
 *
 * @see eina_model_new()
 * @see eina_model_ref() and eina_model_xref()
 * @see eina_model_unref(), eina_model_xunref() and eina_model_del()
 * @see eina_model_type_get() and eina_model_interface_get()
 * @since 1.2
 */
typedef struct _Eina_Model Eina_Model;

/**
 * @typedef Eina_Model_Type
 * Data Model Type.
 *
 * @see #_Eina_Model_Type explains fields.
 * @since 1.2
 */
typedef struct _Eina_Model_Type Eina_Model_Type;

/**
 * @typedef Eina_Model_Interface
 * Data Model Interface.
 *
 * @see #_Eina_Model_Interface explains fields.
 * @since 1.2
 */
typedef struct _Eina_Model_Interface Eina_Model_Interface;

/**
 * @typedef Eina_Model_Event_Description
 * Data Model Event Description.
 *
 * This is used to declare events supported by types and interfaces
 * and also to provide introspection to receivers of signals so they
 * can know which data they are receiving as @c event_info.
 *
 * @see EINA_MODEL_EVENT_DESCRIPTION()
 * @see #EINA_MODEL_EVENT_DESCRIPTION_SENTINEL
 * @see #_Eina_Model_Event_Description explains fields.
 * @since 1.2
 */
typedef struct _Eina_Model_Event_Description Eina_Model_Event_Description;

/**
 * @brief Creates a new model of type @a Type.
 * @param type The type of the model to create.
 * @return If successfull pointer to model, @c NULL otherwise.
 *
 * @see _Eina_Model_Type
 * @see eina_model_del()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_new(const Eina_Model_Type *type);
/**
 * @brief Frees the memory associated with @a model
 * @param model The model instance.
 *
 * @see eina_model_new()
 * @since 1.2
 */
EAPI void eina_model_del(Eina_Model *model);

/**
 * @brief Returns the type of @a model.
 * @param model The model instance.
 * @return The type of @a model.
 *
 * @see eina_model_new()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI const Eina_Model_Type *eina_model_type_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;

/**
 * @brief Returns the interface named @a name of @a model.
 * @param model The model instance.
 * @param name Name of interface to get.
 * @return If successfull requested interface, @c NULL otherwise.
 *
 * The name of every interface of @a model will be compared to @a name, the
 * first one to match will be returned.
 *
 * @see eina_model_new()
 * @see _Eina_Model_Interface
 * @since 1.2
 */
EAPI const Eina_Model_Interface *eina_model_interface_get(const Eina_Model *model,
                                                          const char *name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE;

/**
 * @brief Increases the refcount of @a model.
 * @param model The model to increase reference.
 * @return The @a model with reference increased.
 * @return If successfull pointer to model, @c NULL otherwise.
 *
 * @see eina_model_new()
 * @see eina_model_unref()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_ref(Eina_Model *model) EINA_ARG_NONNULL(1);

/**
 * @brief Increases the refcount of @a model, informs reference identifier.
 * @param model The model to increase reference.
 * @param id An identifier to mark this reference.
 * @param label An optional label to help debug, may be @c NULL.
 * @return The @a model with reference increased.
 *
 * This extended version of reference explicitly marks the origin of
 * the reference and eina_model_xunref() should be used to check and
 * remove it.
 *
 * Usually the @a id is another object, like a parent object, or some
 * class/structure/file/function that is holding the reference for
 * some reason.
 *
 * Its purpose is to help debuging if Eina was compiled with model
 * usage debug enabled and environment variable @c EINA_MODEL_DEBUG=1
 * is set.
 *
 * It is recommended to use eina_model_xref() and eina_model_xunref()
 * pair whenever you want to be sure you released your
 * references. Both at your own type, or using applications. As an
 * example #EINA_MODEL_INTERFACE_CHILDREN_INARRAY will use this to
 * make sure it deleted every managed children.
 *
 * In order to debug leaks, consider using eina_model_xrefs_get() or
 * eina_models_usage_dump() for a global picture. However, some
 * references are not tracked, namely:
 *
 * @li eina_model_new()
 * @li eina_model_child_get()
 * @li eina_model_child_iterator_get()
 * @li eina_model_child_reversed_iterator_get()
 * @li eina_model_child_sorted_iterator_get()
 * @li eina_model_child_filtered_iterator_get()
 * @li eina_model_child_slice_iterator_get()
 * @li eina_model_child_slice_reversed_iterator_get()
 * @li eina_model_child_slice_sorted_iterator_get()
 * @li eina_model_child_slice_filtered_iterator_get()
 *
 * @note this function is slower than eina_model_ref() if
 *       @c EINA_MODEL_DEBUG is set to "1" or "backtrace". Otherwise it
 *       should have the same performance cost.
 *
 * @see eina_model_ref()
 * @see eina_model_xunref()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_xref(Eina_Model *model,
                                 const void *id,
                                 const char *label) EINA_ARG_NONNULL(1, 2);

/**
 * @brief Decreases the refcount of @a model.
 * @param model The model to decrease reference.
 * @return If successfull pointer to model, @c NULL otherwise.
 *
 * After this function returns, consider @a model pointer invalid.
 *
 * @see eina_model_ref()
 * @see eina_model_del()
 * @since 1.2
 */
EAPI void eina_model_unref(Eina_Model *model) EINA_ARG_NONNULL(1);

/**
 * @brief Decreases the refcount of @a model, informs reference identifier.
 * @param model The model to decrease reference.
 * @param id An identifier to mark this reference.
 * @return If successfull pointer to model, @c NULL otherwise.
 *
 * This function will match eina_model_xref() and the @a id must match
 * a previously call, otherwise it will produce an error if @c
 * EINA_MODEL_DEBUG is set to "1" or "backtrace", and the reference is
 * not decreased!
 *
 * After this function returns, consider @a model pointer invalid.
 *
 * @note this function is slower than eina_model_unref() if
 *       @c EINA_MODEL_DEBUG is set to "1" or "backtrace". Otherwise it
 *       should have the same performance cost.
 *
 * @see eina_model_xref()
 * @since 1.2
 */
EAPI void eina_model_xunref(Eina_Model *model,
                            const void *id) EINA_ARG_NONNULL(1, 2);



/**
 * @defgroup Eina_Model_Event_Group Data Model Events
 * Events and their usage with models.
 *
 * Events are specified by each type and interface level
 * using #Eina_Model_Event_Description. One can know all events supported
 * by a model with eina_model_event_names_list_get() and then
 * eina_model_event_description_get() to retrieve details.
 *
 * By default the following events are supported in every object:
 * @li deleted: last reference was released or eina_model_del() was called.
 * @li freed: memory was destroyed, destructors were called.
 * @li property,set: eina_model_property_set() was done.
 * @li property,deleted: eina_model_property_del() was done.
 * @li children,changed: children was changed somehow (added, modified, deleted)
 * @li child,inserted: new child was added (eina_model_child_append() or eina_model_child_insert_at())
 * @li child,set: child was replaced (eina_model_child_set())
 * @li child,deleted: eina_model_child_del() was done.
 * @li loaded: eina_model_load() was done.
 * @li unloaded: eina_model_unload() was done.
 *
 * Mix-in interfaces may emit these:
 * @li properties,loaded
 * @li properties,unloaded
 * @li children,loaded
 * @li children,unloaded
 *
 * One can be notified of events with eina_model_event_callback_add().
 *
 * Types emit these events with eina_model_event_callback_call(),
 * these are handled asynchronously unless event is frozen with
 * eina_model_event_callback_freeze() is blocking it. In this case the
 * events are ignored. Usually this is used in some cases that want to
 * avoid storm of events in batch operations.
 *
 * @{
 */

/**
 * @typedef Eina_Model_Event_Cb
 * Notifies of events in this model.
 *
 * @since 1.2
 */
typedef void (*Eina_Model_Event_Cb)(void *data, Eina_Model *model, const Eina_Model_Event_Description *desc, void *event_info);

/**
 * @brief Add a callback to be called when @a event_name is emited.
 * @param model The model instance.
 * @param event_name The name of event for which @a cb will be called.
 * @param cb The function to be called.
 * @param data Data @a cb will be called with. May be @c NULL.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see eina_model_event_callback_del()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_event_callback_add(Eina_Model *model,
                                             const char *event_name,
                                             Eina_Model_Event_Cb cb,
                                             const void *data) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Remove a callback that was to be called when @a event_name was emited.
 * @param model The model instance.
 * @param event_name The name of event for which to delete callback.
 * @param cb The function given to eina_model_event_callback_add().
 * @param data Data given to eina_model_event_callback_add(). A @c NULL value means
 * every @a data will not be compared.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see eina_model_event_callback_add()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_event_callback_del(Eina_Model *model,
                                             const char *event_name,
                                             Eina_Model_Event_Cb cb,
                                             const void *data) EINA_ARG_NONNULL(1, 2, 3);

/**
 * @brief Returns a description of the event named @c event_name
 * @param model The model instance.
 * @param event_name Name of event whose description is wanted.
 * @return Description of event.
 *
 * @see Eina_Model_Event_Description
 * @since 1.2
 */
EAPI const Eina_Model_Event_Description *eina_model_event_description_get(const Eina_Model *model,
                                                                           const char *event_name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE;

/**
 * @brief Returns list of events this model may emit.
 * @param model The model whose events are to be listed.
 * @return An Eina_List of stringshares with the name of every event. Free the
 * list with eina_model_event_names_list_free().
 *
 * @since 1.2
 */
EAPI Eina_List *eina_model_event_names_list_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
/**
 * @brief Frees the list of event's names gotten from
 * eina_model_event_names_list_get().
 * @param list The list to free.
 *
 * @see eina_model_event_names_list_get()
 * @since 1.2
 */
EAPI void eina_model_event_names_list_free(Eina_List *list);

/**
 * @brief Calls every callback associated to @a name on model @a model with @a
 * event_info.
 * @param model The model instance.
 * @param name The event whose callbacks will be called.
 * @param event_info The data given to the callback as event_info. May be @c NULL.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see eina_model_event_callback_add()
 * @see eina_model_event_callback_del()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_event_callback_call(Eina_Model *model,
                                              const char *name,
                                              const void *event_info) EINA_ARG_NONNULL(1, 2);

/**
 * @brief Makes @a model not call the callbacks associated with @a name.
 * @param model The model instance.
 * @param name The event whose callbacks are to be frozen.
 * @return Count of freezes called on this event.
 *
 * @see eina_model_event_callback_call()
 * @see eina_model_event_callback_thaw()
 * @since 1.2
 */
EAPI int eina_model_event_callback_freeze(Eina_Model *model,
                                          const char *name) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Makes @a model able to call the callbacks associated with @a name.
 * @param model The model instance.
 * @param name The event whose callbacks are to be frozen.
 * @return Count of freezes still valid in this event.
 *
 * @warning Behavior is undefined if called on a @a model, @a name not frozen.
 *
 * @see eina_model_event_callback_call()
 * @see eina_model_event_callback_freeze()
 * @since 1.2
 */
EAPI int eina_model_event_callback_thaw(Eina_Model *model,
                                        const char *name) EINA_ARG_NONNULL(1, 2);

/**
 * @}
 */


/**
 * @brief Makes a shallow copy of @a model.
 * @param model The model instance.
 * @return Copied model.
 *
 * The returned model will have a copy of the properties of @a model and a
 * reference to the children of @a model.
 *
 * @see eina_model_deep_copy()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_copy(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC;
/**
 * @brief Makes a deep(complete) copy of @a model.
 * @param model The model instance.
 * @return Copied model.
 *
 * The returned model will have a copy of the properties of @a model, its
 * children will be created by making a deep copy of the children of @a model.
 *
 * @see eina_model_copy()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_deep_copy(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC;

/**
 * @brief Compares two models.
 * @param a The first model to compare.
 * @param b The second model to compare.
 * @return Greater than zero if @a a > @a b, zero if @a a == @a b and less than
 * zero if @a a < @a b
 *
 * The default comparison checks that the properties of @a a and @a b all have
 * the same name and value, and then recursively compares all children.
 *
 * A model with less properties or children is considered smaller than one with
 * more properties.
 *
 * @since 1.2
 */
EAPI int eina_model_compare(const Eina_Model *a, const Eina_Model *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2);

/**
 * @brief Loads the @a model's data.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * By convention this means loading data from an external source and populating
 * the models properties and children with it. For example in the case of file
 * system backed model, this means opening the relevant files and reading the
 * data from them(creating the properties and children from it).
 * @warning This convention should be followed, but no guarantees of behaviour
 * by user defined types can be given.
 *
 * @note The types provided by Eina_Model don't implement this method.
 * @note Calling this function on a model that doesn't implement it
 * returns #EINA_TRUE without any effect on @a model.
 *
 * @see eina_model_unload()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_load(Eina_Model *model) EINA_ARG_NONNULL(1);
/**
 * @brief Unloads the @a model's data.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * By convention this means releasing data gotten from an external source. For
 * example of a database backed model this might mean releasing the iterator for
 * the currently loaded data or deleting a temporary table.
 * @warning This convention should be followed, but no guarantees of behaviour
 * by user defined types can be given.
 *
 * @note The types provided by Eina_Model don't implement this method.
 * @note Calling this function on a model that doesn't implement it
 * returns #EINA_TRUE without any effect on @a model.
 *
 * @see eina_model_load()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_unload(Eina_Model *model) EINA_ARG_NONNULL(1);


/**
 * @defgroup Eina_Model_Properties_Group Data Model Properties
 * Properties and their usage with models.
 *
 * Properties are attributes of model. They have a name and contain a
 * data value (@ref Eina_Value_Group).
 *
 * The actual values and their types, if it is possible to read and
 * write them and if new properties can be created or deleted it is up
 * to the type.
 *
 * @{
 */
/**
 * @brief Gets the value of @a model's property named @a name.
 * @param[in] model The model from which to get the property.
 * @param[in] name The name of the property whose value is wanted.
 * @param[out] value A pointer to an Eina_Value to receive the property's value.
 * @return #EINA_TRUE if @a model has a property named @a name, #EINA_FALSE
 * otherwise.
 *
 * @see eina_model_property_set()
 * @see eina_model_property_del()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_property_get(const Eina_Model *model,
                                       const char *name,
                                       Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Sets the value of @a model's property named @a name to @a value.
 * @param model The model in which to set the property.
 * @param name The name of the property whose value is to set.
 * @param value A pointer to a const Eina_Value to containing the property's
 * value.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see eina_model_property_get()
 * @see eina_model_property_del()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_property_set(Eina_Model *model,
                                       const char *name,
                                       const Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Deletes @a model's property named @a name.
 * @param model The model from which to delete the property.
 * @param name The name of the property to delete.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see eina_model_property_set()
 * @see eina_model_property_get()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_property_del(Eina_Model *model,
                                       const char *name) EINA_ARG_NONNULL(1, 2);

/**
 * @brief Gets a list of the names of every property of @a model.
 * @param model The model instance.
 * @return #Eina_List of names.
 *
 * @note The returned list should be freed with @c
 * eina_model_properties_names_list_free().
 *
 * @see eina_model_properties_names_list_free()
 * @see eina_model_property_get()
 * @since 1.2
 */
EAPI Eina_List *eina_model_properties_names_list_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
/**
 * @brief Frees a list of names of properties gotten with @c
 * eina_model_properties_names_list_get().
 * @param list The list to free.
 *
 * @warning Behavior is undefined if called on a list not gotten from @c
 * eina_model_properties_names_list_get().
 *
 * @see eina_model_properties_names_list_get()
 * @see eina_model_property_get()
 * @since 1.2
 */
EAPI void eina_model_properties_names_list_free(Eina_List *list);

/**
 * @}
 */

/**
 * @defgroup Eina_Model_Children_Group Data Model Children
 * Children and their usage with models.
 *
 * Children are other model instances that are kept sequentially in
 * the model. They are accessed by their integer index within the
 * model. Their index may change if child are inserted or deleted
 * before them, as in an array.
 *
 * @{
 */

/**
 * @brief Returns the number of child models in @a model.
 * @param model The model instance.
 * @return Number of children in @a model.
 *
 * @see eina_model_child_append()
 * @see eina_model_child_get()
 * @see eina_model_child_del()
 * @since 1.2
 */
EAPI int eina_model_child_count(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Get the child at a given position from a model.
 * @param model the model instance.
 * @param position index of child to get.
 * @return child instance with reference @b increased, or @c NULL on error.
 *
 * The given @a position must be valid, otherwise it may fail and
 * return @c NULL, one should check for a valid position with
 * eina_model_child_count().
 *
 * @warning The returned model has its reference increased, you must release it
 * with eina_model_unref(). This convention is imposed to avoid the
 * object being removed before the caller function has time to use it.
 */
EAPI Eina_Model *eina_model_child_get(const Eina_Model *model,
                                      unsigned int position) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Set the child at a given position from a model.
 * @param model the model instance.
 * @param position index of child to set.
 * @param child the child to use at given position.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * The given @a position must be valid, otherwise it may fail and
 * return #EINA_FALSE, one should check for a valid position with
 * eina_model_child_count().
 *
 * The existing child is replaced. Its reference will be decreased
 * automatically. To insert a new item instead of replacing, use
 * eina_model_child_insert_at() or eina_model_child_append().
 *
 * The given model will be adopted by @a model, that is, the @a child
 * will have its reference increased if this call succeeds.
 *
 * @see eina_model_child_append()
 * @see eina_model_child_insert_at()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_child_set(Eina_Model *model,
                                    unsigned int position,
                                    Eina_Model *child) EINA_ARG_NONNULL(1, 3);

/**
 * @brief Deletes the child model in @a position-th of @a model.
 * @param model The model instance.
 * @param position The position of the child to be deleted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning This decrements the reference count of the child being deleted,
 * which may, or not, cause it to be deconstructed and freed.
 *
 * @see eina_model_child_append()
 * @see eina_model_child_get()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_child_del(Eina_Model *model,
                                    unsigned int position) EINA_ARG_NONNULL(1);

/**
 * @brief Insert @a child in the @a position-th of the list of children of @a
 * model.
 * @param model The model instance.
 * @param position Position in which to insert child.
 * @param child The child to be inserted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning This increments the reference count of the child being inserted, if
 * it will no longer be used by the inserting code it should call
 * eina_model_unref() on it.
 *
 * @see eina_model_child_append()
 * @see eina_model_child_set()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_child_insert_at(Eina_Model *model,
                                          unsigned int position,
                                          Eina_Model *child) EINA_ARG_NONNULL(1, 3);

/**
 * @brief Appends @a child in @a model.
 * @param model The model instance.
 * @param child The child to be appended.
 * @return The position of the added child, or @c -1 on failure.
 *
 * @warning This increments the reference count of the child being inserted, if
 * it will no longer be used by the inserting code it should call
 * eina_model_unref() on it.
 *
 * @see eina_model_child_insert_at()
 * @see eina_model_child_set()
 * @since 1.2
 */
EAPI int eina_model_child_append(Eina_Model *model,
                                 Eina_Model *child) EINA_ARG_NONNULL(1, 2);

/**
 * @brief Returns the position of @a other amongst the children of @a model.
 * @param model The parent model whose children will be searched.
 * @param start_position The first children to be compared with @a other.
 * @param other The model whose position is desired.
 * @return The position of the searched for child, or @c -1 if not found.
 *
 * @since 1.2
 */
EAPI int eina_model_child_find(const Eina_Model *model,
                               unsigned int start_position,
                               const Eina_Model *other) EINA_ARG_NONNULL(1, 3) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Returns the position of a child of @a model that mathes the criteria.
 * @param model The model whose children will be searched.
 * @param start_position The position of the first child to be checked.
 * @param match The function used to check if a child matches the criteria.
 * @param data Data given the to the @a match function.
 * @return The position of the first child to match the criteria or @c -1 if no
 * child matches it.
 *
 * Returns the position of the first(from @a start_position) child of @a model
 * to which @a match returns #EINA_TRUE.
 *
 * @since 1.2
 */
EAPI int eina_model_child_criteria_match(const Eina_Model *model,
                                         unsigned int start_position,
                                         Eina_Each_Cb match,
                                         const void *data) EINA_ARG_NONNULL(1, 3) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Sorts the children of @a model according to @a compare.
 * @param model The model instance.
 * @param compare The function to be used in the comparison.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * The @a compare function receives to const pointer to eina models(const
 * *Eina_Model).
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_child_sort(Eina_Model *model,
                                     Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2);

/**
 * @}
 */

/**
 * @defgroup Eina_Model_Iterators_Group Data Model Iterators
 * Iterators and their usage with models.
 *
 * One of the most common tasks of models is to iterate over their
 * children, either forwards or backwards, filtering by some criteria
 * or a different ordering function.
 *
 * @{
 */

/**
 * @brief create an iterator that outputs a child model on each iteration.
 * @param model the model instance.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @code
 *  Eina_Model *child;
 *  Eina_Iterator *it = eina_model_child_iterator_get(model);
 *  EINA_ITERATOR_FOREACH(it, child)
 *    {
 *       use_child(child);
 *       eina_model_unref(child);
 *    }
 *  eina_iterator_free(it);
 * @endcode
 * This code shows how to use iterators to do something (in this example call
 * use_child()) on every child element.
 *
 * @warning Each iteration(call to eina_iterator_next()) gives a child model
 * with reference @b increased! You must call eina_model_unref() after you're
 * done with it.
 *
 * @see eina_model_child_slice_iterator_get()
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_sorted_iterator_get()
 * @see eina_model_child_filtered_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_iterator_get(Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
/**
 * @brief Gets an iterator to a slice of @a model's children.
 * @param model The model whose children to iterate over.
 * @param start The first child included in the iterator.
 * @param count The number of children included in the iterator.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning Each iteration(call to eina_iterator_next()) gives a child model
 * with reference @b increased! You must call eina_model_unref() after you're
 * done with it.
 *
 * @see eina_model_child_iterator_get()
 * @see eina_model_child_slice_reversed_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_slice_iterator_get(Eina_Model *model,
                                                        unsigned int start,
                                                        unsigned int count) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;

/**
 * @brief create an iterator that outputs a child model in reversed order.
 * @param model the model instance.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * Each iteration output a child model with reference @b increased!
 * You must call eina_model_unref() after you're done with it.
 *
 * The order is reversed, that is, the last element is outputted first.
 *
 * @code
 *  Eina_Model *child;
 *  Eina_Iterator *it = eina_model_child_reversed_iterator_get(model);
 *  EINA_ITERATOR_FOREACH(it, child)
 *    {
 *       use_child(child);
 *       eina_model_unref(child);
 *    }
 *  eina_iterator_free(it);
 * @endcode
 * This code shows how to use iterators to do something (in this example call
 * use_child()) on every child element starting from last to first.
 *
 * @warning Each iteration(call to eina_iterator_next()) gives a child model
 * with reference @b increased! You must call eina_model_unref() after you're
 * done with it.
 *
 * @see eina_model_child_slice_iterator_get()
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_sorted_iterator_get()
 * @see eina_model_child_filtered_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_reversed_iterator_get(Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Gets a reversed iterator to a slice of @a model's children.
 * @param model The model whose children to iterate over.
 * @param start The first child included in the iterator.
 * @param count The number of children included in the iterator.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning Each iteration(call to eina_iterator_next()) gives a child model
 * with reference @b increased! You must call eina_model_unref() after you're
 * done with it.
 *
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_slice_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_slice_reversed_iterator_get(Eina_Model *model,
                                                                 unsigned int start,
                                                                 unsigned int count) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;

/**
 * @brief create an iterator that outputs a child model using sort criteria.
 * @param model the model instance.
 * @param compare compare function to use as sort criteria.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * Each iteration output a child model with reference @b increased!
 * You must call eina_model_unref() after you're done with it.
 *
 * The sort will not affect the main object @a model, it's just a view
 * of it.
 *
 * @code
 *  Eina_Model *child;
 *  Eina_Iterator *it = eina_model_child_sorted_iterator_get(model, EINA_COMPARE_CB(eina_model_compare));
 *  EINA_ITERATOR_FOREACH(it, child)
 *    {
 *       use_child(child);
 *       eina_model_unref(child);
 *    }
 *  eina_iterator_free(it);
 * @endcode
 * This bit of code shows how to use iterators to do something (in this example
 * call use_child()) on every child element in the order given by the @a compare
 * function.
 *
 * @warning Each iteration(call to eina_iterator_next()) gives a child model
 * with reference @b increased! You must call eina_model_unref() after you're
 * done with it.
 *
 * @see eina_model_child_slice_iterator_get()
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_sorted_iterator_get()
 * @see eina_model_child_filtered_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_sorted_iterator_get(Eina_Model *model,
                                                         Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Returns a sorted iterator to a slice of @a model's children.
 * @param model The model whose children to iterate over.
 * @param start The position(before sorting) of the first child included in
 * the iterator.
 * @param count The number of children included in the iterator.
 * @param compare The function used to sort the children.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning Each iteration(call to eina_iterator_next()) gives a child model
 * with reference @b increased! You must call eina_model_unref() after you're
 * done with it.
 *
 * @see eina_model_child_slice_iterator_get()
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_sorted_iterator_get()
 * @see eina_model_child_filtered_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_slice_sorted_iterator_get(Eina_Model *model,
                                                               unsigned int start,
                                                               unsigned int count,
                                                               Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 4) EINA_WARN_UNUSED_RESULT;

/**
 * @brief create an iterator that indexes of children that matches.
 * @param model the model instance.
 * @param match function to select children.
 * @param data extra context given to @a match function.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * Unlike other iterators, each iteration output an integer index!
 * This is useful if you want to highlight the matching model
 * somewhere else.
 *
 * If no child element matches a valid, and empty, iterator will be returned.
 * Indexes returned by this iterator are guaranteed to exists.
 *
 * @code
 *  unsigned int idx;
 *  Eina_Iterator *it = eina_model_child_filtered_iterator_get(model, filter, ctx);
 *  EINA_ITERATOR_FOREACH(it, idx)
 *    {
 *       Eina_Model *child = eina_model_child_get(model, idx);
 *       printf("matches at %u %p\n", idx, child);
 *       eina_model_unref(child);
 *    }
 *  eina_iterator_free(it);
 * @endcode
 * This bit of code shows how to use iterators to do something (in this example
 * print the address) on child elements that match the criteria given of @a match.
 *
 * @see eina_model_child_slice_iterator_get()
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_sorted_iterator_get()
 * @see eina_model_child_filtered_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_filtered_iterator_get(Eina_Model *model,
                                                           Eina_Each_Cb match,
                                                           const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Returns a filtered slice of the @a model's children.
 * @param model The model whose children to iterate over.
 * @param start The position of the first child to be tested for inclusion in
 * the iterator.
 * @param count The number of children to be tested for inclusion in the
 * iterator.
 * @param match The function used to decide which children will be included in
 * the iterator.
 * @param data Data passed to the @a match function.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @note Only children for whom @a match returns #EINA_TRUE will be included in
 * the iterator.
 *
 * @note Each iteration(call to eina_iterator_next()) gives an integer index!
 *
 * @warning The iterator may have less than @a count children, but not more.
 *
 * @see eina_model_child_slice_iterator_get()
 * @see eina_model_child_reversed_iterator_get()
 * @see eina_model_child_sorted_iterator_get()
 * @see eina_model_child_filtered_iterator_get()
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_child_slice_filtered_iterator_get(Eina_Model *model,
                                                                 unsigned int start,
                                                                 unsigned int count,
                                                                 Eina_Each_Cb match,
                                                                 const void *data) EINA_ARG_NONNULL(1, 4) EINA_WARN_UNUSED_RESULT;


/**
 * @}
 */

/**
 * @brief Convert model to string.
 * @param model the model instance.
 * @return Newly allocated memory or @c NULL on failure.
 *
 * The default format of the ouput is:
 * Type_Name({Property_Name: Property_Value, ...}, [Child0, Child1, ...])
 *
 * Where:
 *  @li Type_Name: eina_model_type_name_get(eina_model_type_get(model))
 *  @li Properties are sorted alphabetically.
 *  @li Property_Value is created using eina_value_to_string().
 *  @li Children are converted using eina_model_to_string()
 *
 * @since 1.2
 */
EAPI char *eina_model_to_string(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC;

/**
 * @defgroup Eina_Model_Type_Group Data Model Type management
 *
 * Functions and structures related to implementing new types or
 * extending existing ones.
 *
 * All eina_model_type functions takes an Eina_Model_Type or
 * Eina_Model_Interface as parameter and may be used to validate or
 * query information about them.
 *
 * The functions with prefix eina_model_type that matches eina_model
 * counterparts, such as eina_model_type_compare() and
 * eina_model_compare() are used as "super", that is, calls the @c
 * compare() method of the given type (or its parent) instead of the
 * most specific type of provided Eina_Model.
 *
 * Examples:
 * @li @ref eina_model_02_example_page contains an easy to follow
 *     example that demonstrates several of the important features of
 *     eina_model, uses #EINA_MODEL_TYPE_GENERIC.
 * @li @ref eina_model_03_example_page walk-through example on how to
 *     inherit types, a suggestion of eina_model_load() usage and uses
 *     #EINA_MODEL_TYPE_STRUCT.
 *
 * @{
 */

/**
 * @def EINA_MODEL_TYPE_VERSION
 * Current API version, used to validate #_Eina_Model_Type.
 */
#define EINA_MODEL_TYPE_VERSION (1)

/**
 * @struct _Eina_Model_Type
 * API to access models.
 *
 * Each type of the hierarchy and each interface will get its own
 * private data of size @c private_size (defined at each subtype or
 * interface), this can be retrieved with
 * eina_model_type_private_data_get() and
 * eina_model_interface_private_data_get().
 *
 * Private are created @b automatically and should be setup with @c
 * setup and flushed with @c flush. All types (or interfaces)
 * functions that exist are called! Don't call your parent's @c setup or
 * @c flush! The setup is done from parent to child. Flush is done from
 * child to parent.
 *
 * After memory setup was done, @c constructor of the toplevel type
 * defining it is called. If desired it may call parent's constructor
 * in whatever order is desired. This may be used to create
 * properties, children and may use parent's data if needed. The only
 * constructor caled is that of the most specialized type, if interface
 * constructors should be called, do them in the desired order from the type
 * constructor.
 *
 * When the model is deleted, explicitly with eina_model_del() or
 * implicitly with eina_model_unref() on the last reference, the @c
 * destructor is called. It must release references to other
 * models. When the last reference is dropped, every @c flush is
 * called from child to parent, then memory is freed. The only
 * destructor caled is that of the most specialized type, if interface
 * destructors should be called, do them in the desired order from the type
 * destructor.
 *
 *
 * @note The methods @c setup and @c flush should exist if there is
 *       private data, otherwise memory may be uninitialized or leaks.
 * @note It is recommended that @c constructor and @c destructor exist
 *       to correctly do their roles and call parents in the correct
 *       order. Whenever they do not exist, their parent pointer is
 *       called.
 * @note a runtime check will enforce just types with ABI version
 *       version #EINA_MODEL_TYPE_VERSION are used by comparing with
 *       the @c version member.
 *
 * @since 1.2
 */
struct _Eina_Model_Type
{
   unsigned int version; /**< must be #EINA_MODEL_TYPE_VERSION */
   unsigned int private_size; /**< used to allocate type private data */
   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 */
   const char *name; /**< name for debug and introspection */
   const Eina_Model_Type *parent; /**< parent type, must be EINA_MODEL_TYPE_BASE or a child of */
   const Eina_Model_Interface **interfaces; /**< null terminated array of interfaces */
   const Eina_Model_Event_Description *events; /**< null terminated array of events */
   Eina_Bool (*setup)(Eina_Model *model); /**< setup type private data, do @b not call parent type setup! */
   Eina_Bool (*flush)(Eina_Model *model); /**< flush type private data, do @b not call parent type flush! */
   Eina_Bool (*constructor)(Eina_Model *model); /**< construct type instance, setup was already called. Should call parent's or interfaces' constructor if needed */
   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. */
   Eina_Bool (*copy)(const Eina_Model *src, Eina_Model *dst); /**< copy type private data, do @b not call parent type copy! */
   Eina_Bool (*deep_copy)(const Eina_Model *src, Eina_Model *dst); /**< deep copy type private data, do @b not call parent type deep copy! */
   Eina_Bool (*compare)(const Eina_Model *a, const Eina_Model *b, int *cmp);
   Eina_Bool (*load)(Eina_Model *model);
   Eina_Bool (*unload)(Eina_Model *model);
   Eina_Bool (*property_get)(const Eina_Model *model, const char *name, Eina_Value *value);
   Eina_Bool (*property_set)(Eina_Model *model, const char *name, const Eina_Value *value);
   Eina_Bool (*property_del)(Eina_Model *model, const char *name);
   Eina_List *(*properties_names_list_get)(const Eina_Model *model); /**< list of stringshare */
   int (*child_count)(const Eina_Model *model);
   Eina_Model *(*child_get)(const Eina_Model *model, unsigned int position);
   Eina_Bool (*child_set)(Eina_Model *model, unsigned int position, Eina_Model *child);
   Eina_Bool (*child_del)(Eina_Model *model, unsigned int position);
   Eina_Bool (*child_insert_at)(Eina_Model *model, unsigned int position, Eina_Model *child);
   int (*child_find)(const Eina_Model *model, unsigned int start_position, const Eina_Model *other);
   int (*child_criteria_match)(const Eina_Model *model, unsigned int start_position, Eina_Each_Cb match, const void *data);
   void (*child_sort)(Eina_Model *model, Eina_Compare_Cb compare);
   Eina_Iterator *(*child_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count);
   Eina_Iterator *(*child_reversed_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count);
   Eina_Iterator *(*child_sorted_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count, Eina_Compare_Cb compare);
   Eina_Iterator *(*child_filtered_iterator_get)(Eina_Model *model, unsigned int start, unsigned int count, Eina_Each_Cb match, const void *data);
   char *(*to_string)(const Eina_Model *model); /**< used to represent model as string, usually for debug purposes or user convenience */
   void *__extension_ptr0; /**< not to be used */
   void *__extension_ptr1; /**< not to be used */
   void *__extension_ptr2; /**< not to be used */
   void *__extension_ptr3; /**< not to be used */
};

/**
 * @def EINA_MODEL_TYPE_INIT
 * @param name The name of the model to be used.
 * @param type The type of the model to be used.
 * @param private_type The private type to be used.
 * @param parent The parent of the model to be used.
 * @param interfaces The interfaces to be used.
 * @param events The events that the model will support.
 */
#define EINA_MODEL_TYPE_INIT(name, type, private_type, parent, interfaces, events) \
  {EINA_MODEL_TYPE_VERSION,                                         \
   sizeof(private_type),                                            \
   sizeof(type),                                                    \
   name,                                                            \
   parent,                                                          \
   interfaces,                                                      \
   events,                                                          \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL                                                             \
   }
/**
 * @def EINA_MODEL_TYPE_INIT_NOPRIVATE
 * @param name The name of the model to be used.
 * @param type The type of the model to be used.
 * @param parent The parent of the model to be used.
 * @param interfaces The interfaces to be used.
 * @param events The events that the model will support.
 */
#define EINA_MODEL_TYPE_INIT_NOPRIVATE(name, type, parent, interfaces, events) \
  {EINA_MODEL_TYPE_VERSION,                                         \
   0,                                                               \
   sizeof(type),                                                    \
   name,                                                            \
   parent,                                                          \
   interfaces,                                                      \
   events,                                                          \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL                                                             \
   }
/**
 * @def EINA_MODEL_TYPE_INIT_NULL
 * @brief @c NULL value eina model type.
 */
#define EINA_MODEL_TYPE_INIT_NULL                                   \
  {0,                                                               \
   0,                                                               \
   0,                                                               \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL,                                                            \
   NULL                                                             \
   }

/**
 * @brief Calls the constructor of @a type for @a model.
 * @param type The type whose constructor will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This should be used to call the parent's type constructor, something like:
 * @code
 * static Eina_Bool my_type_constructor(Eina_Model *m)
 * {
 *     // call parents constructor:
 *     if (!eina_model_type_constructor(MY_TYPE->parent, m))
 *        return EINA_FALSE;
 *     // do my stuff
 *     return EINA_TRUE;
 * }
 * @endcode
 * @note You should only do your type's initialization after the parent type has
 * done his own(this is as to ensure you can call on your parent's methods).
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_new()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_constructor(const Eina_Model_Type *type,
                                           Eina_Model *model) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
/**
 * @brief Calls the destructor of @a type for @a model.
 * @param type The type whose destructor will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This should be used to call the parent's type destructor, something like:
 * @code
 * static Eina_Bool my_type_destructor(Eina_Model *m)
 * {
 *     // do my stuff
 *     // call parents destructor:
 *     if (!eina_model_type_destructor(MY_TYPE->parent, m))
 *        return EINA_FALSE;
 *     return EINA_TRUE;
 * }
 * @endcode
 * @note It's considered good practice to free your type's resources before
 * calling the parent's destructor.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_del()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_destructor(const Eina_Model_Type *type,
                                          Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the copy method of @a type for @a model.
 * @param type The type whose copy method will be called.
 * @param src Pointer to the model to be copied.
 * @param dst Pointer to where copy will be put.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_copy()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_copy(const Eina_Model_Type *type,
                                    const Eina_Model *src,
                                    Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Calls the deep copy method of @a type for @a model.
 * @param type The type whose copy method will be called.
 * @param src Pointer to the model to be copied.
 * @param dst Pointer to where copy will be put.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_deep_copy()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_deep_copy(const Eina_Model_Type *type,
                                         const Eina_Model *src,
                                         Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Calls the compare method of @a type for @a model.
 * @param[in] type The type whose compare method will be called.
 * @param[in] a Pointer to the first model to be compared.
 * @param[in] b Pointer to the second model to be compared.
 * @param[out] cmp The value of the comparison, 1 if @a b is greater than @a a,
 * -1 if @a b is smaller than @a a, 0 if @a a and @a b are equal.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_compare()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_compare(const Eina_Model_Type *type,
                                       const Eina_Model *a,
                                       const Eina_Model *b,
                                       int *cmp) EINA_ARG_NONNULL(1, 2, 3, 4);
/**
 * @brief Calls the load method of @a type for @a model.
 * @param type The type whose load method will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_load()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_load(const Eina_Model_Type *type,
                                    Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the unload method of @a type for @a model.
 * @param type The type whose unload method will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_unload()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_unload(const Eina_Model_Type *type,
                                      Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the property get method of @a type for @a model.
 * @param[in] type The type whose property get method will be called.
 * @param[in] model The model instance.
 * @param[in] name Name of property to get.
 * @param[out] value Pointer to where value of property will be placed.
 * @return #EINA_TRUE if able to get property, #EINA_FALSE otherwise.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_property_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_property_get(const Eina_Model_Type *type,
                                            const Eina_Model *model,
                                            const char *name,
                                            Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4);
/**
 * @brief Calls the property set method of @a type for @a model.
 * @param type The type whose property set method will be called.
 * @param model The model instance.
 * @param name Name of property whose value will be set.
 * @param value The value to be set.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_property_set()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_property_set(const Eina_Model_Type *type,
                                            Eina_Model *model,
                                            const char *name,
                                            const Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4);
/**
 * @brief Calls the property del method of @a type for @a model.
 * @param type The type whose property delete method will be called.
 * @param model The model instance.
 * @param name The name of the property to be deleted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_property_del()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_property_del(const Eina_Model_Type *type,
                                            Eina_Model *model,
                                            const char *name) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Calls the properties name list method of @a type for @a model.
 * @param type The type whose property name list get method will be called.
 * @param model The model instance.
 * @return #Eina_List of properties' names.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_properties_names_list_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_List *eina_model_type_properties_names_list_get(const Eina_Model_Type *type,
                                                          const Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the child count method of @a type for @a model.
 * @param type The type whose child count method will be called.
 * @param model The model instance.
 * @return Number of children in @a model.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_count()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI int eina_model_type_child_count(const Eina_Model_Type *type,
                                     const Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the child get method of @a type for @a model.
 * @param type The type whose child get method will be called.
 * @param model The model instance.
 * @param position The position of the child to get.
 * @return The child model, or @c NULL on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Model *eina_model_type_child_get(const Eina_Model_Type *type,
                                           const Eina_Model *model,
                                           unsigned int position) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the child set method of @a type for @a model.
 * @param type The type whose child set method will be called.
 * @param model The model instance.
 * @param position The position of the child to be set.
 * @param child Pointer to value (child) to be set.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_set()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_child_set(const Eina_Model_Type *type,
                                         Eina_Model *model,
                                         unsigned int position,
                                         Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4);
/**
 * @brief Calls the child del method of @a type for @a model.
 * @param type The type whose child delete method will be called.
 * @param model The model instance.
 * @param position Position of child to be deleted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_del()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_child_del(const Eina_Model_Type *type,
                                         Eina_Model *model,
                                         unsigned int position) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the child insert at method of @a type for @a model.
 * @param type The type whose child insert method will be called.
 * @param model The model instance.
 * @param position Position in which @a child will be inserted.
 * @param child The child to be inserted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_insert_at()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_child_insert_at(const Eina_Model_Type *type,
                                               Eina_Model *model,
                                               unsigned int position,
                                               Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4);
/**
 * @brief Calls the child find method of @a type for @a model.
 * @param type The type whose find method will be called.
 * @param model The model instance.
 * @param start_position The first position to search for.
 * @param other The child being searched for.
 * @return The index of the searched child, or -1 if not found.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_find()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI int eina_model_type_child_find(const Eina_Model_Type *type,
                                    const Eina_Model *model,
                                    unsigned int start_position,
                                    const Eina_Model *other) EINA_ARG_NONNULL(1, 2, 4);
/**
 * @brief Calls the child criteria match method of @a type for @a model.
 * @param type The type whose child criteria match method will be called.
 * @param model The model instance.
 * @param start_position The first position to be checked.
 * @param match The function used to determine if a child matches the criteria.
 * @param data Data given to the @a match function. May be @c NULL.
 * @return The position of the first child to match the criteria or -1 if no
 * child matches it.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_criteria_match()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI int eina_model_type_child_criteria_match(const Eina_Model_Type *type,
                                              const Eina_Model *model,
                                              unsigned int start_position,
                                              Eina_Each_Cb match,
                                              const void *data) EINA_ARG_NONNULL(1, 2, 4);
/**
 * @brief Calls the child sort method of @a type for @a model.
 * @param type The type whose child sort method will be called.
 * @param model The model instance.
 * @param compare Function used to compare children.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_sort()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI void eina_model_type_child_sort(const Eina_Model_Type *type,
                                     Eina_Model *model,
                                     Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Calls the child iterator get method of @a type for @a model.
 * @param type The type whose child iterator get method will be called.
 * @param model The model instance.
 * @param start The first child to be a part of the iterator.
 * @param count The number of children included in the iterator.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_iterator_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_type_child_iterator_get(const Eina_Model_Type *type,
                                                       Eina_Model *model,
                                                       unsigned int start,
                                                       unsigned int count) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the child reversed iterator get method of @a type for @a model.
 * @param type The type whose child reversed iterator get method will be called.
 * @param model The model instance.
 * @param start The first child to be a part of the iterator.
 * @param count The number of children included in the iterator.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_reversed_iterator_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_type_child_reversed_iterator_get(const Eina_Model_Type *type,
                                                                Eina_Model *model,
                                                                unsigned int start,
                                                                unsigned int count) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the child sorted iterator get method of @a type for @a model.
 * @param type The type whose child sorted iterator get method will be called.
 * @param model The model instance.
 * @param start The first child to be a part of the iterator.
 * @param count The number of children included in the iterator.
 * @param compare Function used to compare children.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_sorted_iterator_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_type_child_sorted_iterator_get(const Eina_Model_Type *type,
                                                              Eina_Model *model,
                                                              unsigned int start,
                                                              unsigned int count,
                                                              Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 5);
/**
 * @brief Calls the child filtered get method of @a type for @a model.
 * @param type The type whose child filtered iterator get method will be called.
 * @param model The model instance.
 * @param start The first child to be a part of the iterator.
 * @param count Number of children to be checked for inclusion in the iterator.
 * @param match Function used to check if child will be included in the iterator.
 * @param data Data given to the @a match function. May be @c NULL.
 * @return Newly created iterator instance on success or @c NULL on failure.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_child_filtered_iterator_get()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Iterator *eina_model_type_child_filtered_iterator_get(const Eina_Model_Type *type,
                                                                Eina_Model *model,
                                                                unsigned int start,
                                                                unsigned int count,
                                                                Eina_Each_Cb match,
                                                                const void *data) EINA_ARG_NONNULL(1, 2, 5);
/**
 * @brief Calls the to string method of @a type for @a model.
 * @param type The type whose to string method will be called.
 * @param model The model instance.
 * @return String representationof @a model.
 *
 * @warning If model doesn't inherit from (or is of) @a type does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_to_string()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI char *eina_model_type_to_string(const Eina_Model_Type *type,
                                     const Eina_Model *model) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_MALLOC;


/**
 * @brief Get resolved method from types that extend Eina_Model_Type given @a offset.
 * @param model the model to query the method
 * @param offset the byte offset in the structure given as type, it
 *        must be bigger than Eina_Model_Type itself.
 * @return Address to resolved method, or @c NULL if method is not implemented.
 *
 * The use of this function is discouraged, you should use
 * eina_model_method_resolve() instead.
 *
 * When implementing new types that augments the basic methods from
 * Eina_Model_Type, the recommended structure layout is as follow:
 * @code
 * typedef struct _My_Type My_Type;
 * struct _My_Type {
 *    Eina_Model_Type base;
 *    int (*my_method)(Eina_Model *model);
 * };
 *
 * int my_type_my_method(Eina_Model *model);
 * @endcode
 *
 * Then the implementation of @c my_type_my_method() needs to get the
 * most specific @c my_method that is not @c NULL from type hierarchy,
 * also called "resolve the method".
 *
 * To do this in an efficient way, Eina_Model infrastructure
 * pre-resolves all methods and provides this function for efficient
 * query. The recommended implementation of my_type_my_method() would
 * be:
 * @code
 * int my_type_my_method(Eina_Model *model)
 * {
 *   int (*meth)(Eina_Model *);
 *
 *   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(model, MY_TYPE), -1);
 *
 *   meth = eina_model_method_offset_resolve(model, offsetof(My_Type, my_method));
 *   EINA_SAFETY_ON_NULL_RETURN(meth, -1);
 *   return meth(model);
 * }
 * @endcode
 *
 * @note offset must be bigger than Eina_Model_Type, otherwise use
 *       specific functions such as eina_model_property_get().
 *
 * @see eina_model_method_resolve
 * @see eina_model_type_method_resolve
 * @since 1.2
 */
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;

/**
 * @brief Gets resolved method from @a type of @a model given @a offset.
 * @param type The type whose method offset resolve method will be called.
 * @param model The model instance.
 * @param offset The offset of the wanted method.
 * @return Address to resolved method, or @c NULL if method is not implemented.
 *
 * @see eina_model_method_offset_resolve()
 * @since 1.2
 */
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;
/**
 * @def eina_model_method_resolve
 * @param model The model to be resolved.
 * @param struct_type The struct of the element to be resolved.
 * @param method The method to be resolved.
 */
#define eina_model_method_resolve(model, struct_type, method) eina_model_method_offset_resolve((model), offsetof(struct_type, method))
/**
 * @def eina_model_type_method_resolve
 * @param type The type of the model to be resolved.
 * @param model The model to be resolved.
 * @param struct_type The struct of the element to be resolved.
 * @param method The method to be resolved.
 */
#define eina_model_type_method_resolve(type, model, struct_type, method) eina_model_type_method_offset_resolve((type), (model), offsetof(struct_type, method))

/**
 * @def EINA_MODEL_INTERFACE_VERSION
 * Current API version, used to validate #_Eina_Model_Interface.
 */
#define EINA_MODEL_INTERFACE_VERSION (1)

/**
 * @struct _Eina_Model_Interface
 * API to access models.
 *
 * Interfaces are managed by name, then multiple Eina_Model_Interface
 * may have the same name meaning it implements that name.
 *
 * Each interface will get its own private data of size @c
 * private_size (defined at each sub interface), this can be retrieved
 * with eina_model_interface_private_data_get().
 *
 * Private are created @b automatically and should be setup with @c
 * setup and flushed with @c flush. All interfaces functions that
 * exist are called! Don't call your parent's @c setup or @c flush!
 * The setup is done from parent to child. Flush is done from child to
 * parent (topological sort is applied to interface graph).
 *
 * @note The methods @c setup and @c flush should exist if there is
 *       private data, otherwise memory may be uninitialized or leaks.
 * @note It is recommended that @c constructor and @c destructor exist
 *       to correctly do their roles and call parents in the correct
 *       order. Whenever they do not exist, their parent pointer is
 *       called.
 * @note Interface's constructor and destructor are only called by
 *       type counterparts. Unlike setup and flush, they are not
 *       guaranteed to be called.
 * @note use the same name pointer on queries to speed up the lookups!
 * @note a runtime check will enforce just types with ABI
 *       version #EINA_MODEL_INTERFACE_VERSION are used by comparing
 *       with the @c version member.
 *
 * @since 1.2
 */
struct _Eina_Model_Interface
{
   unsigned int version; /**< must be #EINA_MODEL_INTERFACE_VERSION */
   unsigned int private_size; /**< used to allocate interface private data */
   unsigned int interface_size; /**< used to know sizeof(Eina_Model_Interface) or subtypes (which may be bigger, by including Eina_Model_Interface as header */
   const char *name; /**< name for debug and introspection */
   const Eina_Model_Interface **interfaces; /**< null terminated array of parent interfaces */
   const Eina_Model_Event_Description *events; /**< null terminated array of events */
   Eina_Bool (*setup)(Eina_Model *model); /**< setup interface private data, do @b not call parent interface setup! */
   Eina_Bool (*flush)(Eina_Model *model); /**< flush interface private data, do @b not call parent interface flush! */
   Eina_Bool (*constructor)(Eina_Model *model); /**< construct interface instance, setup was already called. Should call parent's constructor if needed */
   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. */
   Eina_Bool (*copy)(const Eina_Model *src, Eina_Model *dst); /**< copy interface private data, do @b not call parent interface copy! */
   Eina_Bool (*deep_copy)(const Eina_Model *src, Eina_Model *dst); /**< deep copy interface private data, do @b not call parent interface deep copy! */
   void *__extension_ptr0; /**< not to be used @internal */
   void *__extension_ptr1; /**< not to be used @internal */
   void *__extension_ptr2; /**< not to be used @internal */
   void *__extension_ptr3; /**< not to be used @internal */
};
/**
 * @def EINA_MODEL_INTERFACE_INIT
 * @param name The name of the interface to be created.
 * @param iface The interface to be used.
 * @param private_type The private type to be used.
 * @param parent The parent of the interface to be created.
 * @param events The events that the interface will support.
 */
#define EINA_MODEL_INTERFACE_INIT(name, iface, private_type, parent, events) \
  {EINA_MODEL_INTERFACE_VERSION,                                        \
   sizeof(private_type),                                                \
   sizeof(iface),                                                       \
   name,                                                                \
   parent,                                                              \
   events,                                                              \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL                                                                 \
   }
/**
 * @def EINA_MODEL_INTERFACE_INIT_NOPRIVATE
 * @param name The name of the interface to be created.
 * @param iface The interface to be used.
 * @param parent The parent of the interface to be created.
 * @param events The events that the interface will support.
 */
#define EINA_MODEL_INTERFACE_INIT_NOPRIVATE(name, iface, parent, events) \
  {EINA_MODEL_INTERFACE_VERSION,                                        \
   0,                                                                   \
   sizeof(iface),                                                       \
   name,                                                                \
   parent,                                                              \
   events,                                                              \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL,                                                                \
   NULL                                                                 \
   }
/**
 * @def EINA_MODEL_INTERFACE_INIT_NULL
 * @brief NULL value eina model interface.
 */
#define EINA_MODEL_INTERFACE_INIT_NULL      \
  {0,                                       \
   0,                                       \
   0,                                       \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL,                                    \
   NULL                                     \
   }

/**
 * @brief Calls the constructor of @a iface on @a model.
 * @param iface The interface whose constructor will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If @a model doesn't implement @a iface does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_new()
 * @see _Eina_Model_Interface
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_constructor(const Eina_Model_Interface *iface,
                                                Eina_Model *model) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
/**
 * @brief Calls the destructor of @a iface on @a model.
 * @param iface The interface whose destructor will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If @a model doesn't implement @a iface does nothing and 
 * returns #EINA_FALSE.
 *
 * @see eina_model_del()
 * @see _Eina_Model_Interface
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_destructor(const Eina_Model_Interface *iface,
                                               Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Calls the copy method of @a iface on @a model.
 * @param iface The interface whose copy method will be called.
 * @param src Pointer to the model to be copied.
 * @param dst Pointer to where copy will be put.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If @a model doesn't implement @a iface does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_copy()
 * @see _Eina_Model_Interface
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_copy(const Eina_Model_Interface *iface,
                                         const Eina_Model *src,
                                         Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Calls the deep copy method of @a iface on @a model.
 * @param iface The interface whose deep copy method will be called.
 * @param src Pointer to the model to be copied.
 * @param dst Pointer to where copy will be put.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If @a model doesn't implement @a iface does nothing and
 * returns #EINA_FALSE.
 *
 * @see eina_model_deep_copy()
 * @see _Eina_Model_Interface
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_deep_copy(const Eina_Model_Interface *iface,
                                              const Eina_Model *src,
                                              Eina_Model *dst) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @def eina_model_interface_method_resolve
 * @param iface The interface to be resolved.
 * @param model The model of the interface to be resolved.
 * @param struct_type The struct of the element to be resolved.
 * @param method The method of the interface to be resolved.
 */
#define eina_model_interface_method_resolve(iface, model, struct_type, method) eina_model_interface_method_offset_resolve((iface), (model), offsetof(struct_type, method))

/**
 * @brief Gets the @a iface's method for @a model at @a offset.
 * @param iface The interface whose method offset resolve method will be called.
 * @param model The model instance.
 * @param offset The offset of the wanted method.
 * @return Address to resolved method, or @c NULL if method is not implemented.
 *
 * @see eina_model_method_offset_resolve()
 * @since 1.2
 */
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;


/**
 * @struct _Eina_Model_Event_Description
 * Data Model Event Description.
 *
 * @see EINA_MODEL_EVENT_DESCRIPTION()
 * @see #EINA_MODEL_EVENT_DESCRIPTION_SENTINEL
 * @since 1.2
 */
struct _Eina_Model_Event_Description
{
   const char *name; /**< name used for lookups */
   const char *type; /**< used for introspection purposes, documents what goes as callback event information (@c event_info) */
   const char *doc; /**< documentation for introspection purposes */
};

/**
 * @def EINA_MODEL_EVENT_DESCRIPTION
 *
 * Helper to define Eina_Model_Event_Description fields.
 *
 * @since 1.2
 */
#define EINA_MODEL_EVENT_DESCRIPTION(name, type, doc) {name, type, doc}

/**
 * @def EINA_MODEL_EVENT_DESCRIPTION_SENTINEL
 *
 * Helper to define Eina_Model_Event_Description fields for sentinel (last
 * item).
 *
 * @since 1.2
 */
#define EINA_MODEL_EVENT_DESCRIPTION_SENTINEL {NULL, NULL, NULL}

/**
 * @brief Check @a type is valid.
 * @param type The type to be checked.
 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_check(const Eina_Model_Type *type) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
/**
 * @brief Gets the name @a type.
 * @param type The type whose name is wanted.
 * @return Name of @a type.
 *
 * @since 1.2
 */
EAPI const char *eina_model_type_name_get(const Eina_Model_Type *type) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
/**
 * @brief Gets the parent type of @a type.
 * @param type The type whose parent is wanted.
 * @return Type of parent.
 *
 * @since 1.2
 */
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;

/**
 * @brief Setup the type to be a subclass of another parent type.
 * @param type type to be modified
 * @param parent type to be used as parent
 * @return #EINA_TRUE on success, #EINA_FALSE otherwise.
 *
 * Although @a type is modified, the following properties are not
 * touched or they are actually used for validation:
 *
 * @li @c type->version must be #EINA_MODEL_TYPE_VERSION;
 * @li @c type->private_size unmodified, should be set to type's size;
 * @li @c type->name unmodified, should be set to type's name.
 *
 *
 * All other fields are modified as follow:
 *
 * @li @c type->type_size initiated to parent->type_size
 * @li @c type->interfaces = NULL;
 * @li @c type->events = NULL;
 * @li @c type->setup = NULL;
 * @li @c type->flush = NULL;
 * @li @c type->constructor = NULL;
 * @li @c type->destructor = NULL;
 * @li @c type->copy = NULL;
 * @li @c type->deep_copy = NULL;
 * @li @c type->compare = NULL;
 * @li @c type->load = NULL;
 * @li @c type->unload = NULL;
 * @li @c type->property_get = NULL;
 * @li @c type->property_set = NULL;
 * @li @c type->property_del = NULL;
 * @li @c type->properties_names_list_get = NULL;
 * @li @c type->child_count = NULL;
 * @li @c type->child_get = NULL;
 * @li @c type->child_set = NULL;
 * @li @c type->child_del = NULL;
 * @li @c type->child_insert_at = NULL;
 * @li @c type->child_find = NULL;
 * @li @c type->child_criteria_match = NULL;
 * @li @c type->child_sort = NULL;
 * @li @c type->child_iterator_get = NULL;
 * @li @c type->child_reversed_iterator_get = NULL;
 * @li @c type->child_sorted_iterator_get = NULL;
 * @li @c type->child_filtered_iterator_get = NULL;
 * @li @c type->to_string = NULL;
 *
 * If you have custom methods, overload them afterwards
 * eina_model_type_subclass_setup() returns with #EINA_TRUE.
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_subclass_setup(Eina_Model_Type *type,
                                              const Eina_Model_Type *parent) EINA_ARG_NONNULL(1, 2);

/**
 * @brief Checks if @a type is a subclass of(or the same as) @a self_or_parent.
 * @param type The type to be checked.
 * @param self_or_parent The type being checked for.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_type_subclass_check(const Eina_Model_Type *type,
                                              const Eina_Model_Type *self_or_parent) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE;


/**
 * @brief Gets a interface with name @a name from @a type.
 * @param type The type instance.
 * @param name The name of the desired interface.
 * @return The interface implemented by @a type with name @a name, or null if
 * this type doesn't implement any interface with name @a name.
 *
 * @since 1.2
 */
EAPI const Eina_Model_Interface *eina_model_type_interface_get(const Eina_Model_Type *type,
                                                               const char *name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE;

/**
 * @brief Gets the private date of @a model for type @a type.
 * @param model The model instance.
 * @param type The type whose private data will be gotten.
 * @return Pointer to type's private data.
 *
 * @since 1.2
 */
EAPI void *eina_model_type_private_data_get(const Eina_Model *model,
                                            const Eina_Model_Type *type) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;

/**
 * @brief Checks if @a iface is a valid interface.
 * @param iface The interface instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_check(const Eina_Model_Interface *iface) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;

/**
 * @brief Gets the private date of @a model for interface @a iface.
 * @param model The model instance.
 * @param iface The interface whose private data will be gotten.
 * @return Pointer to interface's private data.
 *
 * @since 1.2
 */
EAPI void *eina_model_interface_private_data_get(const Eina_Model *model,
                                                 const Eina_Model_Interface *iface) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;

/**
 * @def EINA_MODEL_INTERFACE_PROPERTIES_VERSION
 * Current API version, used to validate #_Eina_Model_Interface_Properties.
 */
#define EINA_MODEL_INTERFACE_PROPERTIES_VERSION (1)

/**
 * @typedef Eina_Model_Interface_Properties
 * Interface to manage model's properties.
 *
 * This extends #Eina_Model_Interface as expected by interface
 * name #EINA_MODEL_INTERFACE_NAME_PROPERTIES.
 *
 * This interface is meant to help managing properties of a model, it
 * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for
 * children independently from properties.
 *
 * @see #_Eina_Model_Interface_Properties explains fields.
 * @since 1.2
 */
typedef struct _Eina_Model_Interface_Properties Eina_Model_Interface_Properties;

/**
 * @struct _Eina_Model_Interface_Properties
 * Interface to manage model's properties.
 *
 * This extends #Eina_Model_Interface as expected by interface
 * name #EINA_MODEL_INTERFACE_NAME_PROPERTIES.
 *
 * This interface is meant to help managing properties of a model, it
 * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for
 * children independently from properties.
 *
 * @since 1.2
 */
struct _Eina_Model_Interface_Properties
{
   Eina_Model_Interface base; /**< common interface methods */
   unsigned int version; /**< must be #EINA_MODEL_INTERFACE_PROPERTIES_VERSION */
   Eina_Bool (*compare)(const Eina_Model *a, const Eina_Model *b, int *cmp); /**< How to compare properties of this model */
   Eina_Bool (*load)(Eina_Model *model); /**< How to load properties of this model */
   Eina_Bool (*unload)(Eina_Model *model); /**< How to unload properties of this model */
   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. */
   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. */
   Eina_Bool (*del)(Eina_Model *model, const char *name); /**< Delete a property given its name */
   Eina_List *(*names_list_get)(const Eina_Model *model); /**< List of stringshare with known property names */
};

/**
 * @brief Compares properties using @a iface's comparing function.
 *
 * @param[in] iface The interface used to compare the properties.
 * @param[in] a The first model whose properties will be compared.
 * @param[in] b The second model whose properties will be compared.
 * @param[out] cmp A pointer to an integer which will contain the result of the
 * comparison.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_compare()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_properties_compare(const Eina_Model_Interface *iface,
                                                       const Eina_Model *a,
                                                       const Eina_Model *b,
                                                       int *cmp) EINA_ARG_NONNULL(1, 2, 3, 4) EINA_WARN_UNUSED_RESULT;

/**
 * @brief Loads properties using @a iface's loading function.
 * @param iface The properties interface whose load method will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_load()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_properties_load(const Eina_Model_Interface *iface,
                                                    Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Unloads properties using @a iface's unloading function.
 * @param iface The properties interface whose unload method will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_unload()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_properties_unload(const Eina_Model_Interface *iface,
                                                      Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Gets property named @a name using @a iface's function to get properties.
 * @param iface The properties interface whose property get method will be called.
 * @param model The model instance.
 * @param name The name of the property to get.
 * @param value Pointer to where value will be stored.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_property_get()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_properties_get(const Eina_Model_Interface *iface,
                                                   const Eina_Model *model,
                                                   const char *name,
                                                   Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4);
/**
 * @brief Sets property named @a name using @a iface's function to set properties.
 * @param iface The properties interface whose property set method will be called.
 * @param model The model instance.
 * @param name The name of the property to set.
 * @param value The value to be set.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_property_set()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_properties_set(const Eina_Model_Interface *iface,
                                                   Eina_Model *model,
                                                   const char *name,
                                                   const Eina_Value *value) EINA_ARG_NONNULL(1, 2, 3, 4);
/**
 * @brief Deletes property named @a name using @a iface's function to delete properties.
 * @param iface The properties interface whose property delete method will be called.
 * @param model The model instance.
 * @param name The name of the property to delete.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_property_del()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_properties_del(const Eina_Model_Interface *iface,
                                                   Eina_Model *model,
                                                   const char *name) EINA_ARG_NONNULL(1, 2, 3);
/**
 * @brief Gets properties name list using @a iface's function to get properties
 * name list.
 * @param iface The properties interface whose property name list get method
 * will be called.
 * @param model The model instance.
 * @return #Eina_List of properties' names.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_properties_names_list_get()
 * @since 1.2
 */
EAPI Eina_List *eina_model_interface_properties_names_list_get(const Eina_Model_Interface *iface,
                                                               const Eina_Model *model) EINA_ARG_NONNULL(1, 2); /**< list of stringshare */

/**
 * @typedef Eina_Model_Interface_Children
 * Interface to manage model's children.
 *
 * This extends #Eina_Model_Interface as expected by interface
 * name #EINA_MODEL_INTERFACE_NAME_CHILDREN.
 *
 * This interface is meant to help managing properties of a model, it
 * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for
 * children independently from properties.
 *
 * @see #_Eina_Model_Interface_Children explains fields.
 * @since 1.2
 */
typedef struct _Eina_Model_Interface_Children Eina_Model_Interface_Children;

/**
 * @def EINA_MODEL_INTERFACE_CHILDREN_VERSION
 * Current API version, used to validate #_Eina_Model_Interface_Children.
 */
#define EINA_MODEL_INTERFACE_CHILDREN_VERSION (1)

/**
 * @struct _Eina_Model_Interface_Children
 * Interface to manage model's children.
 *
 * This extends #Eina_Model_Interface as expected by interface
 * name #EINA_MODEL_INTERFACE_NAME_CHILDREN.
 *
 * This interface is meant to help managing properties of a model, it
 * is used by #EINA_MODEL_TYPE_MIXIN in order to configure methods for
 * children independently from properties.
 *
 * @since 1.2
 */
struct _Eina_Model_Interface_Children
{
   Eina_Model_Interface base; /**< common interface methods */
   unsigned int version; /**< must be #EINA_MODEL_INTERFACE_CHILDREN_VERSION */
   Eina_Bool (*compare)(const Eina_Model *a, const Eina_Model *b, int *cmp); /**< How to compare children of this model */
   Eina_Bool (*load)(Eina_Model *model); /**< How to load children of this model */
   Eina_Bool (*unload)(Eina_Model *model); /**< How to unload children of this model */
   int (*count)(const Eina_Model *model); /**< How many children of this model */
   Eina_Model *(*get)(const Eina_Model *model, unsigned int position); /**< Retrieve a child of this model, returned child must have reference increased! */
   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! */
   Eina_Bool (*del)(Eina_Model *model, unsigned int position); /**< Delete a child of this model. Existing child will have reference decreased! */
   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. */
   void (*sort)(Eina_Model *model, Eina_Compare_Cb compare); /**< Reorder children to be sorted respecting comparison function @c compare() */
};

/**
 * @brief Compares children using @a iface's comparing function.
 *
 * @param[in] iface The interface used to compare the properties.
 * @param[in] a The first model whose properties will be compared.
 * @param[in] b The second model whose properties will be compared.
 * @param[out] cmp A pointer to an integer which will contain the result of the
 * comparison.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_compare()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_children_compare(const Eina_Model_Interface *iface,
                                                     const Eina_Model *a,
                                                     const Eina_Model *b,
                                                     int *cmp) EINA_ARG_NONNULL(1, 2, 3, 4) EINA_WARN_UNUSED_RESULT;
/**
 * @brief Loads children using @a iface's loading function.
 * @param iface The children interface whose load method will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_load()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_children_load(const Eina_Model_Interface *iface,
                                                  Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Unloads children using @a iface's unloading function.
 * @param iface The children interface whose unload method will be called.
 * @param model The model instance.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return #EINA_FALSE.
 *
 * @see eina_model_unload()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_children_unload(const Eina_Model_Interface *iface,
                                                    Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Count children using @a iface's counting function.
 * @param iface The children interface whose count method will be called.
 * @param model The model instance.
 * @return Number of children in @a model.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return @c -1.
 *
 * @see eina_model_child_count()
 * @since 1.2
 */
EAPI int eina_model_interface_children_count(const Eina_Model_Interface *iface,
                                             const Eina_Model *model) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Get child using @a iface's function to get children.
 * @param iface The children interface whose get method will be called.
 * @param model The model instance.
 * @param position Position of child to be retrieved.
 * @return The requested child.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return @c -1.
 *
 * @see eina_model_child_get()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_interface_children_get(const Eina_Model_Interface *iface,
                                                   const Eina_Model *model,
                                                   unsigned int position) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Set child using @a iface's function to set children.
 * @param iface The children interface whose set method will be called.
 * @param model The model instance.
 * @param position Position of child to be set.
 * @param child Value(child) to be set.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return @c -1.
 *
 * @see eina_model_child_set()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_children_set(const Eina_Model_Interface *iface,
                                                 Eina_Model *model,
                                                 unsigned int position,
                                                 Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4);
/**
 * @brief Delete child using @a iface's function to delete children.
 * @param iface The children interface whose delete method will be called.
 * @param model The model instance.
 * @param position Position of child to be deleted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return @c -1.
 *
 * @see eina_model_child_del()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_children_del(const Eina_Model_Interface *iface,
                                                 Eina_Model *model,
                                                 unsigned int position) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Insert child using @a iface's function to insert children.
 * @param iface The children interface whose insert method will be called.
 * @param model The model instance.
 * @param position Position in which to insert @a child.
 * @param child Value(child) to be inserted.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return @c -1.
 *
 * @see eina_model_child_insert_at()
 * @since 1.2
 */
EAPI Eina_Bool eina_model_interface_children_insert_at(const Eina_Model_Interface *iface,
                                                       Eina_Model *model,
                                                       unsigned int position,
                                                       Eina_Model *child) EINA_ARG_NONNULL(1, 2, 4);
/**
 * @brief Sort children using @a iface's function to sort children.
 * @param iface The children interface whose sort method will be called.
 * @param model The model instance.
 * @param compare Function used to compare children.
 *
 * @warning If either model doesn't implement @a iface will do nothing and
 * return @c -1.
 *
 * @see eina_model_child_sort().
 * @since 1.2
 */
EAPI void eina_model_interface_children_sort(const Eina_Model_Interface *iface,
                                             Eina_Model *model,
                                             Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3);


/**
 * @}
 */

/**
 * @defgroup Eina_Model_Utils_Group Data Model Utilities
 *
 * Miscellaneous utilities to help usage or debug of @ref Eina_Model_Group.
 *
 * @{
 */

/**
 * @brief Checks if @a model is an instance of @a type.
 * @param model The model instance.
 * @param type The type being checked for.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see eina_model_new()
 * @see _Eina_Model_Type
 * @since 1.2
 */
EAPI Eina_Bool eina_model_instance_check(const Eina_Model *model,
                                         const Eina_Model_Type *type) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE;

/**
 * @brief Checks if @a model implements @a iface.
 * @param model The model instance.
 * @param iface The interface being checked for.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * @see _Eina_Model_Interface
 * @since 1.2
 */
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;

/**
 * @brief Returns the number of references to @a model.
 * @param model The model to query number of references.
 * @return Number of references to model.
 *
 * @see eina_model_ref()
 * @see eina_model_unref()
 * @see eina_model_xref()
 * @see eina_model_xunref()
 * @see eina_model_xrefs_get()
 * @since 1.2
 */
EAPI int eina_model_refcount(const Eina_Model *model) EINA_ARG_NONNULL(1);

/**
 * @typedef Eina_Model_XRef
 * Extended reference to model.
 *
 * This is returned by eina_model_xrefs_get() and should never be
 * modified. It is managed by eina_model_xref() and
 * eina_model_xunref() when @c EINA_MODEL_DEBUG is set to "1" or
 * "backtrace".
 *
 * @see #_Eina_Model_XRef explains fields.
 * @since 1.2
 */
typedef struct _Eina_Model_XRef Eina_Model_XRef;

/**
 * @struct _Eina_Model_XRef
 * Extended reference to model.
 *
 * This is returned by eina_model_xrefs_get() and should never be
 * modified. It is managed by eina_model_xref() and
 * eina_model_xunref() when @c EINA_MODEL_DEBUG is set to "1" or
 * "backtrace".
 *
 * @see eina_model_xrefs_get()
 * @see eina_models_usage_dump()
 * @since 1.2
 */
struct _Eina_Model_XRef
{
   EINA_INLIST;
   const void *id; /**< as given to eina_model_xref() */
   struct {
      const void * const *symbols; /**< only if @c EINA_MODEL_DEBUG=backtrace is set, otherwise is @c NULL */
      unsigned int count; /**< only if @c EINA_MODEL_DEBUG=backtrace is set, otherwise is 0 */
   } backtrace;
   char label[]; /**< Any given label given to eina_model_xref(). */
};

/**
 * @brief Returns the current references of this model.
 * @param model The model to query references.
 * @return List of reference holders as Eina_Model_XRef. This is the internal
 *         list for speed purposes, do not modify or free it in anyway!
 *
 * @note This list only exist if environment variable
 *       @c EINA_MODEL_DEBUG is set to "1" or "backtrace".
 *
 * @note The backtrace information is only available if environment
 *       variable @c EINA_MODEL_DEBUG=backtrace is set.
 * @since 1.2
 */
EAPI const Eina_Inlist *eina_model_xrefs_get(const Eina_Model *model) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC;

/**
 * @brief Dump usage of all existing modules.
 * @since 1.2
 */
EAPI void eina_models_usage_dump(void);

/**
 * @brief Return a list of all live models.
 * @return a newly allocated list of Eina_Model. Free using
 *         eina_models_list_free()
 *
 * @note this is meant to debug purposes, do not modify the models in
 *       any way!
 *
 * @note due performance reasons, this is only @b enabled when
 *       @c EINA_MODEL_DEBUG is set to "1" or "backtrace".
 *
 * @since 1.2
 */
EAPI Eina_List *eina_models_list_get(void);

/**
 * @brief Release list returned by eina_models_list_get()
 * @param list the list to release.
 */
EAPI void eina_models_list_free(Eina_List *list);

/**
 * @}
 */

/**
 * @var EINA_MODEL_INTERFACE_CHILDREN_INARRAY
 *
 * Implements #Eina_Model_Interface_Children
 * (#EINA_MODEL_INTERFACE_NAME_CHILDREN) using #Eina_Inarray. It
 * should be efficient in space and time for most operations.
 *
 * @note it may become slow if eina_model_child_insert_at() is used at(or near)
 *       the beginning of the array as the members from that position
 *       to the end must be memmove()d.
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Interface *EINA_MODEL_INTERFACE_CHILDREN_INARRAY;


/**
 * @var EINA_MODEL_TYPE_BASE
 * Base type for all eina model types.
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_BASE;

/**
 * @var EINA_MODEL_TYPE_MIXIN
 *
 * Type that uses #EINA_MODEL_INTERFACE_NAME_PROPERTIES
 * and #EINA_MODEL_INTERFACE_NAME_CHILDREN to manage the model.
 *
 * This is an abstract type, it does not work out of the box as one
 * needs to subclass it and define the interface implementations for
 * properties and children, as done by #EINA_MODEL_TYPE_GENERIC
 *
 * @see EINA_MODEL_TYPE_GENERIC
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_MIXIN;

/**
 * @var EINA_MODEL_TYPE_GENERIC
 *
 * Subclass of #EINA_MODEL_TYPE_MIXIN that
 * uses #EINA_MODEL_INTERFACE_PROPERTIES_HASH
 * and #EINA_MODEL_INTERFACE_CHILDREN_INARRAY.
 *
 * Should be generic enough to hold lots of items with runtime
 * configurable properties of any type.
 *
 * @see #EINA_MODEL_TYPE_STRUCT
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_GENERIC;

/**
 * @var EINA_MODEL_TYPE_STRUCT
 *
 * Subclass of #EINA_MODEL_TYPE_MIXIN that
 * uses #EINA_MODEL_INTERFACE_PROPERTIES_STRUCT
 * and #EINA_MODEL_INTERFACE_CHILDREN_INARRAY.
 *
 * Should be struct enough to hold lots of items with compile time
 * configurable properties of any type.
 *
 * @see #EINA_MODEL_TYPE_GENERIC
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_STRUCT;

/**
 * @brief Create and setup an instance of #EINA_MODEL_TYPE_STRUCT.
 * @param desc struct description to use for properties.
 * @return newly created and set model, or @c NULL on errors.
 *
 * @see eina_model_type_struct_new()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_struct_new(const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC;

/**
 * @brief Create and setup an instance of type subclass of #EINA_MODEL_TYPE_STRUCT.
 * @param type a type which is subclass of #EINA_MODEL_TYPE_STRUCT.
 * @param desc struct description to use for properties.
 * @return newly created and set model, or @c NULL on errors.
 *
 * @see eina_model_struct_new()
 * @since 1.2
 */
EAPI Eina_Model *eina_model_type_struct_new(const Eina_Model_Type *type,
                                            const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_MALLOC;


/**
 * @brief Configure the internal properties of model implementing #EINA_MODEL_INTERFACE_PROPERTIES_STRUCT.
 * @param model The model instance to configure.
 * @param desc The structure description to use.
 * @param memory If not @c NULL, will be copied by model.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This will setup the internal pointers so that the given @a desc is
 * used to manage the properties of this struct.
 *
 * If a given memory is provided, it will be copied (including
 * members) and no references are taken after this function returns.
 *
 * @see #EINA_VALUE_TYPE_STRUCT
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_struct_set(Eina_Model *model,
                                     const Eina_Value_Struct_Desc *desc,
                                     void *memory) EINA_ARG_NONNULL(1, 2);
/**
 * @brief Get the internal properties of model implementing #EINA_MODEL_INTERFACE_PROPERTIES_STRUCT.
 * @param model the model instance.
 * @param p_desc where to return the structure description in use.
 * @param p_memory where to return the structure memory in use.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * No copies are made! The memory and description may be invalidaded
 * by calls to eina_model_struct_set() or eina_model_del().
 *
 * @since 1.2
 */
EAPI Eina_Bool eina_model_struct_get(const Eina_Model *model,
                                     const Eina_Value_Struct_Desc **p_desc,
                                     void **p_memory) EINA_ARG_NONNULL(1, 2);

/**
 * @var EINA_MODEL_INTERFACE_NAME_PROPERTIES
 *
 * Interface that uses #Eina_Model_Interface_Properties
 * as #Eina_Model_Interface and can manage the model properties.
 *
 * @since 1.2
 */
EAPI extern const char *EINA_MODEL_INTERFACE_NAME_PROPERTIES;

/**
 * @var EINA_MODEL_INTERFACE_PROPERTIES_HASH
 *
 * Implements #Eina_Model_Interface_Properties
 * (#EINA_MODEL_INTERFACE_NAME_PROPERTIES) using #Eina_Hash.
 *
 * @note This function is generic but uses too much space given the
 *       hash data type. For huge number of elements it's better to
 *       use custom implementation instead.
 *
 * @see EINA_MODEL_INTERFACE_PROPERTIES_STRUCT
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Interface *EINA_MODEL_INTERFACE_PROPERTIES_HASH;

/**
 * @var EINA_MODEL_INTERFACE_PROPERTIES_STRUCT
 *
 * Implements #Eina_Model_Interface_Properties
 * (#EINA_MODEL_INTERFACE_NAME_PROPERTIES) using #Eina_Value_Struct.
 *
 * The interface private data is #Eina_Value of
 * type #EINA_VALUE_TYPE_STRUCT. Properties will be accessed using
 * Eina_Value_Struct::desc information that can be set by types such
 * as #EINA_MODEL_TYPE_STRUCT
 *
 * @see EINA_MODEL_INTERFACE_PROPERTIES_HASH
 *
 * @since 1.2
 */
EAPI extern const Eina_Model_Interface *EINA_MODEL_INTERFACE_PROPERTIES_STRUCT;

/**
 * @var EINA_MODEL_INTERFACE_NAME_CHILDREN
 *
 * Interface that uses #Eina_Model_Interface_Children
 * as #Eina_Model_Interface and can manage the model children.
 *
 * @since 1.2
 */
EAPI extern const char *EINA_MODEL_INTERFACE_NAME_CHILDREN;

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */
#endif