Re: is GBoxed the way to wrap things like GList, GHashMap, ... [resend]



On Fri, 2005-04-22 at 08:37 +0200, Stefan Kost wrote:
hi,

Several of my GObjects provide thgs like GList or GHashmap as readable 
properties. Unfortunately these properties are just gpointers.
For the file-serialisation it would be nice to know whats behind the pointer. Is 
GBoxed the way to go? This modules has only vague docs, especially what it is for.

For GList I assume I would do:

#define MY_TYPE_BOXED_LIST my_boxed_list_get_type();

GType my_boxed_list_get_type (void)
{
   static GType type = 0;
   if (type == 0) {
     type = g_boxed_type_register_static("MyBoxedList",
         my_boxed_list_copy,my_boxed_list_free);
   }
   return type;
}

gpointer my_boxed_list_copy (GType boxed_type, gconstpointer src_boxed)
{
   return g_list_copy (src_boxed);
}

gpointer my_boxed_list_free (GType boxed_type, gpointer boxed)
{
   return g_list_free (boxed);
}

For the properties I would install a g_param_spec_boxed with the type = 
MY_TYPE_BOXED_LIST?

Yes, this will work. Of course, "GList" isn't a very useful object type,
you can't serialize a "list" - you need to know what it is a list of.
So, for many cases you might as well use G_TYPE_POINTER, unless you
actually want the copies for memory management reasons.

Does that makes sense? Or can anyone point me to a more complete example?

There are many examples of boxed types in GTK+. But we generally avoid
properties and signal parameters of type GList because it doesn't work
for language bindings. You'd need parameterized types for that, which
we've never really wanted to add to GObject.

Regards,
                                                Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]