GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-basic-gobject.h
1 /********************************************************************\
2  * gnc-basic-gobject.h *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, write to the Free Software *
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
17 \********************************************************************/
18 
19 
20 #ifndef GNC_BASIC_GOBJECT_H
21 #define GNC_BASIC_GOBJECT_H
22 
23 /* A simple macro to define simple gobjects */
24 
25 #define GNC_BASIC_GOBJECT_TYPE(type_struct,klass_struct,parent,klass_init,inst_init,get_type_fcn) \
26 GType \
27 get_type_fcn (void) \
28 { \
29  static GType type = 0; \
30  \
31  if (type == 0) { \
32  GTypeInfo type_info = { \
33  sizeof (klass_struct), \
34  NULL, \
35  NULL, \
36  (GClassInitFunc) klass_init, \
37  NULL, \
38  NULL, \
39  sizeof (type_struct), \
40  0, \
41  (GInstanceInitFunc) inst_init, \
42  }; \
43  \
44  type = g_type_register_static (parent, #type_struct, &type_info, 0); \
45  } \
46  \
47  return type; \
48 }
49 
50 #define GNC_BASIC_GOBJECT_NEW(type_struct,new_fcn,get_type_fcn) \
51 type_struct * \
52 new_fcn (void) \
53 { \
54  return (type_struct *) g_object_new(get_type_fcn (), NULL); \
55 }
56 
57 #define GNC_BASIC_GOBJECT(type_struct,klass_struct,parent,klass_init,inst_init,get_type_fcn,new_fcn) \
58 GNC_BASIC_GOBJECT_TYPE(type_struct,klass_struct,parent,klass_init,inst_init,get_type_fcn) \
59 GNC_BASIC_GOBJECT_NEW(type_struct,new_fcn,get_type_fcn)
60 
61 #endif /* GNC_BASIC_GOBJECT_H */