

This example describes the usage of \mbox{\hyperlink{group__Eina__Inline__List__Group_gad93973c87f867f249482e936797096ad}{Eina\+\_\+\+Inlist}} mixed with \mbox{\hyperlink{group__Eina__List__Group_ga3295e1210efea1fb0fd6acbf3cbc1f29}{Eina\+\_\+\+List}} . We create and add elements to an inlist, and the even members are also added to a normal list. Later we remove the elements divisible by 3 from this normal list.

The struct that is going to be used is the same used in \mbox{\hyperlink{eina_inlist_01_example_page}{Eina\+\_\+\+Inlist basic usage}} , since we still need the \mbox{\hyperlink{group__Eina__Inline__List__Group_gab30a76fcfa50307c797491705d60136a}{EINA\+\_\+\+INLIST}} macro to declare the inlist node info\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{struct\ }my\_struct\ \{}
\DoxyCodeLine{\ \ \ \ \ \mbox{\hyperlink{group__Eina__Inline__List__Group_gab30a76fcfa50307c797491705d60136a}{EINA\_INLIST}};}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordtype}{int}\ a,\ b;}
\DoxyCodeLine{\};}

\end{DoxyCodeInclude}
 The resulting node representing this struct can be exemplified by the following picture\+:

  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth,height=\textheight/2,keepaspectratio=true]{eina_inlist-node_eg2-my-struct}}
\end{DoxyImageNoCaption}


Now we need some pointers and auxiliary variables that will help us iterate on the lists\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }my\_struct\ *d,\ *cur;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ i;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__Inlist}{Eina\_Inlist}}\ *inlist\ =\ NULL;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *list\ =\ NULL,\ *l\_itr,\ *l\_next;}

\end{DoxyCodeInclude}
 Allocating 100 elements and putting them into an inlist, and the even elements also go to the normal list\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ 100;\ i++)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ d\ =\ malloc(\textcolor{keyword}{sizeof}(*d));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ d-\/>a\ =\ i;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ d-\/>b\ =\ i\ *\ 10;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ inlist\ =\ \mbox{\hyperlink{group__Eina__Inline__List__Group_gaef650e653f43178ecfee2c661bea7a85}{eina\_inlist\_append}}(inlist,\ \mbox{\hyperlink{group__Eina__Inline__List__Group_ga5bc991428e75557c6195f6b9e38321fb}{EINA\_INLIST\_GET}}(d));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((i\ \%\ 2)\ ==\ 0)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga4a2716e8fba1c3f60e3b112caef26fb9}{eina\_list\_prepend}}(list,\ d);}
\DoxyCodeLine{\ \ \ \ \ \}}

\end{DoxyCodeInclude}
 After this point, what we have are two distinct lists that share some elements. The first list (inlist) is defined by the pointers inside the elements data structure, while the second list (normal list) has its own node data structure that is kept outside of the elements.

The two lists, sharing some elements, can be represented by the following picture\+:

  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{eina_inlist-node_eg2-list-inlist}}
\end{DoxyImageNoCaption}


Accessing both lists is done normally, as if they didn\textquotesingle{}t have any elements in common\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}inlist=\%p\(\backslash\)n"{}},\ inlist);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__List__Group_ga65e496b9b16d527d23c1d735652b4e62}{EINA\_INLIST\_FOREACH}}(inlist,\ cur)}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}\(\backslash\)ta=\%d,\ b=\%d\(\backslash\)n"{}},\ cur-\/>a,\ cur-\/>b);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}list=\%p\(\backslash\)n"{}},\ list);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}}(list,\ l\_itr,\ cur)}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}\(\backslash\)ta=\%d,\ b=\%d\(\backslash\)n"{}},\ cur-\/>a,\ cur-\/>b);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}inlist\ count=\%d\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__Inline__List__Group_ga3039bdea008dcb10d52f648d154690f8}{eina\_inlist\_count}}(inlist));}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}list\ count=\%d\(\backslash\)n\(\backslash\)n"{}},\ eina\_list\_count(list));}

\end{DoxyCodeInclude}
 We can remove elements from the normal list, but we just don\textquotesingle{}t free them because they are still stored in the inlist\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__List__Group_ga5b4d2aac696cd2558aaed03e3929d873}{EINA\_LIST\_FOREACH\_SAFE}}(list,\ l\_itr,\ l\_next,\ cur)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((cur-\/>a\ \%\ 3)\ ==\ 0)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ list\ =\ \mbox{\hyperlink{group__Eina__List__Group_gaf86ee0fd9fe0643ece301fc86f04e720}{eina\_list\_remove\_list}}(list,\ l\_itr);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}inlist\ count=\%d\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__Inline__List__Group_ga3039bdea008dcb10d52f648d154690f8}{eina\_inlist\_count}}(inlist));}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}list\ count=\%d\(\backslash\)n\(\backslash\)n"{}},\ eina\_list\_count(list));}

\end{DoxyCodeInclude}
 To finish this example, we want to free both lists, we can\textquotesingle{}t just free all elements on the second list (normal list) because they are still being used in the inlist. So we first discard the normal list without freeing its elements, then we free all elements in the inlist (that contains all elements allocated until now)\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__List__Group_ga82a1bfa543e21853f9ea3ff88dd1250b}{eina\_list\_free}}(list);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{while}\ (inlist)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{struct\ }my\_struct\ *aux\ =\ \mbox{\hyperlink{group__Eina__Inline__List__Group_ga8c4e6011e7caa9ec5c22b003c4950338}{EINA\_INLIST\_CONTAINER\_GET}}(inlist,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{struct}\ my\_struct);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ inlist\ =\ \mbox{\hyperlink{group__Eina__Inline__List__Group_gaf885b08d5b5a750a901f3780d3c65338}{eina\_inlist\_remove}}(inlist,\ inlist);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ free(aux);}
\DoxyCodeLine{\ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Here is the full source code for this example\+: \mbox{\hyperlink{eina_inlist_02_c}{eina\+\_\+inlist\+\_\+02.\+c Eina\+\_\+\+Inlist advanced usage -\/ lists and inlists source}} 