Re: Glib / GObject newbie



Laurent JALLET <jallet irit fr> writes:

> Hi all,
>
> I'm developping an application in C and I'd like to use the GObjects
> (and later GTypeModule).
> I'm not using GTK, I just want to "program Object Oriented with C".
>
> I've studied Mathieu Lacage's Gobject sample (maman_bar etc.) and I've
> created some 'simple' classes but I 'd like to implement a Gobject
> containing other Gobjects. And I don't know how to write the
> get/set_property for a Gobject.
> I'm sorry I'm not very clear.
>
> hum...
> that's what I want to implement using GObjects :
> . a Camera containing a position ( => Vector3 : a GObject containing 3
> gfloats) and other members
>
>
> so I've got :
> typedef struct t_Camera Camera;
> typedef struct t_CameraPrivate CameraPrivate;
>
> struct t_Camera {
>   GObject parent;
>   /* instance members */
>   CameraPrivate *priv;
> };
>
> and
> struct t_CameraPrivate
> {
>   gfloat mFov;
>   Vector3 mPosition;
> // and other members ...
> };
>
One note: if you want to use gtk-doc later on, you should probably use
the same "layout" as GTK+/GObject do:

,----
| typedef struct _Camera Camera;
| typedef struct _CameraPrivate CameraPrivate;
| 
| struct _Camera {
|   GObject parent;
|   /* instance members */
|   CameraPrivate *priv;
| };
`----

Also note that with GLib 2.4, you can get rid of the "priv" member and
move CameraPrivate into the .c file (which is just a matter of
preference).

>  How can I transform a GValue into a GObject ?
> And how do I use it ?
>
Look at g_value_{get,set,take}_object(). 

> Of course there's the same problem with the camera_set_property function.
>
> I don't really understand what GValue is and how I can use it.
>
A GValue is kind of a 'tagged value', like you find in dynamically
typed languages (e.g. Python, Scheme). Given a GValue, you can tell at
*runtime* what type it contains. You can essentially treat it like a
small box you can put different things in (integers, objects,
pointers, ...) and get them out again. The box does not only contains
the raw value, but information about the value's type also. Hope that
makes things a bit more clear.

Regards, Rotty
-- 
Andreas Rottmann         | Rotty ICQ      | 118634484 ICQ | a rottmann gmx at
http://yi.org/rotty      | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62
v2sw7MYChw5pr5OFma7u7Lw2m5g/l7Di6e6t5BSb7en6g3/5HZa2Xs6MSr1/2p7 hackerkey.com

Latein ist das humanoide �uivalent zu Fortran.
   -- Alexander Bartolich in at.linux




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