Re: [gtk-list] number of GtkContainer childs ?




On Tue, 29 Jun 1999, Peter Lerner wrote:
> 
> to be more explicit: 
> is there a way to get the number of items in a GtkList?
> 
...
> 
>  Gtk_Container *container = my_menu;
>  guint num = container.size();
> 

The only way I see to do this is:

GList* list = gtk_container_children(GTK_CONTAINER(gtklist));
guint num = g_list_length(list);
g_list_free(list);
return num;

Which is needless to say not very efficient. If you want to "cheat,"  you
can use GTK_LIST(gtklist)->children instead of calling the function, which
saves a list copy/free but is still O(N) slow. However, technically
speaking I think this struct member is private.

Some of the STL containers (notably list or slist, IIRC) also have O(N)
complexity for the size() method so this should be consistent at least.

Havoc




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