On Mon, 18 Apr 2011 11:26:16 +0900 Gina Jeong <[email protected]> said:
i'm replying to you and the e devel mailing list so people can see the reply.
attached code that works.
> Hello,
> I'm having using eet. I am trying to save a trie to a file. I have the
> following struct.
>
> typedef struct _tnode{
> char key[4];
> char *s;
> int count;
> struct _tnode *children[2208]; // array of pointers to the structure
> _tnode
> }tnode;
>
> So far, I have the following code for the descriptor
>
>
> /* code */
> tnode *root;
> int size;
> Eet_File *ef;
> Eet_Data_Descriptor *edd;
> Eet_Data_Descriptor_Class eddc;
>
> eet_init();
> EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, tnode);
> edd= eet_data_descriptor_stream_new(&eddc);
>
> EET_DATA_DESCRIPTOR_ADD_BASIC(edd, tnode, "key", key, EET_G_ARRAY);
> EET_DATA_DESCRIPTOR_ADD_BASIC(edd, tnode, "s", s, EET_T_STRING);
> EET_DATA_DESCRIPTOR_ADD_BASIC(edd, tnode, "count", count, EET_T_INT);
> EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, tnode, "children", children, tnode *);
>
> ...
> /* code to make the trie using the variable "root" as the root. */
> ...
> eet_shutdown();
>
> /* end of code*/
>
>
> However whenever I compile this at the command line using the command:
> gcc -o -c main.o main.c `pkg-config --cflags eet`
>
> I get the error at the line with
> EET_DATA_DESCRIPTOR_ADD_ARRAY(edd, tnode, "children", children, tnode *);
>
> I believe the last entry is suppose the specify the subtype of the array
> elements, in this case, it is a pointer to the struct _tnode. But the error
> at the command line comes up as :
> error: expected expression before ‘tnode’
>
> I believe the error is at the second occurrence of the word "tnode" because
> the EET_DATA_DESCRIPTOR_ADD_ARRAY is same as EET_DATA_DESCRIPTOR_ADD_BASIC
> except for the last entry. Is the last entry of
> EET_DATA_DESCRIPTOR_ADD_ARRAY incorrect? I thank you in advance for taking
> the time to help me.
>
> Gina
--
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler) [email protected]
#include <Eet.h>
#include <Eina.h>
#include <stdio.h>
typedef struct _tnodep tnodep;
typedef struct _tnode tnode;
struct _tnode
{
char key[4];
char *s;
int children_count;
tnodep *children;
};
struct _tnodep
{
tnode *p;
};
int
main(int argc, char **argv)
{
FILE *f;
Eet_Data_Descriptor_Class eddc;
Eet_Data_Descriptor *edd, *edd2;
tnode *t1, *t2, *t3, *t4, *tres;
void *data = NULL;
int size = 0;
eet_init();
// init descriptor class with standard eina type allocators for lists
// etc. we calso get malloc and free along for the ride.
EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, tnode);
edd = eet_data_descriptor_stream_new(&eddc);
// init a sub descriptor that is only used to hold a single pointer
EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, tnodep);
edd2 = eet_data_descriptor_stream_new(&eddc);
// only thing in here... pointer to main descriptor
EET_DATA_DESCRIPTOR_ADD_SUB(edd2, tnodep, "p", p, edd);
// continue with main descriptor
// FIXED size array of type char (EET_T_CHAR) at memeber key. we give
// this element the keyname of "k" (nice and short as we dont need longer).
// we use eet_data_descriptor_element_add(0 as no happy macro exists for
// something this simple. offsetof() is also a c99 thing to find out how
// many bytes in to a struct a member is.
eet_data_descriptor_element_add(edd, "k", EET_T_CHAR, EET_G_ARRAY,
offsetof(tnode, key), 4, NULL, NULL);
// add in the string - a simple type, and we call it "s" for a key.
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, tnode, "s", s, EET_T_STRING);
// add a variable sized array. it will be allocated in a separate chunk of
// memory to the main struct, so needs freeing on its own, and this macro
// ASSUMES you have a XXX_count var - eg children_count to store the
// count of items in the variable array. if you want to call it something
// else you'll have to call eet_data_descriptor_element_add() yourself
// and not use the convenience macro
EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY(edd, tnode, "c", children, edd2);
// build some data in memory
t1 = calloc(1, sizeof(tnode));
t2 = calloc(1, sizeof(tnode));
t3 = calloc(1, sizeof(tnode));
t4 = calloc(1, sizeof(tnode));
strcpy(t1->key, "abc");
t1->s = strdup("hello");
t1->children_count = 2;
t1->children = calloc(1, sizeof(tnodep) * 2);
t1->children[0].p = t2;
t1->children[1].p = t3;
strcpy(t2->key, "def");
t2->s = strdup("world");
t2->children_count = 1;
t2->children = calloc(1, sizeof(tnodep) * 1);
t2->children[0].p = t4;
strcpy(t3->key, "ghi");
t3->s = strdup("how goes it?");
strcpy(t4->key, "jkl");
t4->s = strdup("pants on!");
// encode that data and save it for posterity
data = eet_data_descriptor_encode(edd, t1, &size);
printf("encoded: %p size %i\n", data, size);
f = fopen("out.data", "w");
fwrite(data, size, 1, f);
fclose(f);
// decode that data back to a new struct tree
tres = eet_data_descriptor_decode(edd, data, size);
printf("tres->key[] = %s\n", tres->key);
printf("tres->s = %s\n", tres->s);
printf("tres->children_count = %i\n", tres->children_count);
printf("tres->children[0].p->key[] = %s\n", tres->children[0].p->key);
printf("tres->children[0].p->s = %s\n", tres->children[0].p->s);
printf("tres->children[0].p->children_count = %i\n", tres->children[0].p->children_count);
printf("tres->children[0].p->children[0]->key[] = %s\n", tres->children[0].p->children[0].p->key);
printf("tres->children[0].p->children[0]->s = %s\n", tres->children[0].p->children[0].p->s);
printf("tres->children[0].p->children[0]->children_count = %i\n", tres->children[0].p->children[0].p->children_count);
printf("tres->children[1].p->key[] = %s\n", tres->children[1].p->key);
printf("tres->children[1].p->s = %s\n", tres->children[1].p->s);
printf("tres->children[1].p->children_count = %i\n", tres->children[1].p->children_count);
eet_shutdown();
}
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel