define gstring in terms of gchar*. this typedef reflects the type name of
[platform/upstream/glib.git] / gobject / gobject.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifndef __G_GOBJECT_H__
20 #define __G_GOBJECT_H__
21
22 #include        <gobject/gtype.h>
23 #include        <gobject/gvalue.h>
24 #include        <gobject/gparam.h>
25
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30
31
32 /* --- type macros --- */
33 #define G_TYPE_IS_OBJECT(type)     (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
34 #define G_OBJECT(object)           (G_IS_OBJECT (object) ? ((GObject*) (object)) : \
35                                     G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
36 #define G_OBJECT_CLASS(class)      (G_IS_OBJECT_CLASS (class) ? ((GObjectClass*) (class)) : \
37                                     G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
38 #define G_IS_OBJECT(object)        (((GObject*) (object)) != NULL && \
39                                     G_IS_OBJECT_CLASS (((GTypeInstance*) (object))->g_class))
40 #define G_IS_OBJECT_CLASS(class)   (((GTypeClass*) (class)) != NULL && \
41                                     G_TYPE_IS_OBJECT (((GTypeClass*) (class))->g_type))
42 #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
43 #define G_OBJECT_TYPE(object)      (G_TYPE_FROM_INSTANCE (object))
44 #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
45 #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
46 #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
47 #define G_IS_VALUE_OBJECT(value)   (G_TYPE_CHECK_CLASS_TYPE ((value), G_TYPE_OBJECT))
48
49 #define G_NOTIFY_PRIORITY          (G_PRIORITY_HIGH_IDLE + 20)
50
51
52 /* --- typedefs & structures --- */
53 typedef struct _GObject      GObject;
54 typedef struct _GObjectClass GObjectClass;
55 typedef void (*GObjectGetParamFunc)     (GObject     *object,
56                                          guint        param_id,
57                                          GValue      *value,
58                                          GParamSpec  *pspec,
59                                          const gchar *trailer);
60 typedef void (*GObjectSetParamFunc)     (GObject     *object,
61                                          guint        param_id,
62                                          GValue      *value,
63                                          GParamSpec  *pspec,
64                                          const gchar *trailer);
65 typedef void (*GObjectFinalizeFunc)     (GObject     *object);
66 struct  _GObject
67 {
68   GTypeInstance g_type_instance;
69   
70   /*< private >*/
71   guint         ref_count;
72   GData        *qdata;
73 };
74 struct  _GObjectClass
75 {
76   GTypeClass   g_type_class;
77
78   guint        n_param_specs;
79   GParamSpec **param_specs;
80   
81   void       (*get_param)               (GObject        *object,
82                                          guint           param_id,
83                                          GValue         *value,
84                                          GParamSpec     *pspec,
85                                          const gchar    *trailer);
86   void       (*set_param)               (GObject        *object,
87                                          guint           param_id,
88                                          GValue         *value,
89                                          GParamSpec     *pspec,
90                                          const gchar    *trailer);
91   void       (*queue_param_changed)     (GObject        *object,
92                                          GParamSpec     *pspec);
93   void       (*dispatch_param_changed)  (GObject        *object,
94                                          GParamSpec     *pspec);
95   void       (*shutdown)                (GObject        *object);
96   void       (*finalize)                (GObject        *object);
97 };
98
99
100 /* --- prototypes --- */
101 void        g_object_class_install_param   (GObjectClass   *oclass,
102                                             guint           param_id,
103                                             GParamSpec     *pspec /* +1 ref */);
104 GParamSpec* g_object_class_find_param_spec (GObjectClass   *oclass,
105                                             const gchar    *param_name);
106 gpointer    g_object_new                   (GType           object_type,
107                                             const gchar    *first_param_name,
108                                             ...);
109 gpointer    g_object_new_valist            (GType           object_type,
110                                             const gchar    *first_param_name,
111                                             va_list         var_args);
112 void        g_object_set                   (GObject        *object,
113                                             const gchar    *first_param_name,
114                                             ...);
115 void        g_object_get                   (GObject        *object,
116                                             const gchar    *first_param_name,
117                                             ...);
118 void        g_object_set_valist            (GObject        *object,
119                                             const gchar    *first_param_name,
120                                             va_list         var_args);
121 void        g_object_get_valist            (GObject        *object,
122                                             const gchar    *first_param_name,
123                                             va_list         var_args);
124 void        g_object_set_param             (GObject        *object,
125                                             const gchar    *param_name,
126                                             const GValue   *value);
127 void        g_object_get_param             (GObject        *object,
128                                             const gchar    *param_name,
129                                             GValue         *value);
130 void        g_object_queue_param_changed   (GObject        *object,
131                                             const gchar    *param_name);
132 GObject*    g_object_ref                   (GObject        *object);
133 void        g_object_unref                 (GObject        *object);
134 gpointer    g_object_get_qdata             (GObject        *object,
135                                             GQuark          quark);
136 void        g_object_set_qdata             (GObject        *object,
137                                             GQuark          quark,
138                                             gpointer        data);
139 void        g_object_set_qdata_full        (GObject        *object,
140                                             GQuark          quark,
141                                             gpointer        data,
142                                             GDestroyNotify  destroy);
143 gpointer    g_object_steal_qdata           (GObject        *object,
144                                             GQuark          quark);
145 void        g_value_set_object             (GValue         *value,
146                                             GObject        *v_object);
147 GObject*    g_value_get_object             (GValue         *value);
148 GObject*    g_value_dup_object             (GValue         *value);
149
150
151 /* --- implementation macros --- */
152 #define G_WARN_INVALID_PARAM_ID(object, param_id, pspec) \
153 G_STMT_START { \
154   GObject *_object = (GObject*) (object); \
155   GParamSpec *_pspec = (GParamSpec*) (pspec); \
156   guint _param_id = (param_id); \
157   g_warning ("%s: invalid parameter id %u for \"%s\" of type `%s' in `%s'", \
158              G_STRLOC, \
159              _param_id, \
160              _pspec->name, \
161              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
162              BSE_OBJECT_TYPE_NAME (_object)); \
163 } G_STMT_END
164
165
166
167 #ifdef __cplusplus
168 }
169 #endif /* __cplusplus */
170
171 #endif /* __G_GOBJECT_H__ */