Updated Spanish translation
[anjuta-git-plugin.git] / libegg / util / egg-macros.h
blobfa70c2914dbe9bdd091dfdd2c40b8c570a347572
1 /**
2 * Useful macros.
4 * Author:
5 * Darin Adler <darin@bentspoon.com>
7 * Copyright 2001 Ben Tea Spoons, Inc.
8 */
9 #ifndef _EGG_MACROS_H_
10 #define _EGG_MACROS_H_
12 #include <glib/gmacros.h>
14 G_BEGIN_DECLS
16 /* Macros for defining classes. Ideas taken from Nautilus and GOB. */
18 /* Define the boilerplate type stuff to reduce typos and code size. Defines
19 * the get_type method and the parent_class static variable. */
21 #define EGG_BOILERPLATE(type, type_as_function, corba_type, \
22 parent_type, parent_type_macro, \
23 register_type_macro) \
24 static void type_as_function ## _class_init (type ## Class *klass); \
25 static void type_as_function ## _instance_init (type *object); \
26 static parent_type ## Class *parent_class = NULL; \
27 static void \
28 type_as_function ## _class_init_trampoline (gpointer klass, \
29 gpointer data) \
30 { \
31 parent_class = (parent_type ## Class *)g_type_class_ref ( \
32 parent_type_macro); \
33 type_as_function ## _class_init ((type ## Class *)klass); \
34 } \
35 GType \
36 type_as_function ## _get_type (void) \
37 { \
38 static GType object_type = 0; \
39 if (object_type == 0) { \
40 static const GTypeInfo object_info = { \
41 sizeof (type ## Class), \
42 NULL, /* base_init */ \
43 NULL, /* base_finalize */ \
44 type_as_function ## _class_init_trampoline, \
45 NULL, /* class_finalize */ \
46 NULL, /* class_data */ \
47 sizeof (type), \
48 0, /* n_preallocs */ \
49 (GInstanceInitFunc) type_as_function ## _instance_init \
50 }; \
51 object_type = register_type_macro \
52 (type, type_as_function, corba_type, \
53 parent_type, parent_type_macro); \
54 } \
55 return object_type; \
58 /* Just call the parent handler. This assumes that there is a variable
59 * named parent_class that points to the (duh!) parent class. Note that
60 * this macro is not to be used with things that return something, use
61 * the _WITH_DEFAULT version for that */
62 #define EGG_CALL_PARENT(parent_class_cast, name, args) \
63 ((parent_class_cast(parent_class)->name != NULL) ? \
64 parent_class_cast(parent_class)->name args : (void)0)
66 /* Same as above, but in case there is no implementation, it evaluates
67 * to def_return */
68 #define EGG_CALL_PARENT_WITH_DEFAULT(parent_class_cast, \
69 name, args, def_return) \
70 ((parent_class_cast(parent_class)->name != NULL) ? \
71 parent_class_cast(parent_class)->name args : def_return)
73 /* Call a virtual method */
74 #define EGG_CALL_VIRTUAL(object, get_class_cast, method, args) \
75 (get_class_cast (object)->method ? (* get_class_cast (object)->method) args : (void)0)
77 /* Call a virtual method with default */
78 #define EGG_CALL_VIRTUAL_WITH_DEFAULT(object, get_class_cast, method, args, default) \
79 (get_class_cast (object)->method ? (* get_class_cast (object)->method) args : default)
81 #define EGG_CLASS_BOILERPLATE(type, type_as_function, \
82 parent_type, parent_type_macro) \
83 EGG_BOILERPLATE(type, type_as_function, type, \
84 parent_type, parent_type_macro, \
85 EGG_REGISTER_TYPE)
87 #define EGG_REGISTER_TYPE(type, type_as_function, corba_type, \
88 parent_type, parent_type_macro) \
89 g_type_register_static (parent_type_macro, #type, &object_info, 0)
92 G_END_DECLS
94 #endif /* _EGG_MACROS_H_ */