]> git.0d.be Git - empathy.git/blob - tools/gobject-foo.py
remove released flag
[empathy.git] / tools / gobject-foo.py
1 #!/usr/bin/python
2
3 # gobject-foo.py: generate standard GObject type macros etc.
4 #
5 # The master copy of this program is in the telepathy-glib repository -
6 # please make any changes there.
7 #
8 # Copyright (C) 2007-2010 Collabora Ltd. <http://www.collabora.co.uk/>
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
24 def gobject_header(head, tail, as_interface=False):
25     out = []
26     o = out.append
27
28     name = head + '_' + tail
29     MixedCase = name.replace('_', '')
30     lower_case = name.lower()
31     UPPER_CASE = name.upper()
32
33     gtype = head.upper() + '_TYPE_' + tail.upper()
34
35     o("typedef struct _%s %s;" % (MixedCase, MixedCase))
36
37     if as_interface:
38         o("typedef struct _%sInterface %sInterface;" % (MixedCase, MixedCase))
39     else:
40         o("typedef struct _%sClass %sClass;" % (MixedCase, MixedCase))
41         o("typedef struct _%sPrivate %sPrivate;" % (MixedCase, MixedCase))
42
43     o("")
44     o("GType %s_get_type (void);" % lower_case)
45     o("")
46
47     o("#define %s \\" % gtype)
48     o("  (%s_get_type ())" % lower_case)
49
50     o("#define %s(obj) \\" % UPPER_CASE)
51     o("  (G_TYPE_CHECK_INSTANCE_CAST ((obj), %s, \\" % gtype)
52     o("                               %s))" % MixedCase)
53
54     if not as_interface:
55         o("#define %s_CLASS(klass) \\" % UPPER_CASE)
56         o("  (G_TYPE_CHECK_CLASS_CAST ((klass), %s, \\" % gtype)
57         o("                            %sClass))" % MixedCase)
58
59     o("#define %s_IS_%s(obj) \\" % (head.upper(), tail.upper()))
60     o("  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), %s))" % gtype)
61
62     if as_interface:
63         o("#define %s_GET_IFACE(obj) \\" % UPPER_CASE)
64         o("  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, \\" % gtype)
65         o("                                  %sInterface))" % MixedCase)
66     else:
67         o("#define %s_IS_%s_CLASS(klass) \\" % (head.upper(), tail.upper()))
68         o("  (G_TYPE_CHECK_CLASS_TYPE ((klass), %s))" % gtype)
69
70         o("#define %s_GET_CLASS(obj) \\" % UPPER_CASE)
71         o("  (G_TYPE_INSTANCE_GET_CLASS ((obj), %s, \\" % gtype)
72         o("                              %sClass))" % MixedCase)
73
74     return out
75
76 if __name__ == '__main__':
77     import sys
78     from getopt import gnu_getopt
79
80     options, argv = gnu_getopt(sys.argv[1:], '', ['interface'])
81
82     as_interface = False
83
84     for opt, val in options:
85         if opt == '--interface':
86             as_interface = True
87
88     head, tail = argv
89
90     print('\n'.join(gobject_header(head, tail, as_interface=as_interface)))