Commit 5a087664 authored by Cedric BAIL's avatar Cedric BAIL

* eet: Add an experimentale API for walking Eet_Node.

	This API should be used to generate native scripting object from
	an Eet_Data.


SVN revision: 45389
parent 33ba2279
......@@ -313,3 +313,7 @@
2010-01-17 Cedric BAIL
* Add a mempool for Eet_Node.
2010-01-21 Cedric BAIL
* Add experimental API to walk Eet_Node tree.
......@@ -111,9 +111,40 @@ extern "C" {
typedef struct _Eet_Data_Descriptor Eet_Data_Descriptor;
typedef struct _Eet_Key Eet_Key;
typedef struct _Eet_Node Eet_Node;
typedef struct _Eet_Node_Data Eet_Node_Data;
typedef struct _Eet_Node_Walk Eet_Node_Walk;
typedef struct _Eet_Data_Descriptor_Class Eet_Data_Descriptor_Class;
struct _Eet_Node_Data
{
union {
char c;
short s;
int i;
long long l;
float f;
double d;
unsigned char uc;
unsigned short us;
unsigned int ui;
unsigned long long ul;
const char *str;
} value;
};
struct _Eet_Node_Walk
{
void *(*struct_alloc)(const char *type, void *user_data);
void (*struct_add)(void *parent, const char *name, void *child, void *user_data);
void *(*array)(Eina_Bool variable, const char *name, int count, void *user_data);
void (*insert)(void *array, int index, void *child, void *user_data);
void *(*list)(const char *name, void *user_data);
void (*append)(void *list, void *child, void *user_data);
void *(*hash)(void *parent, const char *name, const char *key, void *value, void *user_data);
void *(*simple)(int type, Eet_Node_Data *data, void *user_data);
};
#define EET_DATA_DESCRIPTOR_CLASS_VERSION 2
struct _Eet_Data_Descriptor_Class
{
......@@ -1507,6 +1538,9 @@ eet_dictionary_string_check * example: values), and @p type is the basic data
EAPI Eet_Node *eet_data_node_read_cipher(Eet_File *ef, const char *name, const char *key);
EAPI int eet_data_node_write_cipher(Eet_File *ef, const char *name, const char *key, Eet_Node *node, int compress);
/* EXPERIMENTAL: THIS API MAY CHANGE IN THE FUTUR, USE IT ONLY IF YOU KNOW WHAT YOU ARE DOING. */
EAPI void *eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data);
/***************************************************************************/
#ifdef __cplusplus
......
......@@ -61,19 +61,7 @@ struct _Eet_Node
Eet_Node *values;
Eet_Node *next;
Eet_Node *parent;
union {
char c;
short s;
int i;
long long l;
float f;
double d;
unsigned char uc;
unsigned short us;
unsigned int ui;
unsigned long long ul;
const char *str;
} data;
Eet_Node_Data data;
};
/*
......
......@@ -1947,7 +1947,7 @@ _eet_data_dump_encode(int parent_type,
{
case EET_T_STRING:
case EET_T_INLINED_STRING:
data = eet_data_put_type(ed, n->type, &(n->data.str), &size);
data = eet_data_put_type(ed, n->type, &(n->data.value.str), &size);
if (data) eet_data_encode(ed, ds, data, node->name, size, n->type, node->type);
break;
case EET_T_NULL:
......@@ -1982,7 +1982,7 @@ _eet_data_dump_encode(int parent_type,
{
case EET_T_STRING:
case EET_T_INLINED_STRING:
data = eet_data_put_type(ed, n->type, &(n->data.str), &size);
data = eet_data_put_type(ed, n->type, &(n->data.value.str), &size);
if (data) eet_data_encode(ed, ds, data, node->name, size, n->type, node->type);
break;
case EET_T_NULL:
......@@ -2022,7 +2022,7 @@ _eet_data_dump_encode(int parent_type,
{
case EET_T_STRING:
case EET_T_INLINED_STRING:
data = eet_data_put_type(ed, n->type, &(n->data.str), &size);
data = eet_data_put_type(ed, n->type, &(n->data.value.str), &size);
if (data) eet_data_encode(ed, ds, data, node->name, size, n->type, node->type);
break;
case EET_T_NULL:
......@@ -2045,7 +2045,7 @@ _eet_data_dump_encode(int parent_type,
#define EET_DATA_NODE_ENCODE(Eet_Type, Type) \
case Eet_Type: \
data = eet_data_put_type(ed, node->type, &(node->data.Type), &size); \
data = eet_data_put_type(ed, node->type, &(node->data.value.Type), &size); \
if (data) \
{ \
eet_data_encode(ed, ds, data, node->name, size, node->type, parent_type); \
......@@ -2214,67 +2214,67 @@ _eet_data_dump_parse(Eet_Dictionary *ed,
if (!strcmp(tok3, "char:"))
{
n->type = EET_T_CHAR;
sscanf(tok4, "%hhi", &(n->data.c));
sscanf(tok4, "%hhi", &(n->data.value.c));
}
else if (!strcmp(tok3, "short:"))
{
n->type = EET_T_SHORT;
sscanf(tok4, "%hi", &(n->data.s));
sscanf(tok4, "%hi", &(n->data.value.s));
}
else if (!strcmp(tok3, "int:"))
{
n->type = EET_T_INT;
sscanf(tok4, "%i", &(n->data.i));
sscanf(tok4, "%i", &(n->data.value.i));
}
else if (!strcmp(tok3, "long_long:"))
{
n->type = EET_T_LONG_LONG;
sscanf(tok4, "%lli", &(n->data.l));
sscanf(tok4, "%lli", &(n->data.value.l));
}
else if (!strcmp(tok3, "float:"))
{
n->type = EET_T_FLOAT;
sscanf(tok4, "%f", &(n->data.f));
sscanf(tok4, "%f", &(n->data.value.f));
}
else if (!strcmp(tok3, "double:"))
{
n->type = EET_T_DOUBLE;
sscanf(tok4, "%lf", &(n->data.d));
sscanf(tok4, "%lf", &(n->data.value.d));
}
else if (!strcmp(tok3, "uchar:"))
{
n->type = EET_T_UCHAR;
sscanf(tok4, "%hhu", &(n->data.uc));
sscanf(tok4, "%hhu", &(n->data.value.uc));
}
else if (!strcmp(tok3, "ushort:"))
{
n->type = EET_T_USHORT;
sscanf(tok4, "%hu", &(n->data.us));
sscanf(tok4, "%hu", &(n->data.value.us));
}
else if (!strcmp(tok3, "uint:"))
{
n->type = EET_T_UINT;
sscanf(tok4, "%u", &(n->data.ui));
sscanf(tok4, "%u", &(n->data.value.ui));
}
else if (!strcmp(tok3, "ulong_long:"))
{
n->type = EET_T_ULONG_LONG;
sscanf(tok4, "%llu", &(n->data.ul));
sscanf(tok4, "%llu", &(n->data.value.ul));
}
else if (!strcmp(tok3, "string:"))
{
n->type = EET_T_STRING;
n->data.str = eina_stringshare_add(tok4);
n->data.value.str = eina_stringshare_add(tok4);
}
else if (!strcmp(tok3, "inlined:"))
{
n->type = EET_T_INLINED_STRING;
n->data.str = eina_stringshare_add(tok4);
n->data.value.str = eina_stringshare_add(tok4);
}
else if (!strcmp(tok3, "null"))
{
n->type = EET_T_NULL;
n->data.str = NULL;
n->data.value.str = NULL;
}
else
{
......
......@@ -75,7 +75,7 @@ _eet_node_append(Eet_Node *n, Eina_List *nodes)
n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \
\
n->data.Value = Value; \
n->data.value.Value = Value; \
\
return n; \
}
......@@ -89,7 +89,7 @@ _eet_node_append(Eet_Node *n, Eina_List *nodes)
n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \
\
n->data.Value = eina_stringshare_add(Value); \
n->data.value.Value = eina_stringshare_add(Value); \
\
return n; \
}
......@@ -115,7 +115,7 @@ eet_node_null_new(const char *name)
n = _eet_node_new(name, EET_T_NULL);
if (!n) return NULL;
n->data.str = NULL;
n->data.value.str = NULL;
return n;
}
......@@ -328,7 +328,7 @@ eet_node_del(Eet_Node *n)
break;
case EET_T_STRING:
case EET_T_INLINED_STRING:
eina_stringshare_del(n->data.str);
eina_stringshare_del(n->data.value.str);
break;
case EET_T_CHAR:
case EET_T_SHORT:
......@@ -442,7 +442,7 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
case Eet_Type: \
{ \
dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]); \
snprintf(tbuf, sizeof (tbuf), eet_node_dump_t_name[Eet_Type][1], n->data.Type); \
snprintf(tbuf, sizeof (tbuf), eet_node_dump_t_name[Eet_Type][1], n->data.value.Type); \
dumpfunc(dumpdata, tbuf); \
break; \
}
......@@ -465,7 +465,7 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
if (!type_name) type_name = "string: \"";
dumpfunc(dumpdata, type_name);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.str);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str);
dumpfunc(dumpdata, "\"");
break;
case EET_T_NULL:
......@@ -561,6 +561,68 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
}
}
void*
eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data)
{
Eet_Node *it;
void *me = NULL;
int i;
if (!root)
{
if (parent) cb->struct_add(parent, name, NULL, user_data);
return NULL;
}
switch (root->type)
{
case EET_G_UNKNOWN:
me = cb->struct_alloc(root->name, user_data);
for (it = root->values; it != NULL; it = it->next)
eet_node_walk(me, it->name, it, cb, user_data);
break;
case EET_G_VAR_ARRAY:
case EET_G_ARRAY:
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data);
for (i = 0, it = root->values; it != NULL; it = it->next)
cb->insert(me, i++, eet_node_walk(NULL, NULL, it, cb, user_data), user_data);
break;
case EET_G_LIST:
me = cb->list(root->name, user_data);
for (it = root->values; it != NULL; it = it->next)
cb->append(me, eet_node_walk(NULL, NULL, it, cb, user_data), user_data);
break;
case EET_G_HASH:
if (!parent) return NULL;
return cb->hash(parent, root->name, root->key, eet_node_walk(NULL, NULL, root->values, cb, user_data), user_data);
case EET_T_STRING:
case EET_T_INLINED_STRING:
case EET_T_CHAR:
case EET_T_SHORT:
case EET_T_INT:
case EET_T_LONG_LONG:
case EET_T_FLOAT:
case EET_T_DOUBLE:
case EET_T_UCHAR:
case EET_T_USHORT:
case EET_T_UINT:
case EET_T_ULONG_LONG:
me = cb->simple(root->type, &root->data, user_data);
break;
}
if (parent) cb->struct_add(parent, name, me, user_data);
return me;
};
int
eet_node_init(void)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment