\hypertarget{eina_value_02_8c-example}{}\section{eina\+\_\+value\+\_\+02.\+c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc eina\_value\_02.c -o eina\_value\_02 `pkg-config --cflags --libs eina`}

\textcolor{preprocessor}{#include <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}

\textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__Value__Struct__Desc}{Eina\_Value\_Struct\_Desc}} *V1\_DESC = NULL;
\textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__Value__Struct__Desc}{Eina\_Value\_Struct\_Desc}} *V2\_DESC = NULL;

\textcolor{keywordtype}{void} value\_init(\textcolor{keywordtype}{void})
\{
   \textcolor{keyword}{typedef} \textcolor{keyword}{struct }\_My\_Struct\_V1 \{
     \textcolor{keywordtype}{int} param1;
     \textcolor{keywordtype}{char} param2;
   \} My\_Struct\_V1;


   \textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__Value__Struct__Member}{Eina\_Value\_Struct\_Member}} v1\_members[] = \{
     \textcolor{comment}{// no eina\_value\_type as they are not constant initializers, see below.}
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga139206ef35b0b76e87eef56a202c0ae9}{EINA\_VALUE\_STRUCT\_MEMBER}}(NULL, My\_Struct\_V1, param1),
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga139206ef35b0b76e87eef56a202c0ae9}{EINA\_VALUE\_STRUCT\_MEMBER}}(NULL, My\_Struct\_V1, param2)
   \};
   v1\_members[0].\mbox{\hyperlink{struct__Eina__Value__Struct__Member_a615cdf08597bd18623c8c7daec7b4641}{type}} = \mbox{\hyperlink{group__Eina__Value__Group_ga17974fd9ab773a3efefd591ffde58f77}{EINA\_VALUE\_TYPE\_INT}};
   v1\_members[1].\mbox{\hyperlink{struct__Eina__Value__Struct__Member_a615cdf08597bd18623c8c7daec7b4641}{type}} = \mbox{\hyperlink{group__Eina__Value__Group_ga0d54e0b952b44b7ac4f2fd573f7839c0}{EINA\_VALUE\_TYPE\_CHAR}};
   \textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__Value__Struct__Desc}{Eina\_Value\_Struct\_Desc}} v1\_desc = \{
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_gae76aada4965672ce991f1f41baf71975}{EINA\_VALUE\_STRUCT\_DESC\_VERSION}},
     NULL, \textcolor{comment}{// no special operations}
     v1\_members,
     \mbox{\hyperlink{group__Eina__Types__Group_ga7c1b6f81660b4e30516169e9e7d3261c}{EINA\_C\_ARRAY\_LENGTH}}(v1\_members),
     \textcolor{keyword}{sizeof}(My\_Struct\_V1)
   \};
   V1\_DESC = &v1\_desc;

   \textcolor{keyword}{typedef} \textcolor{keyword}{struct }\_My\_Struct\_V2 \{
     \textcolor{keywordtype}{int} param1;
     \textcolor{keywordtype}{char} param2;
     \textcolor{keywordtype}{int} param3;
   \} My\_Struct\_V2;
   \textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__Value__Struct__Member}{Eina\_Value\_Struct\_Member}} v2\_members[] = \{
     \textcolor{comment}{// no eina\_value\_type as they are not constant initializers, see below.}
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga139206ef35b0b76e87eef56a202c0ae9}{EINA\_VALUE\_STRUCT\_MEMBER}}(NULL, My\_Struct\_V2, param1),
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga139206ef35b0b76e87eef56a202c0ae9}{EINA\_VALUE\_STRUCT\_MEMBER}}(NULL, My\_Struct\_V2, param2),
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga139206ef35b0b76e87eef56a202c0ae9}{EINA\_VALUE\_STRUCT\_MEMBER}}(NULL, My\_Struct\_V2, param3)
   \};
   v2\_members[0].\mbox{\hyperlink{struct__Eina__Value__Struct__Member_a615cdf08597bd18623c8c7daec7b4641}{type}} = \mbox{\hyperlink{group__Eina__Value__Group_ga17974fd9ab773a3efefd591ffde58f77}{EINA\_VALUE\_TYPE\_INT}};
   v2\_members[1].\mbox{\hyperlink{struct__Eina__Value__Struct__Member_a615cdf08597bd18623c8c7daec7b4641}{type}} = \mbox{\hyperlink{group__Eina__Value__Group_ga0d54e0b952b44b7ac4f2fd573f7839c0}{EINA\_VALUE\_TYPE\_CHAR}};
   v2\_members[2].\mbox{\hyperlink{struct__Eina__Value__Struct__Member_a615cdf08597bd18623c8c7daec7b4641}{type}} = \mbox{\hyperlink{group__Eina__Value__Group_ga17974fd9ab773a3efefd591ffde58f77}{EINA\_VALUE\_TYPE\_INT}};
   \textcolor{keyword}{static} \mbox{\hyperlink{struct__Eina__Value__Struct__Desc}{Eina\_Value\_Struct\_Desc}} v2\_desc = \{
     \mbox{\hyperlink{group__Eina__Value__Struct__Group_gae76aada4965672ce991f1f41baf71975}{EINA\_VALUE\_STRUCT\_DESC\_VERSION}},
     NULL, \textcolor{comment}{// no special operations}
     v2\_members,
     \mbox{\hyperlink{group__Eina__Types__Group_ga7c1b6f81660b4e30516169e9e7d3261c}{EINA\_C\_ARRAY\_LENGTH}}(v2\_members),
     \textcolor{keyword}{sizeof}(My\_Struct\_V2)
   \};
   V2\_DESC = &v2\_desc;
\}

\textcolor{keywordtype}{void} rand\_init(\mbox{\hyperlink{struct__Eina__Value}{Eina\_Value}} *v)
\{
   \textcolor{keywordflow}{if} (v->type != \mbox{\hyperlink{group__Eina__Value__Group_ga8147143699c5f5a686415090080d3f9e}{EINA\_VALUE\_TYPE\_STRUCT}})
     \textcolor{keywordflow}{return};

   \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga476aa64a399aba776fa14f2fb065b268}{eina\_value\_struct\_set}}(v, \textcolor{stringliteral}{"param1"}, rand());
   \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga476aa64a399aba776fa14f2fb065b268}{eina\_value\_struct\_set}}(v, \textcolor{stringliteral}{"param2"}, rand() % 256);
   \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga476aa64a399aba776fa14f2fb065b268}{eina\_value\_struct\_set}}(v, \textcolor{stringliteral}{"param3"}, rand());
\}

\textcolor{keywordtype}{void} my\_struct\_use(\mbox{\hyperlink{struct__Eina__Value}{Eina\_Value}} *params)
\{
   \textcolor{keywordtype}{int} p1, p3;
   \textcolor{keywordtype}{char} p2;

   \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga07a7cc420f03a247dffe4d13ce1ad6c5}{eina\_value\_struct\_get}}(params, \textcolor{stringliteral}{"param1"}, &p1);
   \mbox{\hyperlink{group__Eina__Value__Struct__Group_ga07a7cc420f03a247dffe4d13ce1ad6c5}{eina\_value\_struct\_get}}(params, \textcolor{stringliteral}{"param2"}, &p2);
   printf(\textcolor{stringliteral}{"param1: %d\(\backslash\)nparam2: %c\(\backslash\)n"}, p1, p2);

   \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__Eina__Value__Struct__Group_ga07a7cc420f03a247dffe4d13ce1ad6c5}{eina\_value\_struct\_get}}(params, \textcolor{stringliteral}{"param3"}, &p3))
     printf(\textcolor{stringliteral}{"param3: %d\(\backslash\)n"}, p3);
\}

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   (void)argc;
   (void)argv;
   \mbox{\hyperlink{struct__Eina__Value}{Eina\_Value}} *v1, *v2;

   \mbox{\hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}}();
   value\_init();
   srand(time(NULL));

   v1 = \mbox{\hyperlink{group__Eina__Value__Struct__Group_gaf469abb97ac59b73e8b2c726a58a78f8}{eina\_value\_struct\_new}}(V1\_DESC);
   v2 = \mbox{\hyperlink{group__Eina__Value__Struct__Group_gaf469abb97ac59b73e8b2c726a58a78f8}{eina\_value\_struct\_new}}(V2\_DESC);

   rand\_init(v1);
   my\_struct\_use(v1);

   rand\_init(v2);
   my\_struct\_use(v2);

   \mbox{\hyperlink{group__Eina__Value__Value__Group_gaa2aa7ac9d1fcd7c4497cf104cb374a52}{eina\_value\_free}}(v1);
   \mbox{\hyperlink{group__Eina__Value__Value__Group_gaa2aa7ac9d1fcd7c4497cf104cb374a52}{eina\_value\_free}}(v2);
   \mbox{\hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}}();
\}
\end{DoxyCodeInclude}
 