-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_byhandtest.py
74 lines (49 loc) · 2.39 KB
/
gen_byhandtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Test script for generating a wrapper for the code in autogentest.h by hand.
"""
import sys
import os
from pybindgen import ReturnValue, Parameter, Module, Function, FileCodeSink
from pybindgen import CppMethod, CppConstructor, CppClass, Enum
import pybindgen.settings
pybindgen.settings.automatic_type_narrowing = True
NAME = 'byhandtest'
SRC = 'autogentest.h'
DEST = 'byhandtest_wrap.cpp'
def my_module_gen():
module = Module(NAME)
module.add_include('"%s"' % SRC)
A = module.add_class('A', allow_subclassing=True)
A.add_constructor([])
A.add_method('virtualMethod1', None, [], is_virtual=True, is_pure_virtual=True)
A.add_method('virtualMethod2', None, [], is_virtual=True)
B = module.add_class('B', parent=A)
B.add_constructor([])
B.add_constructor([Parameter.new('int', 'a'), Parameter.new('int', 'b')])
B.add_method('virtualMethod1', None, [], is_virtual=True)
B.add_method('overloadedMethod', None, [])
B.add_method('overloadedMethod', None, [Parameter.new('int', 'a'), Parameter.new('int', 'b')])
B.add_method('overloadedMethod', None, [Parameter.new('double', 'd')])
B.add_method('defaultArgs', None, [Parameter.new('int', 'a', default_value='0'),
Parameter.new('int', 'b', default_value='123')])
#bool operator==(const B& other) { return false; }
#bool operator!=(const B& other) { return true; }
#B& operator+(const B& other) { return *this; }
#// anything special done for these?
#int __len__() { return 0; } // yes, added to sequence methods structure
#int __int__() { return 0; } // no but the method is still there
#operator bool() { return true; } // no
#static void staticMethod() {}
#int m_publicAttribute;
C = module.add_class('C', parent=B)
C.add_constructor([])
C.add_constructor([Parameter.new('int', 'a'), Parameter.new('int', 'b')])
C.add_method('returnBaseClassPtr',
ReturnValue.new('A*',reference_existing_object=True),
[])
C.add_method('baseClassParameterPtr', None, [Parameter.new('const A*', 'other')])
C.add_method('baseClassParameterRef', None, [Parameter.new('const A&', 'other')])
output = open(DEST, 'w')
module.generate(FileCodeSink(output))
if __name__ == '__main__':
my_module_gen()