Mobile native

[UI Sample] InList Sample Overview

The InList sample demonstrates how to manage inline list using EFL InList functions. If you do not fully understand these functions, use regular lists instead.

Inline list is a list with nodes inlined into user types. This means that the node pointers share the same memory with the data. Inline lists fragment the memory less and avoid node -> data indirection, however, they have a higher cost for some common operations, like count and sort.

The following log shows the result of the InList sample.

I/inlist_tag( 3390): list=0xb85638e0
I/inlist_tag( 3390): 	a=3, b=30
I/inlist_tag( 3390): 	a=1, b=10
I/inlist_tag( 3390): 	a=2, b=20
I/inlist_tag( 3390): list after sort=0xb85151e0
I/inlist_tag( 3390): 	a=1, b=10
I/inlist_tag( 3390): 	a=2, b=20
I/inlist_tag( 3390): 	a=3, b=30
I/inlist_tag( 3390): 	a=4, b=40

Implementation

The create_base_gui() function utilizes InList to sort given numbers in variables a and b. Basically, a node of the list is created with data a and b with struct. The eina_inlist_append() function creates a head node and later appends and prepends other list nodes with different data using the eina_inlist_append() and eina_inlist_prepend() functions to the existing InList nodes. The eina_inlist_append_relative() and eina_inlist_demote() functions place an InList at the beginning and at the end of the existing ones. The eina_inlist_sort function sorts the data in order. The dlog_print() function of the Core API is used to print the sorted data by using the dlogutil command in the Tizen SDB.

struct my_struct 
{
   EINA_INLIST;
   int a, b;
};

int sort_cb(const void *d1, const void *d2)
{
   const Eina_Inlist *l1, *l2;
   const struct my_struct *x1, *x2;
   l1 = d1;
   l2 = d2;
   x1 = EINA_INLIST_CONTAINER_GET(l1, struct my_struct);
   x2 = EINA_INLIST_CONTAINER_GET(l2, struct my_struct);
   return x1->a - x2->a;
}

static void
create_base_gui(appdata_s *ad)
{
   // Window 
   ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
   elm_win_autodel_set(ad->win, EINA_TRUE);
   evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);

   // InList Code
   struct my_struct *d, *cur;
   Eina_Inlist *list, *itr, *tmp;
   d = malloc(sizeof(*d));
   d->a = 1;
   d->b = 10;
   list = eina_inlist_append(NULL, EINA_INLIST_GET(d));
   d = malloc(sizeof(*d));
   d->a = 2;
   d->b = 20;
   list = eina_inlist_append(list, EINA_INLIST_GET(d));
   d = malloc(sizeof(*d));
   d->a = 3;
   d->b = 30;
   list = eina_inlist_prepend(list, EINA_INLIST_GET(d));
   dlog_print(DLOG_INFO, "inlist_tag", "list=%p\n", list);
   EINA_INLIST_FOREACH(list, cur);
   dlog_print(DLOG_INFO, "inlist_tag","\ta=%d, b=%d\n", cur->a, cur->b);
   list = eina_inlist_promote(list, EINA_INLIST_GET(d));
   d = malloc(sizeof(*d));
   d->a = 4;
   d->b = 40;
   list = eina_inlist_append_relative(list, EINA_INLIST_GET(d), list);
   list = eina_inlist_demote(list, EINA_INLIST_GET(d));
   list = eina_inlist_sort(list, sort_cb);
   dlog_print(DLOG_INFO, "inlist_tag","list after sort=%p\n", list);
   EINA_INLIST_FOREACH(list, cur)
   dlog_print(DLOG_INFO, "inlist_tag","\ta=%d, b=%d\n", cur->a, cur->b);
   tmp = eina_inlist_find(list, EINA_INLIST_GET(d));
   if (tmp)
      cur = EINA_INLIST_CONTAINER_GET(tmp, struct my_struct);
   else
      cur = NULL;
   if (d != cur)
      dlog_print(DLOG_INFO, "inlist_tag","wrong node! cur=%p\n", cur);
   list = eina_inlist_remove(list, EINA_INLIST_GET(d));
   free(d);
   printf("list=%p\n", list);
   for (itr = list; itr != NULL; itr = itr->next)
   {
      cur = EINA_INLIST_CONTAINER_GET(itr, struct my_struct);
      printf("\ta=%d, b=%d\n", cur->a, cur->b);
   }

   while (list)
   {
      struct my_struct *aux = EINA_INLIST_CONTAINER_GET(list,struct my_struct);
      list = eina_inlist_remove(list, list);
      free(aux);
   }

   // Window UI can be ignored from this sample as dlog_print is used to show the result
   // Show the window after the base GUI is set up 
   evas_object_show(ad->win);

   ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, keydown_cb, ad);
}
Go to top