1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/* gnome-macros.h
* Macros for making GObject objects to avoid typos and reduce code size
* Copyright (C) 2000 Eazel, Inc.
*
* Authors: George Lebl <jirka@5z.com>
*
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
@NOTATION@
*/
#ifndef GNOME_MACROS_H
#define GNOME_MACROS_H
/* Macros for defining classes. Ideas taken from Nautilus and GOB. */
/* Define the boilerplate type stuff to reduce typos and code size. Defines
* the get_type method and the parent_class static variable. */
#define GNOME_CLASS_BOILERPLATE(type, type_as_function, \
parent_type, parent_type_as_function, \
parent_type_macro) \
static void type_as_function ## _class_init (type ## Class *klass); \
static void type_as_function ## _instance_init (type *object); \
static parent_type ## Class *parent_class = NULL; \
GType \
type_as_function ## _get_type (void) \
{ \
static GType object_type = 0; \
if (object_type == 0) { \
static const GTypeInfo object_info = { \
sizeof (type ## Class), \
(GBaseInitFunc) NULL, \
(GBaseFinalizeFunc) NULL, \
(GClassInitFunc) type_as_function ## _class_init, \
NULL, /* class_finalize */ \
NULL, /* class_data */ \
sizeof (type), \
0, /* n_preallocs */ \
(GInstanceInitFunc) type_as_function ## _instance_init \
}; \
object_type = g_type_register_static \
(parent_type_macro, #type, &object_info, 0); \
parent_class = g_type_class_ref (parent_type_macro); \
} \
return object_type; \
}
/* Just call the parent handler. This assumes that there is a variable
* named parent_class that points to the (duh!) parent class. Note that
* this macro is not to be used with things that return something, use
* the _WITH_DEFAULT version for that */
#define GNOME_CALL_PARENT_HANDLER(parent_class_cast, name, args) \
((parent_class_cast(parent_class)->name != NULL) ? \
parent_class_cast(parent_class)->name args : (void)0)
/* Same as above, but in case there is no implementation, it evaluates
* to def_return */
#define GNOME_CALL_PARENT_HANDLER_WITH_DEFAULT(parent_class_cast, \
name, args, def_return) \
((parent_class_cast(parent_class)->name != NULL) ? \
parent_class_cast(parent_class)->name args : def_return)
#endif /* GNOME_MACROS_H */
|