~ubuntu-branches/debian/squeeze/glib2.0/squeeze

« back to all changes in this revision

Viewing changes to gobject/gtype.h

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mfrom: (1.3.1 upstream) (69.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20090215130043-q47fbt3owmt42m2f
Tags: 2.18.4-2
* Release to unstable
* debian/rules:
- bump SHVER, since we are already forcing a 2.18.0 dependecy on the
  symbols introduced in the development versions
* debian/control.in:
- added Homepage and Vcs-* control fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
/* Basic Type Macros
31
31
 */
 
32
/**
 
33
 * G_TYPE_FUNDAMENTAL:
 
34
 * @type: A #GType value.
 
35
 * 
 
36
 * The fundamental type which is the ancestor of @type.
 
37
 * Fundamental types are types that serve as ultimate bases for the derived types, 
 
38
 * thus they are the roots of distinct inheritance hierarchies.
 
39
 */
32
40
#define G_TYPE_FUNDAMENTAL(type)        (g_type_fundamental (type))
 
41
/**
 
42
 * G_TYPE_FUNDAMENTAL_MAX:
 
43
 * 
 
44
 * An integer constant that represents the number of identifiers reserved
 
45
 * for types that are assigned at compile-time.
 
46
 */
33
47
#define G_TYPE_FUNDAMENTAL_MAX          (255 << G_TYPE_FUNDAMENTAL_SHIFT)
34
48
 
35
49
/* Constant fundamental types,
36
50
 * introduced by g_type_init().
37
51
 */
 
52
/**
 
53
 * G_TYPE_INVALID:
 
54
 * 
 
55
 * An invalid #GType used as error return value in some functions which return
 
56
 * a #GType. 
 
57
 */
38
58
#define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
 
59
/**
 
60
 * G_TYPE_NONE:
 
61
 * 
 
62
 * A fundamental type which is used as a replacement for the C
 
63
 * <literal>void</literal> return type.
 
64
 */
39
65
#define G_TYPE_NONE                     G_TYPE_MAKE_FUNDAMENTAL (1)
 
66
/**
 
67
 * G_TYPE_INTERFACE:
 
68
 * 
 
69
 * The fundamental type from which all interfaces are derived.
 
70
 */
40
71
#define G_TYPE_INTERFACE                G_TYPE_MAKE_FUNDAMENTAL (2)
 
72
/**
 
73
 * G_TYPE_CHAR:
 
74
 * 
 
75
 * The fundamental type corresponding to #gchar.
 
76
 * The type designated by G_TYPE_CHAR is unconditionally an 8-bit signed integer.
 
77
 * This may or may not be the same type a the C type "gchar".
 
78
 */
41
79
#define G_TYPE_CHAR                     G_TYPE_MAKE_FUNDAMENTAL (3)
 
80
/**
 
81
 * G_TYPE_UCHAR:
 
82
 * 
 
83
 * The fundamental type corresponding to #guchar.
 
84
 */
42
85
#define G_TYPE_UCHAR                    G_TYPE_MAKE_FUNDAMENTAL (4)
 
86
/**
 
87
 * G_TYPE_BOOLEAN:
 
88
 * 
 
89
 * The fundamental type corresponding to #gboolean.
 
90
 */
43
91
#define G_TYPE_BOOLEAN                  G_TYPE_MAKE_FUNDAMENTAL (5)
 
92
/**
 
93
 * G_TYPE_INT:
 
94
 * 
 
95
 * The fundamental type corresponding to #gint.
 
96
 */
44
97
#define G_TYPE_INT                      G_TYPE_MAKE_FUNDAMENTAL (6)
 
98
/**
 
99
 * G_TYPE_UINT:
 
100
 * 
 
101
 * The fundamental type corresponding to #guint.
 
102
 */
45
103
#define G_TYPE_UINT                     G_TYPE_MAKE_FUNDAMENTAL (7)
 
104
/**
 
105
 * G_TYPE_LONG:
 
106
 * 
 
107
 * The fundamental type corresponding to #glong.
 
108
 */
46
109
#define G_TYPE_LONG                     G_TYPE_MAKE_FUNDAMENTAL (8)
 
110
/**
 
111
 * G_TYPE_ULONG:
 
112
 * 
 
113
 * The fundamental type corresponding to #gulong.
 
114
 */
47
115
#define G_TYPE_ULONG                    G_TYPE_MAKE_FUNDAMENTAL (9)
 
116
/**
 
117
 * G_TYPE_INT64:
 
118
 * 
 
119
 * The fundamental type corresponding to #gint64.
 
120
 */
48
121
#define G_TYPE_INT64                    G_TYPE_MAKE_FUNDAMENTAL (10)
 
122
/**
 
123
 * G_TYPE_UINT64:
 
124
 * 
 
125
 * The fundamental type corresponding to #guint64.
 
126
 */
49
127
#define G_TYPE_UINT64                   G_TYPE_MAKE_FUNDAMENTAL (11)
 
128
/**
 
129
 * G_TYPE_ENUM:
 
130
 * 
 
131
 * The fundamental type from which all enumeration types are derived.
 
132
 */
50
133
#define G_TYPE_ENUM                     G_TYPE_MAKE_FUNDAMENTAL (12)
 
134
/**
 
135
 * G_TYPE_FLAGS:
 
136
 * 
 
137
 * The fundamental type from which all flags types are derived.
 
138
 */
51
139
#define G_TYPE_FLAGS                    G_TYPE_MAKE_FUNDAMENTAL (13)
 
140
/**
 
141
 * G_TYPE_FLOAT:
 
142
 * 
 
143
 * The fundamental type corresponding to #gfloat.
 
144
 */
52
145
#define G_TYPE_FLOAT                    G_TYPE_MAKE_FUNDAMENTAL (14)
 
146
/**
 
147
 * G_TYPE_DOUBLE:
 
148
 * 
 
149
 * The fundamental type corresponding to #gdouble.
 
150
 */
53
151
#define G_TYPE_DOUBLE                   G_TYPE_MAKE_FUNDAMENTAL (15)
 
152
/**
 
153
 * G_TYPE_STRING:
 
154
 * 
 
155
 * The fundamental type corresponding to nul-terminated C strings.
 
156
 */
54
157
#define G_TYPE_STRING                   G_TYPE_MAKE_FUNDAMENTAL (16)
 
158
/**
 
159
 * G_TYPE_POINTER:
 
160
 * 
 
161
 * The fundamental type corresponding to #gpointer.
 
162
 */
55
163
#define G_TYPE_POINTER                  G_TYPE_MAKE_FUNDAMENTAL (17)
 
164
/**
 
165
 * G_TYPE_BOXED:
 
166
 * 
 
167
 * The fundamental type from which all boxed types are derived.
 
168
 */
56
169
#define G_TYPE_BOXED                    G_TYPE_MAKE_FUNDAMENTAL (18)
 
170
/**
 
171
 * G_TYPE_PARAM:
 
172
 * 
 
173
 * The fundamental type from which all #GParamSpec types are derived.
 
174
 */
57
175
#define G_TYPE_PARAM                    G_TYPE_MAKE_FUNDAMENTAL (19)
 
176
/**
 
177
 * G_TYPE_OBJECT:
 
178
 * 
 
179
 * The fundamental type for #GObject.
 
180
 */
58
181
#define G_TYPE_OBJECT                   G_TYPE_MAKE_FUNDAMENTAL (20)
59
182
 
60
183
 
61
184
/* Reserved fundamental type numbers to create new fundamental
62
185
 * type IDs with G_TYPE_MAKE_FUNDAMENTAL().
63
 
 * Send email to gtk-devel-list@redhat.com for reservations.
 
186
 * Send email to gtk-devel-list@gnome.org for reservations.
 
187
 */
 
188
/**
 
189
 * G_TYPE_FUNDAMENTAL_SHIFT:
 
190
 *
 
191
 * Shift value used in converting numbers to type IDs.
64
192
 */
65
193
#define G_TYPE_FUNDAMENTAL_SHIFT        (2)
 
194
/**
 
195
 * G_TYPE_MAKE_FUNDAMENTAL:
 
196
 * @x: the fundamental type number.
 
197
 * 
 
198
 * Get the type ID for the fundamental type number @x.
 
199
 * Use g_type_fundamental_next() instead of this macro to create new fundamental 
 
200
 * types.
 
201
 *
 
202
 * Returns: the GType
 
203
 */
66
204
#define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
 
205
/**
 
206
 * G_TYPE_RESERVED_GLIB_FIRST:
 
207
 * 
 
208
 * First fundamental type number to create a new fundamental type id with
 
209
 * G_TYPE_MAKE_FUNDAMENTAL() reserved for GLib.
 
210
 */
67
211
#define G_TYPE_RESERVED_GLIB_FIRST      (21)
 
212
/**
 
213
 * G_TYPE_RESERVED_GLIB_LAST:
 
214
 * 
 
215
 * Last fundamental type number reserved for GLib.
 
216
 */
68
217
#define G_TYPE_RESERVED_GLIB_LAST       (31)
 
218
/**
 
219
 * G_TYPE_RESERVED_BSE_FIRST:
 
220
 * 
 
221
 * First fundamental type number to create a new fundamental type id with
 
222
 * G_TYPE_MAKE_FUNDAMENTAL() reserved for BSE.
 
223
 */
69
224
#define G_TYPE_RESERVED_BSE_FIRST       (32)
 
225
/**
 
226
 * G_TYPE_RESERVED_BSE_LAST:
 
227
 * 
 
228
 * Last fundamental type number reserved for BSE.
 
229
 */
70
230
#define G_TYPE_RESERVED_BSE_LAST        (48)
 
231
/**
 
232
 * G_TYPE_RESERVED_USER_FIRST:
 
233
 * 
 
234
 * First available fundamental type number to create new fundamental 
 
235
 * type id with G_TYPE_MAKE_FUNDAMENTAL().
 
236
 */
71
237
#define G_TYPE_RESERVED_USER_FIRST      (49)
72
238
 
73
239
 
74
240
/* Type Checking Macros
75
241
 */
 
242
/**
 
243
 * G_TYPE_IS_FUNDAMENTAL:
 
244
 * @type: A #GType value.
 
245
 * 
 
246
 * Checks if @type is a fundamental type.
 
247
 *
 
248
 * Returns: %TRUE on success.
 
249
 */
76
250
#define G_TYPE_IS_FUNDAMENTAL(type)             ((type) <= G_TYPE_FUNDAMENTAL_MAX)
 
251
/**
 
252
 * G_TYPE_IS_DERIVED:
 
253
 * @type: A #GType value.
 
254
 * 
 
255
 * Checks if @type is derived (or in object-oriented terminology:
 
256
 * inherited) from another type (this holds true for all non-fundamental
 
257
 * types).
 
258
 *
 
259
 * Returns: %TRUE on success.
 
260
 */
77
261
#define G_TYPE_IS_DERIVED(type)                 ((type) > G_TYPE_FUNDAMENTAL_MAX)
 
262
/**
 
263
 * G_TYPE_IS_INTERFACE:
 
264
 * @type: A #GType value.
 
265
 * 
 
266
 * Checks if @type is an interface type.
 
267
 * An interface type provides a pure API, the implementation
 
268
 * of which is provided by another type (which is then said to conform
 
269
 * to the interface).  GLib interfaces are somewhat analogous to Java
 
270
 * interfaces and C++ classes containing only pure virtual functions, 
 
271
 * with the difference that GType interfaces are not derivable (but see
 
272
 * g_type_interface_add_prerequisite() for an alternative).
 
273
 *
 
274
 * Returns: %TRUE on success.
 
275
 */
78
276
#define G_TYPE_IS_INTERFACE(type)               (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
 
277
/**
 
278
 * G_TYPE_IS_CLASSED:
 
279
 * @type: A #GType value.
 
280
 * 
 
281
 * Checks if @type is a classed type.
 
282
 *
 
283
 * Returns: %TRUE on success.
 
284
 */
79
285
#define G_TYPE_IS_CLASSED(type)                 (g_type_test_flags ((type), G_TYPE_FLAG_CLASSED))
 
286
/**
 
287
 * G_TYPE_IS_INSTANTIATABLE:
 
288
 * @type: A #GType value.
 
289
 * 
 
290
 * Checks if @type can be instantiated.  Instantiation is the
 
291
 * process of creating an instance (object) of this type.
 
292
 *
 
293
 * Returns: %TRUE on success.
 
294
 */
80
295
#define G_TYPE_IS_INSTANTIATABLE(type)          (g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
 
296
/**
 
297
 * G_TYPE_IS_DERIVABLE:
 
298
 * @type: A #GType value.
 
299
 * 
 
300
 * Checks if @type is a derivable type.  A derivable type can
 
301
 * be used as the base class of a flat (single-level) class hierarchy.
 
302
 *
 
303
 * Returns: %TRUE on success.
 
304
 */
81
305
#define G_TYPE_IS_DERIVABLE(type)               (g_type_test_flags ((type), G_TYPE_FLAG_DERIVABLE))
 
306
/**
 
307
 * G_TYPE_IS_DEEP_DERIVABLE:
 
308
 * @type: A #GType value.
 
309
 * 
 
310
 * Checks if @type is a deep derivable type.  A deep derivable type
 
311
 * can be used as the base class of a deep (multi-level) class hierarchy.
 
312
 *
 
313
 * Returns: %TRUE on success.
 
314
 */
82
315
#define G_TYPE_IS_DEEP_DERIVABLE(type)          (g_type_test_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
 
316
/**
 
317
 * G_TYPE_IS_ABSTRACT:
 
318
 * @type: A #GType value.
 
319
 * 
 
320
 * Checks if @type is an abstract type.  An abstract type can not be
 
321
 * instantiated and is normally used as an abstract base class for
 
322
 * derived classes.
 
323
 *
 
324
 * Returns: %TRUE on success.
 
325
 */
83
326
#define G_TYPE_IS_ABSTRACT(type)                (g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))
 
327
/**
 
328
 * G_TYPE_IS_VALUE_ABSTRACT:
 
329
 * @type: A #GType value.
 
330
 * 
 
331
 * Checks if @type is an abstract value type.  An abstract value type introduces
 
332
 * a value table, but can't be used for g_value_init() and is normally used as
 
333
 * an abstract base type for derived value types.
 
334
 *
 
335
 * Returns: %TRUE on success.
 
336
 */
84
337
#define G_TYPE_IS_VALUE_ABSTRACT(type)          (g_type_test_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
 
338
/**
 
339
 * G_TYPE_IS_VALUE_TYPE:
 
340
 * @type: A #GType value.
 
341
 * 
 
342
 * Checks if @type is a value type and can be used with g_value_init(). 
 
343
 *
 
344
 * Returns: %TRUE on success.
 
345
 */
85
346
#define G_TYPE_IS_VALUE_TYPE(type)              (g_type_check_is_value_type (type))
 
347
/**
 
348
 * G_TYPE_HAS_VALUE_TABLE:
 
349
 * @type: A #GType value.
 
350
 * 
 
351
 * Checks if @type has a #GTypeValueTable.
 
352
 *
 
353
 * Returns: %TRUE on success.
 
354
 */
86
355
#define G_TYPE_HAS_VALUE_TABLE(type)            (g_type_value_table_peek (type) != NULL)
87
356
 
88
357
 
89
358
/* Typedefs
90
359
 */
 
360
/**
 
361
 * GType:
 
362
 * 
 
363
 * A numerical value which represents the unique identifier of a registered
 
364
 * type.
 
365
 */
91
366
#if     GLIB_SIZEOF_SIZE_T != GLIB_SIZEOF_LONG || !defined __cplusplus
92
367
typedef gsize                           GType;
93
368
#else   /* for historic reasons, C++ links against gulong GTypes */
108
383
 
109
384
/* Basic Type Structures
110
385
 */
 
386
/**
 
387
 * GTypeClass:
 
388
 * 
 
389
 * An opaque structure used as the base of all classes.
 
390
 */
111
391
struct _GTypeClass
112
392
{
113
393
  /*< private >*/
114
394
  GType g_type;
115
395
};
 
396
/**
 
397
 * GTypeInstance:
 
398
 * 
 
399
 * An opaque structure used as the base of all type instances.
 
400
 */
116
401
struct _GTypeInstance
117
402
{
118
403
  /*< private >*/
119
404
  GTypeClass *g_class;
120
405
};
 
406
/**
 
407
 * GTypeInterface:
 
408
 * 
 
409
 * An opaque structure used as the base of all interface types.
 
410
 */
121
411
struct _GTypeInterface
122
412
{
123
413
  /*< private >*/
124
414
  GType g_type;         /* iface type */
125
415
  GType g_instance_type;
126
416
};
 
417
/**
 
418
 * GTypeQuery:
 
419
 * @type: the #GType value of the type.
 
420
 * @type_name: the name of the type.
 
421
 * @class_size: the size of the class structure.
 
422
 * @instance_size: the size of the instance structure.
 
423
 * 
 
424
 * A structure holding information for a specific type. It is
 
425
 * filled in by the g_type_query() function.
 
426
 */
127
427
struct _GTypeQuery
128
428
{
129
429
  GType         type;
137
437
 * usage of these macros is reserved to type implementations only
138
438
 */
139
439
/*< protected >*/
 
440
/**
 
441
 * G_TYPE_CHECK_INSTANCE:
 
442
 * @instance: Location of a #GTypeInstance structure.
 
443
 * 
 
444
 * Checks if @instance is a valid #GTypeInstance structure,
 
445
 * otherwise issues a warning and returns %FALSE.
 
446
 * 
 
447
 * This macro should only be used in type implementations.
 
448
 *
 
449
 * Returns: %TRUE on success.
 
450
 */
140
451
#define G_TYPE_CHECK_INSTANCE(instance)                         (_G_TYPE_CHI ((GTypeInstance*) (instance)))
 
452
/**
 
453
 * G_TYPE_CHECK_INSTANCE_CAST:
 
454
 * @instance: Location of a #GTypeInstance structure.
 
455
 * @g_type: The type to be returned.
 
456
 * @c_type: The corresponding C type of @g_type.
 
457
 * 
 
458
 * Checks that @instance is an instance of the type identified by @g_type
 
459
 * and issues a warning if this is not the case. Returns @instance casted 
 
460
 * to a pointer to @c_type.
 
461
 * 
 
462
 * This macro should only be used in type implementations.
 
463
 */
141
464
#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
 
465
/**
 
466
 * G_TYPE_CHECK_INSTANCE_TYPE:
 
467
 * @instance: Location of a #GTypeInstance structure.
 
468
 * @g_type: The type to be checked
 
469
 * 
 
470
 * Checks if @instance is an instance of the type identified by @g_type.
 
471
 * 
 
472
 * This macro should only be used in type implementations.
 
473
 *
 
474
 * Returns: %TRUE on success.
 
475
 */
142
476
#define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type)            (_G_TYPE_CIT ((instance), (g_type)))
 
477
/**
 
478
 * G_TYPE_INSTANCE_GET_CLASS:
 
479
 * @instance: Location of the #GTypeInstance structure.
 
480
 * @g_type: The #GType of the class to be returned.
 
481
 * @c_type: The C type of the class structure.
 
482
 * 
 
483
 * Get the class structure of a given @instance, casted
 
484
 * to a specified ancestor type @g_type of the instance.
 
485
 * 
 
486
 * Note that while calling a GInstanceInitFunc(), the class pointer gets
 
487
 * modified, so it might not always return the expected pointer.
 
488
 * 
 
489
 * This macro should only be used in type implementations.
 
490
 *
 
491
 * Returns: a pointer to the class structure
 
492
 */
143
493
#define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type)     (_G_TYPE_IGC ((instance), (g_type), c_type))
 
494
/**
 
495
 * G_TYPE_INSTANCE_GET_INTERFACE:
 
496
 * @instance: Location of the #GTypeInstance structure.
 
497
 * @g_type: The #GType of the interface to be returned.
 
498
 * @c_type: The C type of the interface structure.
 
499
 * 
 
500
 * Get the interface structure for interface @g_type of a given @instance.
 
501
 * 
 
502
 * This macro should only be used in type implementations.
 
503
 *
 
504
 * Returns: a pointer to the interface structure
 
505
 */
144
506
#define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
 
507
/**
 
508
 * G_TYPE_CHECK_CLASS_CAST:
 
509
 * @g_class: Location of a #GTypeClass structure.
 
510
 * @g_type: The type to be returned.
 
511
 * @c_type: The corresponding C type of class structure of @g_type.
 
512
 * 
 
513
 * Checks that @g_class is a class structure of the type identified by @g_type
 
514
 * and issues a warning if this is not the case. Returns @g_class casted 
 
515
 * to a pointer to @c_type.
 
516
 * 
 
517
 * This macro should only be used in type implementations.
 
518
 */
145
519
#define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type)        (_G_TYPE_CCC ((g_class), (g_type), c_type))
 
520
/**
 
521
 * G_TYPE_CHECK_CLASS_TYPE:
 
522
 * @g_class: Location of a #GTypeClass structure.
 
523
 * @g_type: The type to be checked.
 
524
 * 
 
525
 * Checks if @g_class is a class structure of the type identified by 
 
526
 * @g_type.
 
527
 * 
 
528
 * This macro should only be used in type implementations.
 
529
 *
 
530
 * Returns: %TRUE on success.
 
531
 */
146
532
#define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type)                (_G_TYPE_CCT ((g_class), (g_type)))
 
533
/**
 
534
 * G_TYPE_CHECK_VALUE:
 
535
 * @value: a #GValue
 
536
 * 
 
537
 * Checks if @value has been initialized to hold values
 
538
 * of a value type.
 
539
 * 
 
540
 * This macro should only be used in type implementations.
 
541
 *
 
542
 * Returns: %TRUE on success.
 
543
 */
147
544
#define G_TYPE_CHECK_VALUE(value)                               (_G_TYPE_CHV ((value)))
 
545
/**
 
546
 * G_TYPE_CHECK_VALUE_TYPE:
 
547
 * @value: a #GValue
 
548
 * @g_type: The type to be checked.
 
549
 * 
 
550
 * Checks if @value has been initialized to hold values
 
551
 * of type @g_type. 
 
552
 * 
 
553
 * This macro should only be used in type implementations.
 
554
 *
 
555
 * Returns: %TRUE on success.
 
556
 */
148
557
#define G_TYPE_CHECK_VALUE_TYPE(value, g_type)                  (_G_TYPE_CVH ((value), (g_type)))
 
558
/**
 
559
 * G_TYPE_FROM_INSTANCE:
 
560
 * @instance: Location of a valid #GTypeInstance structure.
 
561
 * 
 
562
 * Get the type identifier from a given @instance structure. 
 
563
 * 
 
564
 * This macro should only be used in type implementations.
 
565
 *
 
566
 * Returns: the #GType
 
567
 */
149
568
#define G_TYPE_FROM_INSTANCE(instance)                          (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
 
569
/**
 
570
 * G_TYPE_FROM_CLASS:
 
571
 * @g_class: Location of a valid #GTypeClass structure.
 
572
 * 
 
573
 * Get the type identifier from a given @class structure.
 
574
 * 
 
575
 * This macro should only be used in type implementations.
 
576
 *
 
577
 * Returns: the #GType
 
578
 */
150
579
#define G_TYPE_FROM_CLASS(g_class)                              (((GTypeClass*) (g_class))->g_type)
 
580
/**
 
581
 * G_TYPE_FROM_INTERFACE:
 
582
 * @g_iface: Location of a valid #GTypeInterface structure.
 
583
 * 
 
584
 * Get the type identifier from a given @interface structure.
 
585
 * 
 
586
 * This macro should only be used in type implementations.
 
587
 *
 
588
 * Returns: the #GType
 
589
 */
151
590
#define G_TYPE_FROM_INTERFACE(g_iface)                          (((GTypeInterface*) (g_iface))->g_type)
152
591
 
 
592
/**
 
593
 * G_TYPE_INSTANCE_GET_PRIVATE:
 
594
 * @instance: the instance of a type deriving from @private_type.
 
595
 * @g_type: the type identifying which private data to retrieve.
 
596
 * @c_type: The C type for the private structure.
 
597
 * 
 
598
 * Gets the private structure for a particular type.
 
599
 * The private structure must have been registered in the
 
600
 * class_init function with g_type_class_add_private().
 
601
 * 
 
602
 * This macro should only be used in type implementations.
 
603
 * 
 
604
 * Since: 2.4
 
605
 * Returns: a pointer to the private data structure.
 
606
 */
153
607
#define G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type)   ((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type)))
154
608
 
155
609
 
156
 
/* debug flags for g_type_init_with_debug_flags() */
 
610
/**
 
611
 * GTypeDebugFlags:
 
612
 * @G_TYPE_DEBUG_NONE: Print no messages.
 
613
 * @G_TYPE_DEBUG_OBJECTS: Print messages about object bookkeeping.
 
614
 * @G_TYPE_DEBUG_SIGNALS: Print messages about signal emissions.
 
615
 * @G_TYPE_DEBUG_MASK: Mask covering all debug flags.
 
616
 * 
 
617
 * The <type>GTypeDebugFlags</type> enumeration values can be passed to
 
618
 * g_type_init_with_debug_flags() to trigger debugging messages during runtime.
 
619
 * Note that the messages can also be triggered by setting the
 
620
 * <envar>GOBJECT_DEBUG</envar> environment variable to a ':'-separated list of 
 
621
 * "objects" and "signals".
 
622
 */
157
623
typedef enum    /*< skip >*/
158
624
{
159
625
  G_TYPE_DEBUG_NONE     = 0,
205
671
 
206
672
 
207
673
/* --- type registration --- */
 
674
/**
 
675
 * GBaseInitFunc:
 
676
 * @g_class: The #GTypeClass structure to initialize.
 
677
 * 
 
678
 * A callback function used by the type system to do base initialization
 
679
 * of the class structures of derived types. It is called as part of the
 
680
 * initialization process of all derived classes and should reallocate
 
681
 * or reset all dynamic class members copied over from the parent class.
 
682
 * For example, class members (such as strings) that are not sufficiently
 
683
 * handled by a plain memory copy of the parent class into the derived class
 
684
 * have to be altered. See GClassInitFunc() for a discussion of the class
 
685
 * intialization process.
 
686
 */
208
687
typedef void   (*GBaseInitFunc)              (gpointer         g_class);
 
688
/**
 
689
 * GBaseFinalizeFunc:
 
690
 * @g_class: The #GTypeClass structure to finalize.
 
691
 * 
 
692
 * A callback function used by the type system to finalize those portions
 
693
 * of a derived types class structure that were setup from the corresponding
 
694
 * GBaseInitFunc() function. Class finalization basically works the inverse
 
695
 * way in which class intialization is performed.
 
696
 * See GClassInitFunc() for a discussion of the class intialization process.
 
697
 */
209
698
typedef void   (*GBaseFinalizeFunc)          (gpointer         g_class);
 
699
/**
 
700
 * GClassInitFunc:
 
701
 * @g_class: The #GTypeClass structure to initialize.
 
702
 * @class_data: The @class_data member supplied via the #GTypeInfo structure.
 
703
 * 
 
704
 * A callback function used by the type system to initialize the class
 
705
 * of a specific type. This function should initialize all static class
 
706
 * members.
 
707
 * The initialization process of a class involves:
 
708
 * <itemizedlist>
 
709
 * <listitem><para>
 
710
 *      1 - Copying common members from the parent class over to the
 
711
 *      derived class structure.
 
712
 * </para></listitem>
 
713
 * <listitem><para>
 
714
 *      2 -  Zero initialization of the remaining members not copied
 
715
 *      over from the parent class.
 
716
 * </para></listitem>
 
717
 * <listitem><para>
 
718
 *      3 - Invocation of the GBaseInitFunc() initializers of all parent
 
719
 *      types and the class' type.
 
720
 * </para></listitem>
 
721
 * <listitem><para>
 
722
 *      4 - Invocation of the class' GClassInitFunc() initializer.
 
723
 * </para></listitem>
 
724
 * </itemizedlist>
 
725
 * Since derived classes are partially initialized through a memory copy
 
726
 * of the parent class, the general rule is that GBaseInitFunc() and
 
727
 * GBaseFinalizeFunc() should take care of necessary reinitialization
 
728
 * and release of those class members that were introduced by the type
 
729
 * that specified these GBaseInitFunc()/GBaseFinalizeFunc().
 
730
 * GClassInitFunc() should only care about initializing static
 
731
 * class members, while dynamic class members (such as allocated strings
 
732
 * or reference counted resources) are better handled by a GBaseInitFunc()
 
733
 * for this type, so proper initialization of the dynamic class members
 
734
 * is performed for class initialization of derived types as well.
 
735
 * An example may help to correspond the intend of the different class
 
736
 * initializers:
 
737
 * 
 
738
 * |[
 
739
 * typedef struct {
 
740
 *   GObjectClass parent_class;
 
741
 *   gint         static_integer;
 
742
 *   gchar       *dynamic_string;
 
743
 * } TypeAClass;
 
744
 * static void
 
745
 * type_a_base_class_init (TypeAClass *class)
 
746
 * {
 
747
 *   class->dynamic_string = g_strdup ("some string");
 
748
 * }
 
749
 * static void
 
750
 * type_a_base_class_finalize (TypeAClass *class)
 
751
 * {
 
752
 *   g_free (class->dynamic_string);
 
753
 * }
 
754
 * static void
 
755
 * type_a_class_init (TypeAClass *class)
 
756
 * {
 
757
 *   class->static_integer = 42;
 
758
 * }
 
759
 * 
 
760
 * typedef struct {
 
761
 *   TypeAClass   parent_class;
 
762
 *   gfloat       static_float;
 
763
 *   GString     *dynamic_gstring;
 
764
 * } TypeBClass;
 
765
 * static void
 
766
 * type_b_base_class_init (TypeBClass *class)
 
767
 * {
 
768
 *   class->dynamic_gstring = g_string_new ("some other string");
 
769
 * }
 
770
 * static void
 
771
 * type_b_base_class_finalize (TypeBClass *class)
 
772
 * {
 
773
 *   g_string_free (class->dynamic_gstring);
 
774
 * }
 
775
 * static void
 
776
 * type_b_class_init (TypeBClass *class)
 
777
 * {
 
778
 *   class->static_float = 3.14159265358979323846;
 
779
 * }
 
780
 * ]|
 
781
 * Initialization of TypeBClass will first cause initialization of
 
782
 * TypeAClass (derived classes reference their parent classes, see
 
783
 * g_type_class_ref() on this).
 
784
 * Initialization of TypeAClass roughly involves zero-initializing its fields,
 
785
 * then calling its GBaseInitFunc() type_a_base_class_init() to allocate
 
786
 * its dynamic members (dynamic_string), and finally calling its GClassInitFunc()
 
787
 * type_a_class_init() to initialize its static members (static_integer).
 
788
 * The first step in the initialization process of TypeBClass is then
 
789
 * a plain memory copy of the contents of TypeAClass into TypeBClass and 
 
790
 * zero-initialization of the remaining fields in TypeBClass.
 
791
 * The dynamic members of TypeAClass within TypeBClass now need
 
792
 * reinitialization which is performed by calling type_a_base_class_init()
 
793
 * with an argument of TypeBClass.
 
794
 * After that, the GBaseInitFunc() of TypeBClass, type_b_base_class_init()
 
795
 * is called to allocate the dynamic members of TypeBClass (dynamic_gstring),
 
796
 * and finally the GClassInitFunc() of TypeBClass, type_b_class_init(),
 
797
 * is called to complete the initialization process with the static members
 
798
 * (static_float).
 
799
 * Corresponding finalization counter parts to the GBaseInitFunc() functions
 
800
 * have to be provided to release allocated resources at class finalization
 
801
 * time.
 
802
 */
210
803
typedef void   (*GClassInitFunc)             (gpointer         g_class,
211
804
                                              gpointer         class_data);
 
805
/**
 
806
 * GClassFinalizeFunc:
 
807
 * @g_class: The #GTypeClass structure to finalize.
 
808
 * @class_data: The @class_data member supplied via the #GTypeInfo structure.
 
809
 * 
 
810
 * A callback function used by the type system to finalize a class.
 
811
 * This function is rarely needed, as dynamically allocated class resources
 
812
 * should be handled by GBaseInitFunc() and GBaseFinalizeFunc().
 
813
 * Also, specification of a GClassFinalizeFunc() in the #GTypeInfo
 
814
 * structure of a static type is invalid, because classes of static types
 
815
 * will never be finalized (they are artificially kept alive when their
 
816
 * reference count drops to zero).
 
817
 */
212
818
typedef void   (*GClassFinalizeFunc)         (gpointer         g_class,
213
819
                                              gpointer         class_data);
 
820
/**
 
821
 * GInstanceInitFunc:
 
822
 * @instance: The instance to initialize.
 
823
 * @g_class: The class of the type the instance is created for.
 
824
 * 
 
825
 * A callback function used by the type system to initialize a new
 
826
 * instance of a type. This function initializes all instance members and
 
827
 * allocates any resources required by it.
 
828
 * Initialization of a derived instance involves calling all its parent
 
829
 * types instance initializers, so the class member of the instance
 
830
 * is altered during its initialization to always point to the class that
 
831
 * belongs to the type the current initializer was introduced for.
 
832
 */
214
833
typedef void   (*GInstanceInitFunc)          (GTypeInstance   *instance,
215
834
                                              gpointer         g_class);
 
835
/**
 
836
 * GInterfaceInitFunc:
 
837
 * @g_iface: The interface structure to initialize.
 
838
 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure.
 
839
 * 
 
840
 * A callback function used by the type system to initialize a new
 
841
 * interface.  This function should initialize all internal data and
 
842
 * allocate any resources required by the interface.
 
843
 */
216
844
typedef void   (*GInterfaceInitFunc)         (gpointer         g_iface,
217
845
                                              gpointer         iface_data);
 
846
/**
 
847
 * GInterfaceFinalizeFunc:
 
848
 * @g_iface: The interface structure to finalize.
 
849
 * @iface_data: The @interface_data supplied via the #GInterfaceInfo structure.
 
850
 * 
 
851
 * A callback function used by the type system to finalize an interface.
 
852
 * This function should destroy any internal data and release any resources
 
853
 * allocated by the corresponding GInterfaceInitFunc() function.
 
854
 */
218
855
typedef void   (*GInterfaceFinalizeFunc)     (gpointer         g_iface,
219
856
                                              gpointer         iface_data);
 
857
/**
 
858
 * GTypeClassCacheFunc:
 
859
 * @cache_data: data that was given to the g_type_add_class_cache_func() call
 
860
 * @g_class: The #GTypeClass structure which is unreferenced
 
861
 * 
 
862
 * A callback function which is called when the reference count of a class 
 
863
 * drops to zero. It may use g_type_class_ref() to prevent the class from
 
864
 * being freed. You should not call g_type_class_unref() from a 
 
865
 * #GTypeClassCacheFunc function to prevent infinite recursion, use 
 
866
 * g_type_class_unref_uncached() instead.
 
867
 * 
 
868
 * The functions have to check the class id passed in to figure 
 
869
 * whether they actually want to cache the class of this type, since all
 
870
 * classes are routed through the same #GTypeClassCacheFunc chain.
 
871
 * 
 
872
 * Returns: %TRUE to stop further #GTypeClassCacheFunc<!-- -->s from being 
 
873
 *  called, %FALSE to continue.
 
874
 */
220
875
typedef gboolean (*GTypeClassCacheFunc)      (gpointer         cache_data,
221
876
                                              GTypeClass      *g_class);
 
877
/**
 
878
 * GTypeInterfaceCheckFunc:
 
879
 * @check_data: data passed to g_type_add_interface_check().
 
880
 * @g_iface: the interface that has been initialized
 
881
 * 
 
882
 * A callback called after an interface vtable is initialized.
 
883
 * See g_type_add_interface_check().
 
884
 * 
 
885
 * Since: 2.4
 
886
 */
222
887
typedef void     (*GTypeInterfaceCheckFunc)  (gpointer         check_data,
223
888
                                              gpointer         g_iface);
 
889
/**
 
890
 * GTypeFundamentalFlags:
 
891
 * @G_TYPE_FLAG_CLASSED: Indicates a classed type.
 
892
 * @G_TYPE_FLAG_INSTANTIATABLE: Indicates an instantiable type (implies classed).
 
893
 * @G_TYPE_FLAG_DERIVABLE: Indicates a flat derivable type.
 
894
 * @G_TYPE_FLAG_DEEP_DERIVABLE: Indicates a deep derivable type (implies derivable).
 
895
 * 
 
896
 * Bit masks used to check or determine specific characteristics of a
 
897
 * fundamental type.
 
898
 */
224
899
typedef enum    /*< skip >*/
225
900
{
226
901
  G_TYPE_FLAG_CLASSED           = (1 << 0),
228
903
  G_TYPE_FLAG_DERIVABLE         = (1 << 2),
229
904
  G_TYPE_FLAG_DEEP_DERIVABLE    = (1 << 3)
230
905
} GTypeFundamentalFlags;
 
906
/**
 
907
 * GTypeFlags:
 
908
 * @G_TYPE_FLAG_ABSTRACT: Indicates an abstract type. No instances can be
 
909
 *  created for an abstract type.
 
910
 * @G_TYPE_FLAG_VALUE_ABSTRACT: Indicates an abstract value type, i.e. a type
 
911
 *  that introduces a value table, but can't be used for
 
912
 *  g_value_init().
 
913
 * 
 
914
 * Bit masks used to check or determine characteristics of a type.
 
915
 */
231
916
typedef enum    /*< skip >*/
232
917
{
233
918
  G_TYPE_FLAG_ABSTRACT          = (1 << 4),
234
919
  G_TYPE_FLAG_VALUE_ABSTRACT    = (1 << 5)
235
920
} GTypeFlags;
 
921
/**
 
922
 * GTypeInfo:
 
923
 * @class_size: Size of the class structure (required for interface, classed and instantiatable types).
 
924
 * @base_init: Location of the base initialization function (optional).
 
925
 * @base_finalize: Location of the base finalization function (optional).
 
926
 * @class_init: Location of the class initialization function for
 
927
 *  classed and instantiatable types. Location of the default vtable 
 
928
 *  inititalization function for interface types. (optional) This function 
 
929
 *  is used both to fill in virtual functions in the class or default vtable, 
 
930
 *  and to do type-specific setup such as registering signals and object
 
931
 *  properties.
 
932
 * @class_finalize: Location of the class finalization function for
 
933
 *  classed and instantiatable types. Location fo the default vtable 
 
934
 *  finalization function for interface types. (optional)
 
935
 * @class_data: User-supplied data passed to the class init/finalize functions.
 
936
 * @instance_size: Size of the instance (object) structure (required for instantiatable types only).
 
937
 * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the <link linkend="glib-Memory-Slices">slice allocator</link> now.
 
938
 * @instance_init: Location of the instance initialization function (optional, for instantiatable types only).
 
939
 * @value_table: A #GTypeValueTable function table for generic handling of GValues of this type (usually only
 
940
 *  useful for fundamental types).
 
941
 * 
 
942
 * This structure is used to provide the type system with the information
 
943
 * required to initialize and destruct (finalize) a type's class and
 
944
 * its instances.
 
945
 * The initialized structure is passed to the g_type_register_static() function
 
946
 * (or is copied into the provided #GTypeInfo structure in the
 
947
 * g_type_plugin_complete_type_info()). The type system will perform a deep
 
948
 * copy of this structure, so its memory does not need to be persistent
 
949
 * across invocation of g_type_register_static().
 
950
 */
236
951
struct _GTypeInfo
237
952
{
238
953
  /* interface types, classed types, instantiated types */
254
969
  /* value handling */
255
970
  const GTypeValueTable *value_table;
256
971
};
 
972
/**
 
973
 * GTypeFundamentalInfo:
 
974
 * @type_flags: #GTypeFundamentalFlags describing the characteristics of the fundamental type
 
975
 * 
 
976
 * A structure that provides information to the type system which is
 
977
 * used specifically for managing fundamental types.  
 
978
 */
257
979
struct _GTypeFundamentalInfo
258
980
{
259
981
  GTypeFundamentalFlags  type_flags;
260
982
};
 
983
/**
 
984
 * GInterfaceInfo:
 
985
 * @interface_init: location of the interface initialization function
 
986
 * @interface_finalize: location of the interface finalization function
 
987
 * @interface_data: user-supplied data passed to the interface init/finalize functions
 
988
 * 
 
989
 * A structure that provides information to the type system which is
 
990
 * used specifically for managing interface types.
 
991
 */
261
992
struct _GInterfaceInfo
262
993
{
263
994
  GInterfaceInitFunc     interface_init;
264
995
  GInterfaceFinalizeFunc interface_finalize;
265
996
  gpointer               interface_data;
266
997
};
 
998
/**
 
999
 * GTypeValueTable:
 
1000
 * @value_init: Default initialize @values contents by poking values
 
1001
 *  directly into the value->data array. The data array of
 
1002
 *  the #GValue passed into this function was zero-filled
 
1003
 *  with <function>memset()</function>, so no care has to
 
1004
 *  be taken to free any
 
1005
 *  old contents. E.g. for the implementation of a string
 
1006
 *  value that may never be %NULL, the implementation might
 
1007
 *  look like:
 
1008
 *  |[
 
1009
 *  value->data[0].v_pointer = g_strdup ("");
 
1010
 *  ]|
 
1011
 * @value_free: Free any old contents that might be left in the
 
1012
 *  data array of the passed in @value. No resources may
 
1013
 *  remain allocated through the #GValue contents after
 
1014
 *  this function returns. E.g. for our above string type:
 
1015
 *  |[
 
1016
 *  // only free strings without a specific flag for static storage
 
1017
 *  if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
 
1018
 *    g_free (value->data[0].v_pointer);
 
1019
 *  ]|
 
1020
 * @value_copy: @dest_value is a #GValue with zero-filled data section
 
1021
 *  and @src_value is a properly setup #GValue of same or
 
1022
 *  derived type.
 
1023
 *  The purpose of this function is to copy the contents of
 
1024
 *  @src_value into @dest_value in a way, that even after
 
1025
 *  @src_value has been freed, the contents of @dest_value
 
1026
 *  remain valid. String type example:
 
1027
 *  |[
 
1028
 *  dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
 
1029
 *  ]|
 
1030
 * @value_peek_pointer: If the value contents fit into a pointer, such as objects
 
1031
 *  or strings, return this pointer, so the caller can peek at
 
1032
 *  the current contents. To extend on our above string example:
 
1033
 *  |[
 
1034
 *  return value->data[0].v_pointer;
 
1035
 *  ]|
 
1036
 * @collect_format: A string format describing how to collect the contents of
 
1037
 *  this value bit-by-bit. Each character in the format represents
 
1038
 *  an argument to be collected, and the characters themselves indicate
 
1039
 *  the type of the argument. Currently supported arguments are:
 
1040
 *  <variablelist>
 
1041
 *  <varlistentry><term /><listitem><para>
 
1042
 *  'i' - Integers. passed as collect_values[].v_int.
 
1043
 *  </para></listitem></varlistentry>
 
1044
 *  <varlistentry><term /><listitem><para>
 
1045
 *  'l' - Longs. passed as collect_values[].v_long.
 
1046
 *  </para></listitem></varlistentry>
 
1047
 *  <varlistentry><term /><listitem><para>
 
1048
 *  'd' - Doubles. passed as collect_values[].v_double.
 
1049
 *  </para></listitem></varlistentry>
 
1050
 *  <varlistentry><term /><listitem><para>
 
1051
 *  'p' - Pointers. passed as collect_values[].v_pointer.
 
1052
 *  </para></listitem></varlistentry>
 
1053
 *  </variablelist>
 
1054
 *  It should be noted that for variable argument list construction,
 
1055
 *  ANSI C promotes every type smaller than an integer to an int, and
 
1056
 *  floats to doubles. So for collection of short int or char, 'i'
 
1057
 *  needs to be used, and for collection of floats 'd'.
 
1058
 * @collect_value: The collect_value() function is responsible for converting the
 
1059
 *  values collected from a variable argument list into contents
 
1060
 *  suitable for storage in a GValue. This function should setup
 
1061
 *  @value similar to value_init(); e.g. for a string value that
 
1062
 *  does not allow %NULL pointers, it needs to either spew an error,
 
1063
 *  or do an implicit conversion by storing an empty string.
 
1064
 *  The @value passed in to this function has a zero-filled data
 
1065
 *  array, so just like for value_init() it is guaranteed to not
 
1066
 *  contain any old contents that might need freeing.
 
1067
 *  @n_collect_values is exactly the string length of @collect_format,
 
1068
 *  and @collect_values is an array of unions #GTypeCValue with
 
1069
 *  length @n_collect_values, containing the collected values
 
1070
 *  according to @collect_format.
 
1071
 *  @collect_flags is an argument provided as a hint by the caller.
 
1072
 *  It may contain the flag %G_VALUE_NOCOPY_CONTENTS indicating,
 
1073
 *  that the collected value contents may be considered "static"
 
1074
 *  for the duration of the @value lifetime.
 
1075
 *  Thus an extra copy of the contents stored in @collect_values is
 
1076
 *  not required for assignment to @value.
 
1077
 *  For our above string example, we continue with:
 
1078
 *  |[
 
1079
 *  if (!collect_values[0].v_pointer)
 
1080
 *    value->data[0].v_pointer = g_strdup ("");
 
1081
 *  else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
 
1082
 *  {
 
1083
 *    value->data[0].v_pointer = collect_values[0].v_pointer;
 
1084
 *    // keep a flag for the value_free() implementation to not free this string
 
1085
 *    value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
 
1086
 *  }
 
1087
 *  else
 
1088
 *    value->data[0].v_pointer = g_strdup (collect_values[0].v_pointer);
 
1089
 *  return NULL;
 
1090
 *  ]|
 
1091
 *  It should be noted, that it is generally a bad idea to follow the
 
1092
 *  #G_VALUE_NOCOPY_CONTENTS hint for reference counted types. Due to
 
1093
 *  reentrancy requirements and reference count assertions performed
 
1094
 *  by the #GSignal code, reference counts should always be incremented
 
1095
 *  for reference counted contents stored in the value->data array.
 
1096
 *  To deviate from our string example for a moment, and taking a look
 
1097
 *  at an exemplary implementation for collect_value() of #GObject:
 
1098
 *  |[
 
1099
 *  if (collect_values[0].v_pointer)
 
1100
 *  {
 
1101
 *    GObject *object = G_OBJECT (collect_values[0].v_pointer);
 
1102
 *    // never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types
 
1103
 *    value->data[0].v_pointer = g_object_ref (object);
 
1104
 *    return NULL;
 
1105
 *  }
 
1106
 *  else
 
1107
 *    return g_strdup_printf ("Object passed as invalid NULL pointer");
 
1108
 *  }
 
1109
 *  ]|
 
1110
 *  The reference count for valid objects is always incremented,
 
1111
 *  regardless of @collect_flags. For invalid objects, the example
 
1112
 *  returns a newly allocated string without altering @value.
 
1113
 *  Upon success, collect_value() needs to return %NULL. If, however,
 
1114
 *  an error condition occurred, collect_value() may spew an
 
1115
 *  error by returning a newly allocated non-%NULL string, giving
 
1116
 *  a suitable description of the error condition.
 
1117
 *  The calling code makes no assumptions about the @value
 
1118
 *  contents being valid upon error returns, @value
 
1119
 *  is simply thrown away without further freeing. As such, it is
 
1120
 *  a good idea to not allocate #GValue contents, prior to returning
 
1121
 *  an error, however, collect_values() is not obliged to return
 
1122
 *  a correctly setup @value for error returns, simply because
 
1123
 *  any non-%NULL return is considered a fatal condition so further
 
1124
 *  program behaviour is undefined.
 
1125
 * @lcopy_format: Format description of the arguments to collect for @lcopy_value,
 
1126
 *  analogous to @collect_format. Usually, @lcopy_format string consists
 
1127
 *  only of 'p's to provide lcopy_value() with pointers to storage locations.
 
1128
 * @lcopy_value: This function is responsible for storing the @value contents into
 
1129
 *  arguments passed through a variable argument list which got
 
1130
 *  collected into @collect_values according to @lcopy_format.
 
1131
 *  @n_collect_values equals the string length of @lcopy_format,
 
1132
 *  and @collect_flags may contain %G_VALUE_NOCOPY_CONTENTS.
 
1133
 *  In contrast to collect_value(), lcopy_value() is obliged to
 
1134
 *  always properly support %G_VALUE_NOCOPY_CONTENTS.
 
1135
 *  Similar to collect_value() the function may prematurely abort
 
1136
 *  by returning a newly allocated string describing an error condition.
 
1137
 *  To complete the string example:
 
1138
 *  |[
 
1139
 *  gchar **string_p = collect_values[0].v_pointer;
 
1140
 *  if (!string_p)
 
1141
 *    return g_strdup_printf ("string location passed as NULL");
 
1142
 *  if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
 
1143
 *    *string_p = value->data[0].v_pointer;
 
1144
 *  else
 
1145
 *    *string_p = g_strdup (value->data[0].v_pointer);
 
1146
 *  ]|
 
1147
 *  And an illustrative version of lcopy_value() for
 
1148
 *  reference-counted types:
 
1149
 *  |[
 
1150
 *  GObject **object_p = collect_values[0].v_pointer;
 
1151
 *  if (!object_p)
 
1152
 *    return g_strdup_printf ("object location passed as NULL");
 
1153
 *  if (!value->data[0].v_pointer)
 
1154
 *    *object_p = NULL;
 
1155
 *  else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) // always honour
 
1156
 *    *object_p = value->data[0].v_pointer;
 
1157
 *  else
 
1158
 *    *object_p = g_object_ref (value->data[0].v_pointer);
 
1159
 *  return NULL;
 
1160
 *  ]|
 
1161
 * 
 
1162
 * The #GTypeValueTable provides the functions required by the #GValue implementation,
 
1163
 * to serve as a container for values of a type.
 
1164
 */
 
1165
 
267
1166
struct _GTypeValueTable
268
1167
{
269
1168
  void     (*value_init)         (GValue       *value);
321
1220
 
322
1221
 
323
1222
/* --- GType boilerplate --- */
324
 
/* convenience macros for type implementations, which for a type GtkGadget will:
325
 
 * - prototype: static void     gtk_gadget_class_init (GtkGadgetClass *klass);
326
 
 * - prototype: static void     gtk_gadget_init       (GtkGadget      *self);
327
 
 * - define:    static gpointer gtk_gadget_parent_class = NULL;
328
 
 *   gtk_gadget_parent_class is initialized prior to calling gtk_gadget_class_init()
329
 
 * - implement: GType           gtk_gadget_get_type (void) { ... }
330
 
 * - support custom code in gtk_gadget_get_type() after the type is registered.
331
 
 *
332
 
 * macro arguments: TypeName, type_name, TYPE_PARENT, CODE
333
 
 * example: G_DEFINE_TYPE_WITH_CODE (GtkGadget, gtk_gadget, GTK_TYPE_WIDGET,
334
 
 *                                   g_print ("GtkGadget-id: %lu\n", g_define_type_id));
 
1223
/**
 
1224
 * G_DEFINE_TYPE:
 
1225
 * @TN: The name of the new type, in Camel case.
 
1226
 * @t_n: The name of the new type, in lowercase, with words 
 
1227
 *  separated by '_'.
 
1228
 * @T_P: The #GType of the parent type.
 
1229
 * 
 
1230
 * A convenience macro for type implementations, which declares a 
 
1231
 * class initialization function, an instance initialization function (see #GTypeInfo for information about 
 
1232
 * these) and a static variable named @t_n<!-- -->_parent_class pointing to the parent class. Furthermore, it defines 
 
1233
 * a *_get_type() function. See G_DEFINE_TYPE_EXTENDED() for an example.
 
1234
 * 
 
1235
 * Since: 2.4
335
1236
 */
336
1237
#define G_DEFINE_TYPE(TN, t_n, T_P)                         G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
 
1238
/**
 
1239
 * G_DEFINE_TYPE_WITH_CODE:
 
1240
 * @TN: The name of the new type, in Camel case.
 
1241
 * @t_n: The name of the new type in lowercase, with words separated by '_'.
 
1242
 * @T_P: The #GType of the parent type.
 
1243
 * @_C_: Custom code that gets inserted in the *_get_type() function.
 
1244
 * 
 
1245
 * A convenience macro for type implementations.  
 
1246
 * Similar to G_DEFINE_TYPE(), but allows to insert custom code into the 
 
1247
 * *_get_type() function, e.g. interface implementations via G_IMPLEMENT_INTERFACE().
 
1248
 * See G_DEFINE_TYPE_EXTENDED() for an example.
 
1249
 * 
 
1250
 * Since: 2.4
 
1251
 */
337
1252
#define G_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_)          _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
 
1253
/**
 
1254
 * G_DEFINE_ABSTRACT_TYPE:
 
1255
 * @TN: The name of the new type, in Camel case.
 
1256
 * @t_n: The name of the new type, in lowercase, with words 
 
1257
 *  separated by '_'.
 
1258
 * @T_P: The #GType of the parent type.
 
1259
 * 
 
1260
 * A convenience macro for type implementations. 
 
1261
 * Similar to G_DEFINE_TYPE(), but defines an abstract type. 
 
1262
 * See G_DEFINE_TYPE_EXTENDED() for an example.
 
1263
 * 
 
1264
 * Since: 2.4
 
1265
 */
338
1266
#define G_DEFINE_ABSTRACT_TYPE(TN, t_n, T_P)                G_DEFINE_TYPE_EXTENDED (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT, {})
 
1267
/**
 
1268
 * G_DEFINE_ABSTRACT_TYPE_WITH_CODE:
 
1269
 * @TN: The name of the new type, in Camel case.
 
1270
 * @t_n: The name of the new type, in lowercase, with words 
 
1271
 *  separated by '_'.
 
1272
 * @T_P: The #GType of the parent type.
 
1273
 * @_C_: Custom code that gets inserted in the @type_name_get_type() function.
 
1274
 * 
 
1275
 * A convenience macro for type implementations.
 
1276
 * Similar to G_DEFINE_TYPE_WITH_CODE(), but defines an abstract type and allows to 
 
1277
 * insert custom code into the *_get_type() function, e.g. interface implementations 
 
1278
 * via G_IMPLEMENT_INTERFACE(). See G_DEFINE_TYPE_EXTENDED() for an example.
 
1279
 * 
 
1280
 * Since: 2.4
 
1281
 */
339
1282
#define G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, G_TYPE_FLAG_ABSTRACT) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
 
1283
/**
 
1284
 * G_DEFINE_TYPE_EXTENDED:
 
1285
 * @TN: The name of the new type, in Camel case.
 
1286
 * @t_n: The name of the new type, in lowercase, with words 
 
1287
 *  separated by '_'.
 
1288
 * @T_P: The #GType of the parent type.
 
1289
 * @_f_: #GTypeFlags to pass to g_type_register_static()
 
1290
 * @_C_: Custom code that gets inserted in the *_get_type() function.
 
1291
 * 
 
1292
 * The most general convenience macro for type implementations, on which 
 
1293
 * G_DEFINE_TYPE(), etc are based. 
 
1294
 * 
 
1295
 * |[
 
1296
 * G_DEFINE_TYPE_EXTENDED (GtkGadget, 
 
1297
 *                         gtk_gadget, 
 
1298
 *                         GTK_TYPE_WIDGET,
 
1299
 *                         0, 
 
1300
 *                         G_IMPLEMENT_INTERFACE (TYPE_GIZMO, 
 
1301
 *                                                gtk_gadget_gizmo_init));
 
1302
 * ]|
 
1303
 * expands to
 
1304
 * |[
 
1305
 * static void     gtk_gadget_init       (GtkGadget      *self);
 
1306
 * static void     gtk_gadget_class_init (GtkGadgetClass *klass);
 
1307
 * static gpointer gtk_gadget_parent_class = NULL;
 
1308
 * static void     gtk_gadget_class_intern_init (gpointer klass)
 
1309
 * {
 
1310
 *   gtk_gadget_parent_class = g_type_class_peek_parent (klass);
 
1311
 *   gtk_gadget_class_init ((GtkGadgetClass*) klass);
 
1312
 * }
 
1313
 * 
 
1314
 * GType
 
1315
 * gtk_gadget_get_type (void)
 
1316
 * {
 
1317
 *   static GType g_define_type_id = 0; 
 
1318
 *   if (G_UNLIKELY (g_define_type_id == 0)) 
 
1319
 *     { 
 
1320
 *       static const GTypeInfo g_define_type_info = { 
 
1321
 *         sizeof (GtkGadgetClass), 
 
1322
 *         (GBaseInitFunc) NULL, 
 
1323
 *         (GBaseFinalizeFunc) NULL, 
 
1324
 *         (GClassInitFunc) gtk_gadget_class_intern_init, 
 
1325
 *         (GClassFinalizeFunc) NULL, 
 
1326
 *         NULL,   // class_data 
 
1327
 *         sizeof (GtkGadget), 
 
1328
 *         0,      // n_preallocs 
 
1329
 *         (GInstanceInitFunc) gtk_gadget_init, 
 
1330
 *       }; 
 
1331
 *       g_define_type_id = g_type_register_static (GTK_TYPE_WIDGET, "GtkGadget", &g_define_type_info, 0); 
 
1332
 *       {
 
1333
 *         static const GInterfaceInfo g_implement_interface_info = {
 
1334
 *           (GInterfaceInitFunc) gtk_gadget_gizmo_init
 
1335
 *         };
 
1336
 *         g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
 
1337
 *       } 
 
1338
 *     } 
 
1339
 *   return g_define_type_id; 
 
1340
 * }
 
1341
 * ]|
 
1342
 * The only pieces which have to be manually provided are the definitions of the 
 
1343
 * instance and class structure and the definitions of the instance and class 
 
1344
 * init functions.
 
1345
 * 
 
1346
 * Since: 2.4
 
1347
 */
340
1348
#define G_DEFINE_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)      _G_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, _f_) {_C_;} _G_DEFINE_TYPE_EXTENDED_END()
341
1349
 
342
 
/* convenience macro to ease interface addition in the CODE
343
 
 * section of G_DEFINE_TYPE_WITH_CODE() (this macro relies on
344
 
 * the g_define_type_id present within G_DEFINE_TYPE_WITH_CODE()).
345
 
 * usage example:
346
 
 * G_DEFINE_TYPE_WITH_CODE (GtkTreeStore, gtk_tree_store, G_TYPE_OBJECT,
347
 
 *                          G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
348
 
 *                                                 gtk_tree_store_tree_model_init));
 
1350
/**
 
1351
 * G_IMPLEMENT_INTERFACE:
 
1352
 * @TYPE_IFACE: The #GType of the interface to add
 
1353
 * @iface_init: The interface init function
 
1354
 * 
 
1355
 * A convenience macro to ease interface addition in the @_C_ section
 
1356
 * of G_DEFINE_TYPE_WITH_CODE() or G_DEFINE_ABSTRACT_TYPE_WITH_CODE(). 
 
1357
 * See G_DEFINE_TYPE_EXTENDED() for an example.
 
1358
 * 
 
1359
 * Note that this macro can only be used together with the G_DEFINE_TYPE_*
 
1360
 * macros, since it depends on variable names from those macros.
 
1361
 * 
 
1362
 * Since: 2.4
349
1363
 */
350
1364
#define G_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init)       { \
351
1365
  const GInterfaceInfo g_implement_interface_info = { \
491
1505
#  define _G_TYPE_CCT(cp, gt)             (g_type_check_class_is_a ((GTypeClass*) cp, gt))
492
1506
#  define _G_TYPE_CVH(vl, gt)             (g_type_check_value_holds ((GValue*) vl, gt))
493
1507
#endif /* !__GNUC__ */
 
1508
/**
 
1509
 * G_TYPE_FLAG_RESERVED_ID_BIT:
 
1510
 * 
 
1511
 * A bit in the type number that's supposed to be left untouched.
 
1512
 */
494
1513
#define G_TYPE_FLAG_RESERVED_ID_BIT     ((GType) (1 << 0))
495
1514
extern GTypeDebugFlags                  _g_type_debug_flags;
496
1515