GnuCash  4.12-68-g5dc52459a1+
gnc-gobject-utils.h
Go to the documentation of this file.
1 /*
2  * gnc-gobject-utils.h -- utility functions for working
3  * with GObjects
4  * Copyright (C) 2005 David Hampton <hampton@employees.org>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, contact:
18  *
19  * Free Software Foundation Voice: +1-617-542-5942
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21  * Boston, MA 02110-1301, USA gnu@gnu.org
22  */
23 
38 #ifndef GNC_GOBJECT_UTILS_H
39 #define GNC_GOBJECT_UTILS_H
40 
41 #include <glib.h>
42 #include <glib-object.h>
43 
82 void gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass);
83 
88 void gnc_gobject_tracking_forget (GObject *object);
89 
99 const GList *gnc_gobject_tracking_get_list (const gchar *name);
100 
101 
108 void gnc_gobject_tracking_dump (void);
109 
120 #define GNC_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
121  const GInterfaceInfo g_implement_interface_info = { \
122  (GInterfaceInitFunc)(void (*)(void *, void *)) iface_init, NULL, NULL \
123  }; \
124  g_type_add_interface_static (g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
125 }
126 
127 #define GNC_DEFINE_TYPE_WITH_CODE(TN, t_n, T_P, _C_) _GNC_DEFINE_TYPE_EXTENDED_BEGIN (TN, t_n, T_P, 0) {_C_;} _GNC_DEFINE_TYPE_EXTENDED_END()
128 
129 #define _GNC_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
130 \
131 static void type_name##_init (TypeName *self, void *class); \
132 static void type_name##_class_init (TypeName##Class *klass); \
133 static gpointer type_name##_parent_class = NULL; \
134 static gint TypeName##_private_offset; \
135 \
136 _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
137 \
138 G_GNUC_UNUSED \
139 static inline gpointer \
140 type_name##_get_instance_private (TypeName *self) \
141 { \
142  return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
143 } \
144 \
145 GType \
146 type_name##_get_type (void) \
147 { \
148  static gsize g_define_type_id_static = 0; \
149  if (g_once_init_enter (&g_define_type_id_static)) \
150  { \
151  GType g_define_type_id = \
152  g_type_register_static_simple (TYPE_PARENT, \
153  g_intern_static_string (#TypeName), \
154  sizeof (TypeName##Class), \
155  (GClassInitFunc) type_name##_class_intern_init, \
156  sizeof (TypeName), \
157  (GInstanceInitFunc) type_name##_init, \
158  (GTypeFlags) flags); \
159  { /* custom code follows */
160 #define _GNC_DEFINE_TYPE_EXTENDED_END() \
161  /* following custom code */ \
162  } \
163  g_once_init_leave (&g_define_type_id_static, g_define_type_id); \
164  } \
165  return g_define_type_id_static; \
166 } /* closes type_name##_get_type() */
167 
168 
169 #endif /* GNC_GOBJECT_UTILS_H */
170 
const GList * gnc_gobject_tracking_get_list(const gchar *name)
Get a list of all known objects of a specified type.
void gnc_gobject_tracking_dump(void)
Dump the entire object tracking database via the g_log() family of functions.
void gnc_gobject_tracking_remember(GObject *object, GObjectClass *klass)
Tell gnucash to remember this object in the database.
void gnc_gobject_tracking_forget(GObject *object)
Tell gnucash to drop this object from the database.