fixed dealing with collection/lcopy of NULL values.
[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_OBJECT_H__
20 #define __G_OBJECT_H__
21
22 #include        <gobject/gtype.h>
23 #include        <gobject/gvalue.h>
24 #include        <gobject/gparam.h>
25 #include        <gobject/gclosure.h>
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32
33 /* --- type macros --- */
34 #define G_TYPE_IS_OBJECT(type)     (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
35 #define G_OBJECT(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
36 #define G_OBJECT_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
37 #define G_IS_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
38 #define G_IS_OBJECT_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
39 #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
40 #define G_OBJECT_TYPE(object)      (G_TYPE_FROM_INSTANCE (object))
41 #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
42 #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
43 #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
44 #define G_IS_VALUE_OBJECT(value)   (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
45
46
47 /* --- typedefs & structures --- */
48 typedef struct _GObject                  GObject;
49 typedef struct _GObjectClass             GObjectClass;
50 typedef struct _GObjectConstructParam    GObjectConstructParam;
51 typedef void (*GObjectGetPropertyFunc)  (GObject      *object,
52                                          guint         property_id,
53                                          GValue       *value,
54                                          GParamSpec   *pspec,
55                                          const gchar  *trailer);
56 typedef void (*GObjectSetPropertyFunc)  (GObject      *object,
57                                          guint         property_id,
58                                          const GValue *value,
59                                          GParamSpec   *pspec,
60                                          const gchar  *trailer);
61 typedef void (*GObjectFinalizeFunc)     (GObject      *object);
62 struct  _GObject
63 {
64   GTypeInstance g_type_instance;
65   
66   /*< private >*/
67   guint         ref_count;
68   GData        *qdata;
69 };
70 struct  _GObjectClass
71 {
72   GTypeClass   g_type_class;
73
74   /* private, these fields might vanish */
75   guint        n_property_specs;
76   GParamSpec **property_specs;
77
78   /* public overridable methods */
79   GObject*   (*constructor)     (GType                  type,
80                                  guint                  n_construct_properties,
81                                  GObjectConstructParam *construct_params);
82   void       (*get_property)            (GObject        *object,
83                                          guint           property_id,
84                                          GValue         *value,
85                                          GParamSpec     *pspec,
86                                          const gchar    *trailer);
87   void       (*set_property)            (GObject        *object,
88                                          guint           property_id,
89                                          const GValue   *value,
90                                          GParamSpec     *pspec,
91                                          const gchar    *trailer);
92   void       (*shutdown)                (GObject        *object);
93   void       (*finalize)                (GObject        *object);
94
95   /*< private >*/
96   void       (*dispatch_properties_changed) (GObject      *object,
97                                              guint         n_pspecs,
98                                              GParamSpec  **pspecs);
99
100   /* signals */
101   void       (*properties_changed)      (GObject        *object,
102                                          guint           n_pspecs,
103                                          GParamSpec    **pspecs);
104   void       (*notify)                  (GObject        *object,
105                                          GParamSpec     *pspec);
106 };
107 struct _GObjectConstructParam
108 {
109   GParamSpec  *pspec;
110   GValue      *value;
111   const gchar *trailer;
112 };
113
114
115 /* --- prototypes --- */
116 void        g_object_class_install_property   (GObjectClass   *oclass,
117                                                guint           property_id,
118                                                GParamSpec     *pspec);
119 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
120                                                const gchar    *property_name);
121 gpointer    g_object_new                      (GType           object_type,
122                                                const gchar    *first_property_name,
123                                                ...);
124 gpointer    g_object_new_valist               (GType           object_type,
125                                                const gchar    *first_property_name,
126                                                va_list         var_args);
127 void        g_object_set                      (GObject        *object,
128                                                const gchar    *first_property_name,
129                                                ...);
130 void        g_object_get                      (GObject        *object,
131                                                const gchar    *first_property_name,
132                                                ...);
133 void        g_object_set_valist               (GObject        *object,
134                                                const gchar    *first_property_name,
135                                                va_list         var_args);
136 void        g_object_get_valist               (GObject        *object,
137                                                const gchar    *first_property_name,
138                                                va_list         var_args);
139 void        g_object_set_property             (GObject        *object,
140                                                const gchar    *property_name,
141                                                const GValue   *value);
142 void        g_object_get_property             (GObject        *object,
143                                                const gchar    *property_name,
144                                                GValue         *value);
145 void        g_object_freeze_notify            (GObject        *object);
146 void        g_object_notify                   (GObject        *object,
147                                                const gchar    *property_name);
148 void        g_object_thaw_notify              (GObject        *object);
149 GObject*    g_object_ref                      (GObject        *object);
150 void        g_object_unref                    (GObject        *object);
151 gpointer    g_object_get_qdata                (GObject        *object,
152                                                GQuark          quark);
153 void        g_object_set_qdata                (GObject        *object,
154                                                GQuark          quark,
155                                                gpointer        data);
156 void        g_object_set_qdata_full           (GObject        *object,
157                                                GQuark          quark,
158                                                gpointer        data,
159                                                GDestroyNotify  destroy);
160 gpointer    g_object_steal_qdata              (GObject        *object,
161                                                GQuark          quark);
162 gpointer    g_object_get_data                 (GObject        *object,
163                                                const gchar    *key);
164 void        g_object_set_data                 (GObject        *object,
165                                                const gchar    *key,
166                                                gpointer        data);
167 void        g_object_set_data_full            (GObject        *object,
168                                                const gchar    *key,
169                                                gpointer        data,
170                                                GDestroyNotify  destroy);
171 gpointer    g_object_steal_data               (GObject        *object,
172                                                const gchar    *key);
173 void        g_object_watch_closure            (GObject        *object,
174                                                GClosure       *closure);
175 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
176                                                gpointer        object);
177 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
178                                                gpointer        object);
179 GClosure*   g_closure_new_object              (guint           sizeof_closure,
180                                                GObject        *object);
181 void        g_value_set_object                (GValue         *value,
182                                                GObject        *v_object);
183 GObject*    g_value_get_object                (const GValue   *value);
184 GObject*    g_value_dup_object                (const GValue   *value);
185 guint       g_signal_connect_object           (gpointer        instance,
186                                                const gchar    *detailed_signal,
187                                                GCallback       c_handler,
188                                                gpointer        gobject,
189                                                gboolean        swapped,
190                                                gboolean        after);
191
192
193 /* --- implementation macros --- */
194 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
195 G_STMT_START { \
196   GObject *_object = (GObject*) (object); \
197   GParamSpec *_pspec = (GParamSpec*) (pspec); \
198   guint _property_id = (property_id); \
199   g_warning ("%s: invalid property id %u for \"%s\" of type `%s' in `%s'", \
200              G_STRLOC, \
201              _property_id, \
202              _pspec->name, \
203              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
204              G_OBJECT_TYPE_NAME (_object)); \
205 } G_STMT_END
206
207
208
209 #ifdef __cplusplus
210 }
211 #endif /* __cplusplus */
212
213 #endif /* __G_OBJECT_H__ */