Re: Accessing a class pointer and class methods
- From: Gaal Yahas <gaal forum2 org>
- To: gtk-app-devel-list gnome org
- Subject: Re: Accessing a class pointer and class methods
- Date: Sun, 13 Jul 2003 09:15:43 +0300
Sorry to reply to myself, but I figured out how to do this.
On Sat, Jul 12, 2003 at 10:25:36AM +0300, I wrote:
How do I call a class method on some GObject-based type?
How do I even *implement* such a method?
I suppose a fair enough answer to the first question, if this is a type
I'm developing, is to export the method as a function.
The answer to the second question should have been obvious, too :)
Class data are just file-level static variables in the file where the
class is implemented; no need to fetch the class struct from anywhere
or any fancy hackery.
What I still want to know is what is the proper way to implement instance
finalization when the object is a GObject and not a GtkObject (GtkObjects
have a "destroy" signal I can conncet to). See the example below: how
do I have unique_thing_finalize called, say, when the thing's refcount
drops to zero?
uniqething.c:
static GHashTable *thing_cache;
void
unique_thing_class_init() {
thing_cache = g_hash_table_new(g_str_hash, g_str_equal);
}
void
unique_thing_class_finalize() {
g_hash_table_destroy(thing_cache);
}
GObject*
unique_thing_new(gchar *id) {
UniqueThing* ut = g_hash_table_lookup(thing_cache, id);
if (ut)
return(ut);
ut = UNIQUE_THING(g_object_new(unique_thing_get_type(), 0));
ut->id = g_strdup(id);
g_hash_table_insert(thing_cache, g_strdup(id), ut);
return ut;
}
void
unique_thing_finalize(UniqueThing *ut) {
g_hash_table_remove(thing_cache, ut->id);
}
Thanks,
Gaal
--
Gaal Yahas <gaal forum2 org>
http://gaal.livejournal.com/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]