Foreach...

Posted on 2005-01-12 13:58:35 EET.

I just noticed that future started last week :)

What I really hate is glib hash tables iterations. While there is ( seems to be nice ) g_hash_table_foreach function , it forces anyone to write additional routine functions which are passed as parameter and sometimes must call another foreach functions. This makes life very difficult.

While we need allocate some memory for GParamSpec which should be used to register midgard classes, we must know how many properties object should have.
GParamSpec *params = g_malloc(sizeof(GParamSpec*)*(number));

Our magic "number" can not be easily get while parsing xml file as it uses _get_elements_names function which is recursive one. g_hash_table_size is  very helpfull here , as we can get later hash size , increase by 1 ( to add NULL ) and call sizeof with correct number. Yeah, this is it. But we also need at this point number  of property. That's bad.
You may create some easy gint i value which may be used in function which is passed to g_hash_table_foreach. You may , but this value will be set to 0 with every function call. I decided to change midgard MgdHash structure which has gint and GHashTable, so simple hash has also something like index.

typedef struct
{
  GHashTable *hash;
  gint n;
}
MgdHash;

And this seems to work fine, as indexes are automagically created while xml schema file is parsed. Some more changes seems to be required before commiting code to cvs , especially when I noticed my silly mistake. I added two header files to main src core directory. Anyway header files should be changed a lot , so fresh ones should be added in correct place.

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS