5 def __init__(self, name):
14 def wrap_instance(self, instance):
21 Type.__init__(self, "void")
26 class Intrinsic(Type):
28 def __init__(self, name, format):
29 Type.__init__(self, name)
35 def __init__(self, type):
36 Type.__init__(self, 'C' + type.name)
40 return "const " + str(self.type)
45 def __init__(self, type):
46 Type.__init__(self, 'P' + type.name)
50 return str(self.type) + " *"
52 def wrap_instance(self, instance):
53 self.type.wrap_instance("*" + instance)
58 def __init__(self, type):
59 Type.__init__(self, type.name)
68 def wrap_instance(self, instance):
69 self.type.wrap_instance(instance)
74 def __init__(self, name, values):
75 Type.__init__(self, name)
81 def __init__(self, type, values):
82 Type.__init__(self, type.name)
88 def __init__(self, name, members):
89 Type.__init__(self, name)
90 self.members = members
95 def __init__(self, name, type):
96 Type.__init__(self, name)
102 def __init__(self, type, name, args, call = '__stdcall'):
108 def prototype(self, name=None):
115 s = self.call + ' ' + s
116 if name.startswith('*'):
118 s = str(self.type) + ' ' + s
121 s += ", ".join(["%s %s" % (type, name) for type, name in self.args])
128 class Interface(Type):
130 def __init__(self, name, base=None):
131 Type.__init__(self, name)
135 def itermethods(self):
136 if self.base is not None:
137 for method in self.base.itermethods():
139 for method in self.methods:
144 return "Wrap" + self.name
146 def wrap_pre_decl(self):
147 print "class %s;" % self.wrap_name()
150 print "class %s : public %s " % (self.wrap_name(), self.name)
153 print " %s(%s * pInstance);" % (self.wrap_name(), self.name)
154 print " virtual ~%s();" % self.wrap_name()
156 for method in self.itermethods():
157 print " " + method.prototype() + ";"
160 print " Log *m_pLog;"
161 print " %s * m_pInstance;" % (self.name,)
166 print '%s::%s(%s * pInstance) {' % (self.wrap_name(), self.wrap_name(), self.name)
167 print ' m_pInstance = pInstance;'
170 print '%s::~%s() {' % (self.wrap_name(), self.wrap_name())
173 for method in self.itermethods():
174 print method.prototype(self.wrap_name() + '::' + method.name) + ' {'
175 if method.type is Void:
178 print ' %s result;' % method.type
180 print ' g_pLog->BeginCall("%s");' % (self.name + '::' + method.name)
181 print ' %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
182 print ' g_pLog->EndCall();'
183 for type, name in method.args:
185 type.wrap_instance(name)
186 if method.type is not Void:
187 method.type.wrap_instance('result')
188 if method.name == 'QueryInterface':
189 print ' if(*ppvObj == m_pInstance)'
190 print ' *ppvObj = this;'
191 if method.name == 'Release':
192 assert method.type is not Void
194 print ' delete this;'
195 if method.type is not Void:
196 print ' return result;'
202 class Method(Function):
204 def __init__(self, type, name, args):
205 Function.__init__(self, type, name, args)
210 class WrapPointer(Pointer):
212 def __init__(self, type):
213 Pointer.__init__(self, type)
214 if type not in towrap:
217 def wrap_instance(self, instance):
218 print " if(%s)" % instance
219 print " %s = new %s(%s);" % (instance, self.type.wrap_name(), instance)
221 String = Intrinsic("char *", "%s")
222 Int = Intrinsic("int", "%i")
223 Long = Intrinsic("long", "%li")
224 Float = Intrinsic("float", "%f")