Re: Hoe to create Singleton objects with GObjects ?
- From: Emmanuele Bassi <ebassi gmail com>
- To: gtk-list gnome org
- Subject: Re: Hoe to create Singleton objects with GObjects ?
- Date: Tue, 26 Jun 2007 16:04:05 +0100
hi;
I assume you're referring to the C bindings for GObject.
On Tue, 2007-06-26 at 20:11 +0530, Gautam Ravi wrote:
> I dont know whether this is the right place to ask this question, I
> could not find any other list. Please excuse ;-)
>
> I have two things to ask,
>
> 1. Is it possible to create singleton objects in GObjects ?
yes, there are two methods.
1. you provide a foo_object_new() function and store the pointer
g_object_new() returns inside a static variable, and for any
subsequent call you return that pointer;
2. you override the GObjectClass::constructor() vfunc and you
store the pointer of the new instance there, returning the
same instance.
the second method has the advantage that it works even if you call
g_object_new(FOO_TYPE_OBEJCT, NULL) directly instead of passing through
your own constructor function.
> 2. Is it possible to create a final class ? (i.e A class which cannot
> be derived) in GObjects?
yes. typedef your struct inside the header file, but define it inside
your c source file. if someone tries to subclass that object the
compiler will print an error because the type is incomplete.
--
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]