Tizen Native API
Eina_Inlist basic usage

To see the full source for this example, click here: eina_inlist_01.c Eina_Inlist basic usage source

As explained before, inline lists mean its nodes pointers are part of same memory block/blob. This is done by using the macro EINA_INLIST inside the data structure that will be used:

The resulting node representing this struct can be exemplified by the following picture:

eina_inlist-node_eg1-my-struct.png

Let's define a comparison function that will be used later during the sorting of the list:

The Eina_Inlist can be used exactly the same way as Eina_List when appending, prepending and removing items. But since we already have the node pointers inside the structure, they need to be retrieved with the macro EINA_INLIST_GET :

Notice that eina_inlist_append always receives the head of the list as first argument, and its return value should be used as the list pointer (head):

After appending 3 items, the list now should look similar to this:

eina_inlist-node_eg1-inlist.png

The macro EINA_INLIST_FOREACH can be used to iterate over the list:

eina_inlist_promote(), eina_inlist_demote(), eina_inlist_append_relative() and similar functions all work in the same way as the Eina_List :

Now let's use the sort_cb function declared above to sort our list:

Removing an element from the inlist is also similar to Eina_List :

Another way of walking through the inlist.

Notice that in the previous piece of code, since we only have the pointers to the inlist nodes, we have to use the EINA_INLIST_CONTAINER_GET macro that will return the pointer to the entire structure. Of course, in this case it is the same as the list pointer, since the EINA_INLIST macro was used in the beginning of the structure.

Now to finish this example, lets delete this list: