Re: Quick Question: How can I get the GTypeInfo from a GType?



On Thu, 2004-01-08 at 12:33, Ryan McDougall wrote:

As I read through the source codes lots of good and bad ideas pop into
my head. Right now I am thinking about implementing an Iterator object
for use in a STL style container system. I think the APIs for GList,
GArray, GTree, etc can be simplified and enriched by using some ideas
from STL's design. Of course C has no easy way to fake C++'s Generic
programming, but there may be yet some stuff that will transfer over.

Aside: How efficient is GValue for faking Generic Programming?

This is almost certainly not what you want to do.  Glib tries to make C
programming as high-level as possible, but not any more than that.

Glib comes with some simple iterators.  g_list_foreach() is syntactic
sugar and really more inconvenient than

  GList *l;
  for (l = my_list; l; l = l->next)
     do_something_with (l->data);

g_list_foreach() is only useful if you intend to g_list_remove_link()
the node that was fed to the callback --- it implements the usual
while() idiom that allows for this.

About the only useful iterators in glib are g_hash_table_foreach() and
g_node_traverse().  The former, because hash tables are opaque; the
latter, because it implements different traversal methods.

Arrays are so simple to manipulate by hand that you may as well do that,
with no loss of efficiency.

If you really want something like list iterators that can change the
list, look for things like EList in the "gal" package, which Evolution
uses.

In general, don't try to make C too high-level; Greenspun's tenth law of
programming certainly applies.

  Federico




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