Re: Class-Scope Properties



Tim Janik wrote:

ok, if i understand you correctly, you don't mean an object property in
the sense of installing a parameter spec for it/using it through
g_object_set/g_object_get.

No, not an object property though I see no reason why it couldn't be accessed through
g_object_set/g_object_get.  It would just access the same property value for all
instances just like a static class member in C++.

but just have your object (A) aggregate an object of a different type (B),

Yes at the class level; not the object level.

and bundle those throughout lifetime.
the correct way to do this is simply:

A_init (A *a)
{
  a->b = g_object_new (TYPE_B, NULL);   /* b has ref_count==1 after object_new */
}

A_finalize (A *a)
{
  g_object_unref (a->b);
  /* chain parent finalizer */
  [...]
}

Are these the init_class/finalize_class functions or the
init_instance/finalize_instance functions?

finalizers are functions which are called when your object really ends
its lifetime, they have nothing to do with plugins (for instances that
is, _class_ finalizers are plugin type related).

Yes and the property I'm talking about is at the class level, not the instance
level.  It's the same property across all instances of the class.

also note that the above works only for pure GObject, if you want to
bundle a GtkObject/widget to A, you need to sink/ref it after creation.

Just at GLib/GObject level for now.  ;)

Eric.






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