]> git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/scripts/c_tools.py
6df0d9bece5c25e68a016869f1027fd0db9a9c1f
[wxWidgets.git] / docs / doxygen / scripts / c_tools.py
1 """
2 C bindings generator
3 Author: Luke A. Guest
4 """
5
6 import os
7
8 from common import *
9
10 class CBuilder:
11 def __init__(self, doxyparse, outputdir):
12 self.doxyparser = doxyparse
13 self.output_dir = outputdir
14
15 def make_bindings(self):
16 output_dir = os.path.abspath(os.path.join(self.output_dir, "c"))
17 if not os.path.exists(output_dir):
18 os.makedirs(output_dir)
19
20 for aclass in self.doxyparser.classes:
21 # This bit doesn't work, because the aclass.name is not the same as
22 # those listed in common
23 if aclass.name in excluded_classes:
24 #print "Skipping %s" % aclass.name
25 continue
26
27 self.make_c_header(output_dir, aclass)
28
29
30 def make_c_header(self, output_dir, aclass):
31 filename = os.path.join(output_dir, aclass.name[2:].lower() + ".hh")
32 enums_text = make_enums(aclass)
33 method_text = self.make_c_methods(aclass)
34 class_name = aclass.name[2:].capitalize()
35 text = """
36 // Enums
37 %s
38
39 %s
40 """ % (enums_text, method_text)
41
42 afile = open(filename, "wb")
43 afile.write(text)
44 afile.close()
45
46
47 def make_c_methods(self, aclass):
48 retval = ""
49
50 wxc_classname = 'wxC' + aclass.name[2:].capitalize()
51
52 for amethod in aclass.constructors:
53 if amethod.name.startswith('m_'):
54 # for some reason, public members are listed as methods
55 continue
56 retval += """
57 // %s
58 %s%s;\n\n
59 """ % (amethod.brief_description, wxc_classname + '* ' + wxc_classname + '_' + amethod.name, amethod.argsstring)
60
61 for amethod in aclass.methods:
62 args = '(' + wxc_classname + '* obj'
63 if amethod.argsstring.find('()') != -1:
64 args += ')'
65 else:
66 args += ', ' + amethod.argsstring[1:].strip()
67
68 retval += """
69 // %s
70 %s %s%s;\n
71 """ % (amethod.detailed_description, amethod.return_type, wxc_classname + '_' + amethod.name, args)
72
73 return retval