Code

Prevent localized doubles from being written into filter matrices
[inkscape.git] / src / libgdl / gdl-tools.h
1 /*  -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * 
3  * This file is part of the GNOME Devtool Libraries
4  * 
5  * Copyright (C) 1999-2000 Dave Camp <dave@helixcode.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
22 /* Miscellaneous GDL tools/macros */
24 #ifndef __GDL_TOOLS_H__
25 #define __GDL_TOOLS_H__
27 #include <glib.h>
28 #include <gtk/gtkwidget.h>
30 /* FIXME: Toggle this */
32 G_BEGIN_DECLS
34 #define DO_GDL_TRACE
36 #ifdef DO_GDL_TRACE
38 #ifdef __GNUC__
40 #define GDL_TRACE()  G_STMT_START {             \
41     g_log (G_LOG_DOMAIN,                      \
42            G_LOG_LEVEL_DEBUG,                 \
43            "file %s: line %d (%s)",           \
44            __FILE__,                          \
45            __LINE__,                          \
46            __PRETTY_FUNCTION__); } G_STMT_END 
48 #define GDL_TRACE_EXTRA(format, args...) G_STMT_START {     \
49     g_log (G_LOG_DOMAIN,                      \
50            G_LOG_LEVEL_DEBUG,                 \
51            "file %s: line %d (%s): "format,   \
52            __FILE__,                          \
53            __LINE__,                          \
54            __PRETTY_FUNCTION__,               \
55            ##args); } G_STMT_END                   
56     
57 #else /* __GNUC__ */
59 #define GDL_TRACE()  G_STMT_START {             \
60     g_log (G_LOG_DOMAIN,                      \
61            G_LOG_LEVEL_DEBUG,                 \
62            "file %s: line %d",                \
63            __FILE__,                          \
64            __LINE__); } G_STMT_END 
66 #define GDL_TRACE_EXTRA(format, args...) G_STMT_START {     \
67     g_log (G_LOG_DOMAIN,                      \
68            G_LOG_LEVEL_DEBUG,                 \
69            "file %s: line %d: "format,        \
70            __FILE__,                          \
71            __LINE__,                          \
72            ##args); } G_STMT_END                       
73 #endif /* __GNUC__ */
75 #else /* DO_GDL_TRACE */
77 #define GDL_TRACE()
78 #define GDL_TRACE_EXTRA()
80 #endif /* DO_GDL_TRACE */
82 /**
83  * Class boilerplate and base class call macros copied from
84  * bonobo/bonobo-macros.h.  Original copyright follows.
85  *
86  * Author:
87  *   Darin Adler <darin@bentspoon.com>
88  *
89  * Copyright 2001 Ben Tea Spoons, Inc.
90  */
92 /* Macros for defining classes.  Ideas taken from Nautilus and GOB. */
94 /* Define the boilerplate type stuff to reduce typos and code size.  Defines
95  * the get_type method and the parent_class static variable. */
97 #define GDL_BOILERPLATE(type, type_as_function, corba_type,                     \
98                         parent_type, parent_type_macro,                         \
99                         register_type_macro)                                    \
100 static void type_as_function ## _class_init    (type ## Class *klass);          \
101 static void type_as_function ## _instance_init (type          *object);         \
102 static parent_type ## Class *parent_class = NULL;                               \
103 static void                                                                     \
104 type_as_function ## _class_init_trampoline (gpointer klass,                     \
105                                             gpointer data)                      \
106 {                                                                               \
107         parent_class = (parent_type ## Class *)g_type_class_ref (               \
108                 parent_type_macro);                                             \
109         type_as_function ## _class_init ((type ## Class *)klass);               \
110 }                                                                               \
111 GType                                                                           \
112 type_as_function ## _get_type (void)                                            \
113 {                                                                               \
114         static GType object_type = 0;                                           \
115         if (object_type == 0) {                                                 \
116                 static const GTypeInfo object_info = {                          \
117                     sizeof (type ## Class),                                     \
118                     NULL,               /* base_init */                         \
119                     NULL,               /* base_finalize */                     \
120                     type_as_function ## _class_init_trampoline,                 \
121                     NULL,               /* class_finalize */                    \
122                     NULL,               /* class_data */                        \
123                     sizeof (type),                                              \
124                     0,                  /* n_preallocs */                       \
125                     (GInstanceInitFunc) type_as_function ## _instance_init      \
126                 };                                                              \
127                 object_type = register_type_macro                               \
128                         (type, type_as_function, corba_type,                    \
129                          parent_type, parent_type_macro);                       \
130         }                                                                       \
131         return object_type;                                                     \
134 /* Just call the parent handler.  This assumes that there is a variable
135  * named parent_class that points to the (duh!) parent class.  Note that
136  * this macro is not to be used with things that return something, use
137  * the _WITH_DEFAULT version for that */
138 #define GDL_CALL_PARENT(parent_class_cast, name, args)          \
139         ((parent_class_cast(parent_class)->name != NULL) ?      \
140          parent_class_cast(parent_class)->name args : (void)0)
142 #define GDL_CALL_PARENT_GBOOLEAN(parent_class_cast, name, args)          \
143        ((parent_class_cast(parent_class)->name != NULL) ?      \
144         parent_class_cast(parent_class)->name args : (gboolean)0)
147 /* Same as above, but in case there is no implementation, it evaluates
148  * to def_return */
149 #define GDL_CALL_PARENT_WITH_DEFAULT(parent_class_cast,                 \
150                                      name, args, def_return)            \
151         ((parent_class_cast(parent_class)->name != NULL) ?              \
152          parent_class_cast(parent_class)->name args : def_return)
154 /* Define the boilerplate type stuff to reduce typos and code size.  Defines
155  * the get_type method and the parent_class static variable. */
156 #define GDL_CLASS_BOILERPLATE(type, type_as_function,           \
157                                 parent_type, parent_type_macro) \
158         GDL_BOILERPLATE(type, type_as_function, type,           \
159                           parent_type, parent_type_macro,       \
160                           GDL_REGISTER_TYPE)
161 #define GDL_REGISTER_TYPE(type, type_as_function, corba_type,                   \
162                           parent_type, parent_type_macro)                       \
163         g_type_register_static (parent_type_macro, #type, &object_info, 0)
166 #define GDL_CALL_VIRTUAL(object, get_class_cast, method, args) \
167     (get_class_cast (object)->method ? (* get_class_cast (object)->method) args : (void)0)
168 #define GDL_CALL_VIRTUAL_WITH_DEFAULT(object, get_class_cast, method, args, default) \
169     (get_class_cast (object)->method ? (* get_class_cast (object)->method) args : default)
171 /* GdlPixmap structure and method have been copied from Evolution. */
172 typedef struct _GdlPixmap {
173         const char *path;
174         const char *fname;
175         char       *pixbuf;
176 } GdlPixmap;
178 #define GDL_PIXMAP(path,fname)  { (path), (fname), NULL }
179 #define GDL_PIXMAP_END          { NULL, NULL, NULL }
181 G_END_DECLS
183 #endif