forked from Autodesk/AutomaticComponentToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTTI.py
More file actions
593 lines (476 loc) · 22.6 KB
/
RTTI.py
File metadata and controls
593 lines (476 loc) · 22.6 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
'''++
Copyright (C) 2021 ADSK
All rights reserved.
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.
Abstract: This is an autogenerated Python file in order to allow an easy
use of RTTI
Interface version: 1.0.0
'''
import ctypes
import platform
import enum
import os
name = "rtti"
'''Definition of domain specific exception
'''
class ERTTIException(Exception):
def __init__(self, code, message = ''):
self._code = code
self._message = message
def __str__(self):
if self._message:
return 'RTTIException ' + str(self._code) + ': '+ str(self._message)
return 'RTTIException ' + str(self._code)
def get_error_code(self):
"""Returns the error code"""
return self._code
def get_error_message(self):
"""Returns the custom error message"""
return self._message
def get_error_name(self):
"""Returns the error name (constant name)"""
if self._code == ErrorCodes.SUCCESS:
return 'SUCCESS'
elif self._code == ErrorCodes.NOTIMPLEMENTED:
return 'NOTIMPLEMENTED'
elif self._code == ErrorCodes.INVALIDPARAM:
return 'INVALIDPARAM'
elif self._code == ErrorCodes.INVALIDCAST:
return 'INVALIDCAST'
elif self._code == ErrorCodes.BUFFERTOOSMALL:
return 'BUFFERTOOSMALL'
elif self._code == ErrorCodes.GENERICEXCEPTION:
return 'GENERICEXCEPTION'
elif self._code == ErrorCodes.COULDNOTLOADLIBRARY:
return 'COULDNOTLOADLIBRARY'
elif self._code == ErrorCodes.COULDNOTFINDLIBRARYEXPORT:
return 'COULDNOTFINDLIBRARYEXPORT'
elif self._code == ErrorCodes.INCOMPATIBLEBINARYVERSION:
return 'INCOMPATIBLEBINARYVERSION'
else:
return 'UNKNOWN'
def get_error_description(self):
"""Returns the error description (human-readable)"""
if self._code == ErrorCodes.SUCCESS:
return 'success'
elif self._code == ErrorCodes.NOTIMPLEMENTED:
return 'functionality not implemented'
elif self._code == ErrorCodes.INVALIDPARAM:
return 'an invalid parameter was passed'
elif self._code == ErrorCodes.INVALIDCAST:
return 'a type cast failed'
elif self._code == ErrorCodes.BUFFERTOOSMALL:
return 'a provided buffer is too small'
elif self._code == ErrorCodes.GENERICEXCEPTION:
return 'a generic exception occurred'
elif self._code == ErrorCodes.COULDNOTLOADLIBRARY:
return 'the library could not be loaded'
elif self._code == ErrorCodes.COULDNOTFINDLIBRARYEXPORT:
return 'a required exported symbol could not be found in the library'
elif self._code == ErrorCodes.INCOMPATIBLEBINARYVERSION:
return 'the version of the binary interface does not match the bindings interface'
else:
return 'unknown error'
@property
def error_code(self):
"""Property to access error code"""
return self._code
@property
def error_message(self):
"""Property to access custom error message"""
return self._message
@property
def error_name(self):
"""Property to access error name"""
return self.get_error_name()
@property
def error_description(self):
"""Property to access error description"""
return self.get_error_description()
'''Definition of binding API version
'''
class BindingVersion(enum.IntEnum):
MAJOR = 1
MINOR = 0
MICRO = 0
'''Definition Error Codes
'''
class ErrorCodes(enum.IntEnum):
SUCCESS = 0
NOTIMPLEMENTED = 1
INVALIDPARAM = 2
INVALIDCAST = 3
BUFFERTOOSMALL = 4
GENERICEXCEPTION = 5
COULDNOTLOADLIBRARY = 6
COULDNOTFINDLIBRARYEXPORT = 7
INCOMPATIBLEBINARYVERSION = 8
'''Definition of Function Table
'''
class FunctionTable:
rtti_getversion = None
rtti_getlasterror = None
rtti_releaseinstance = None
rtti_acquireinstance = None
rtti_injectcomponent = None
rtti_getsymbollookupmethod = None
rtti_createzoo = None
rtti_base_classtypeid = None
rtti_animal_name = None
rtti_tiger_roar = None
rtti_animaliterator_getnextanimal = None
rtti_animaliterator_getnextoptinalanimal = None
rtti_animaliterator_getnextmandatoryanimal = None
rtti_zoo_iterator = None
'''Wrapper Class Implementation
'''
class Wrapper:
def __init__(self, libraryName = None, symbolLookupMethodAddress = None):
ending = ''
if platform.system() == 'Windows':
ending = 'dll'
elif platform.system() == 'Linux':
ending = 'so'
elif platform.system() == 'Darwin':
ending = 'dylib'
else:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY)
if (not libraryName) and (not symbolLookupMethodAddress):
libraryName = os.path.join(os.path.dirname(os.path.realpath(__file__)),'rtti')
if libraryName is not None:
path = libraryName + '.' + ending
try:
self.lib = ctypes.CDLL(path)
except Exception as e:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(e) + '| "'+path + '"' )
self._loadFunctionTable()
elif symbolLookupMethodAddress is not None:
self.lib = FunctionTable()
self._loadFunctionTableFromMethod(symbolLookupMethodAddress)
else:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(e))
self._checkBinaryVersion()
def _loadFunctionTableFromMethod(self, symbolLookupMethodAddress):
try:
symbolLookupMethodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_char_p, ctypes.POINTER(ctypes.c_void_p))
symbolLookupMethod = symbolLookupMethodType(int(symbolLookupMethodAddress))
methodAddress = ctypes.c_void_p()
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_getversion")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32))
self.lib.rtti_getversion = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_getlasterror")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64), ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool))
self.lib.rtti_getlasterror = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_releaseinstance")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p)
self.lib.rtti_releaseinstance = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_acquireinstance")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p)
self.lib.rtti_acquireinstance = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_injectcomponent")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_char_p, ctypes.c_void_p)
self.lib.rtti_injectcomponent = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_getsymbollookupmethod")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.POINTER(ctypes.c_void_p))
self.lib.rtti_getsymbollookupmethod = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_createzoo")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.POINTER(ctypes.c_void_p))
self.lib.rtti_createzoo = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_base_classtypeid")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint64))
self.lib.rtti_base_classtypeid = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_animal_name")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64), ctypes.c_char_p)
self.lib.rtti_animal_name = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_tiger_roar")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p)
self.lib.rtti_tiger_roar = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_animaliterator_getnextanimal")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p))
self.lib.rtti_animaliterator_getnextanimal = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_animaliterator_getnextoptinalanimal")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_bool))
self.lib.rtti_animaliterator_getnextoptinalanimal = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_animaliterator_getnextmandatoryanimal")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_bool))
self.lib.rtti_animaliterator_getnextmandatoryanimal = methodType(int(methodAddress.value))
err = symbolLookupMethod(ctypes.c_char_p(str.encode("rtti_zoo_iterator")), methodAddress)
if err != 0:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, str(err))
methodType = ctypes.CFUNCTYPE(ctypes.c_int32, ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p))
self.lib.rtti_zoo_iterator = methodType(int(methodAddress.value))
except AttributeError as ae:
raise ERTTIException(ErrorCodes.COULDNOTFINDLIBRARYEXPORT, ae.args[0])
def _loadFunctionTable(self):
try:
self.lib.rtti_getversion.restype = ctypes.c_int32
self.lib.rtti_getversion.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32)]
self.lib.rtti_getlasterror.restype = ctypes.c_int32
self.lib.rtti_getlasterror.argtypes = [ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64), ctypes.c_char_p, ctypes.POINTER(ctypes.c_bool)]
self.lib.rtti_releaseinstance.restype = ctypes.c_int32
self.lib.rtti_releaseinstance.argtypes = [ctypes.c_void_p]
self.lib.rtti_acquireinstance.restype = ctypes.c_int32
self.lib.rtti_acquireinstance.argtypes = [ctypes.c_void_p]
self.lib.rtti_injectcomponent.restype = ctypes.c_int32
self.lib.rtti_injectcomponent.argtypes = [ctypes.c_char_p, ctypes.c_void_p]
self.lib.rtti_getsymbollookupmethod.restype = ctypes.c_int32
self.lib.rtti_getsymbollookupmethod.argtypes = [ctypes.POINTER(ctypes.c_void_p)]
self.lib.rtti_createzoo.restype = ctypes.c_int32
self.lib.rtti_createzoo.argtypes = [ctypes.POINTER(ctypes.c_void_p)]
self.lib.rtti_base_classtypeid.restype = ctypes.c_int32
self.lib.rtti_base_classtypeid.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint64)]
self.lib.rtti_animal_name.restype = ctypes.c_int32
self.lib.rtti_animal_name.argtypes = [ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64), ctypes.c_char_p]
self.lib.rtti_tiger_roar.restype = ctypes.c_int32
self.lib.rtti_tiger_roar.argtypes = [ctypes.c_void_p]
self.lib.rtti_animaliterator_getnextanimal.restype = ctypes.c_int32
self.lib.rtti_animaliterator_getnextanimal.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p)]
self.lib.rtti_animaliterator_getnextoptinalanimal.restype = ctypes.c_int32
self.lib.rtti_animaliterator_getnextoptinalanimal.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_bool)]
self.lib.rtti_animaliterator_getnextmandatoryanimal.restype = ctypes.c_int32
self.lib.rtti_animaliterator_getnextmandatoryanimal.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_bool)]
self.lib.rtti_zoo_iterator.restype = ctypes.c_int32
self.lib.rtti_zoo_iterator.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_void_p)]
except AttributeError as ae:
raise ERTTIException(ErrorCodes.COULDNOTFINDLIBRARYEXPORT, ae.args[0])
def _checkBinaryVersion(self):
nMajor, nMinor, _ = self.GetVersion()
if (nMajor != BindingVersion.MAJOR) or (nMinor < BindingVersion.MINOR):
raise ERTTIException(ErrorCodes.INCOMPATIBLEBINARYVERSION)
def checkError(self, instance, errorCode):
ec = globals().get('ErrorCodes')
if ec is None:
# Interpreter shutdown: ErrorCodes may already be cleared; avoid noisy teardown
return
if errorCode != ec.SUCCESS.value:
if instance:
if instance._wrapper != self:
raise ERTTIException(ec.INVALIDCAST, 'invalid wrapper call')
message,_ = self.GetLastError(instance)
raise ERTTIException(errorCode, message)
def GetVersion(self, Major = None, Minor = None, Micro = None):
pMajor = ctypes.c_uint32(Major if Major is not None else 0)
pMinor = ctypes.c_uint32(Minor if Minor is not None else 0)
pMicro = ctypes.c_uint32(Micro if Micro is not None else 0)
self.checkError(None, self.lib.rtti_getversion(pMajor, pMinor, pMicro))
return pMajor.value, pMinor.value, pMicro.value
def GetLastError(self, InstanceObject, ErrorMessage = None):
InstanceHandle = None
if InstanceObject:
InstanceHandle = InstanceObject._handle
else:
raise ERTTIException(ErrorCodes.INVALIDPARAM, 'Invalid return/output value')
nErrorMessageBufferSize = ctypes.c_uint64(len(ErrorMessage) if ErrorMessage else 0)
nErrorMessageNeededChars = ctypes.c_uint64(0)
pErrorMessageBuffer = ctypes.c_char_p(str.encode(ErrorMessage) if ErrorMessage else None)
pHasError = ctypes.c_bool()
self.checkError(None, self.lib.rtti_getlasterror(InstanceHandle, nErrorMessageBufferSize, nErrorMessageNeededChars, pErrorMessageBuffer, pHasError))
nErrorMessageBufferSize = ctypes.c_uint64(nErrorMessageNeededChars.value)
pErrorMessageBuffer = (ctypes.c_char * (nErrorMessageNeededChars.value))()
self.checkError(None, self.lib.rtti_getlasterror(InstanceHandle, nErrorMessageBufferSize, nErrorMessageNeededChars, pErrorMessageBuffer, pHasError))
return pErrorMessageBuffer.value.decode(), pHasError.value
def ReleaseInstance(self, InstanceObject):
InstanceHandle = None
if InstanceObject:
InstanceHandle = InstanceObject._handle
else:
raise ERTTIException(ErrorCodes.INVALIDPARAM, 'Invalid return/output value')
self.checkError(None, self.lib.rtti_releaseinstance(InstanceHandle))
def AcquireInstance(self, InstanceObject):
InstanceHandle = None
if InstanceObject:
InstanceHandle = InstanceObject._handle
else:
raise ERTTIException(ErrorCodes.INVALIDPARAM, 'Invalid return/output value')
self.checkError(None, self.lib.rtti_acquireinstance(InstanceHandle))
def InjectComponent(self, NameSpace, SymbolAddressMethod):
pNameSpace = ctypes.c_char_p(str.encode(NameSpace))
pSymbolAddressMethod = ctypes.c_void_p(SymbolAddressMethod)
self.checkError(None, self.lib.rtti_injectcomponent(pNameSpace, pSymbolAddressMethod))
bNameSpaceFound = False
if not bNameSpaceFound:
raise ERTTIException(ErrorCodes.COULDNOTLOADLIBRARY, "Unknown namespace " + NameSpace)
def GetSymbolLookupMethod(self):
pSymbolLookupMethod = ctypes.c_void_p()
self.checkError(None, self.lib.rtti_getsymbollookupmethod(pSymbolLookupMethod))
return pSymbolLookupMethod.value
def CreateZoo(self):
InstanceHandle = ctypes.c_void_p()
self.checkError(None, self.lib.rtti_createzoo(InstanceHandle))
if InstanceHandle:
InstanceObject = self._polymorphicFactory(InstanceHandle)
else:
raise ERTTIException(ErrorCodes.INVALIDCAST, 'Invalid return/output value')
return InstanceObject
'''IMPORTANT: PolymorphicFactory method should not be used by application directly.
It's designed to be used on RTTIHandle object only once.
If it's used on any existing object as a form of dynamic cast then
Wrapper.AcquireInstance(object) must be called after instantiating new object.
This is important to keep reference count matching between application and library sides.
'''
def _polymorphicFactory(self, handle):
class PolymorphicFactory():
def getObjectById(self, classtypeid, handle, wrapper):
methodName = 'getObjectById_' + format(classtypeid.value, '016X')
method = getattr(self, methodName, lambda: 'Invalid class type id')
return method(handle, wrapper)
def getObjectById_1549AD28813DAE05(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Base"
return Base(handle, wrapper)
def getObjectById_8B40467DA6D327AF(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Animal"
return Animal(handle, wrapper)
def getObjectById_BC9D5FA7750C1020(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Mammal"
return Mammal(handle, wrapper)
def getObjectById_6756AA8EA5802EC3(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Reptile"
return Reptile(handle, wrapper)
def getObjectById_9751971BD2C2D958(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Giraffe"
return Giraffe(handle, wrapper)
def getObjectById_08D007E7B5F7BAF4(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Tiger"
return Tiger(handle, wrapper)
def getObjectById_5F6826EF909803B2(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Snake"
return Snake(handle, wrapper)
def getObjectById_8E551B208A2E8321(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Turtle"
return Turtle(handle, wrapper)
def getObjectById_F1917FE6BBE77831(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::AnimalIterator"
return AnimalIterator(handle, wrapper)
def getObjectById_2262ABE80A5E7878(self, handle, wrapper): # First 64 bits of SHA1 of a string: "RTTI::Zoo"
return Zoo(handle, wrapper)
if not handle:
return None
pClassTypeId = ctypes.c_uint64()
self.checkError(None, self.lib.rtti_base_classtypeid(handle, pClassTypeId))
factory = PolymorphicFactory()
return factory.getObjectById(pClassTypeId, handle, self)
''' Class Implementation for Base
'''
class Base:
def __init__(self, handle, wrapper):
if not handle or not wrapper:
raise ERTTIException(ErrorCodes.INVALIDPARAM)
self._handle = handle
self._wrapper = wrapper
def __del__(self):
self._wrapper.ReleaseInstance(self)
def ClassTypeId(self):
pClassTypeId = ctypes.c_uint64()
self._wrapper.checkError(self, self._wrapper.lib.rtti_base_classtypeid(self._handle, pClassTypeId))
return pClassTypeId.value
''' Class Implementation for Animal
'''
class Animal(Base):
def __init__(self, handle, wrapper):
Base.__init__(self, handle, wrapper)
def Name(self):
nResultBufferSize = ctypes.c_uint64(0)
nResultNeededChars = ctypes.c_uint64(0)
pResultBuffer = ctypes.c_char_p(None)
self._wrapper.checkError(self, self._wrapper.lib.rtti_animal_name(self._handle, nResultBufferSize, nResultNeededChars, pResultBuffer))
nResultBufferSize = ctypes.c_uint64(nResultNeededChars.value)
pResultBuffer = (ctypes.c_char * (nResultNeededChars.value))()
self._wrapper.checkError(self, self._wrapper.lib.rtti_animal_name(self._handle, nResultBufferSize, nResultNeededChars, pResultBuffer))
return pResultBuffer.value.decode()
''' Class Implementation for Mammal
'''
class Mammal(Animal):
def __init__(self, handle, wrapper):
Animal.__init__(self, handle, wrapper)
''' Class Implementation for Reptile
'''
class Reptile(Animal):
def __init__(self, handle, wrapper):
Animal.__init__(self, handle, wrapper)
''' Class Implementation for Giraffe
'''
class Giraffe(Mammal):
def __init__(self, handle, wrapper):
Mammal.__init__(self, handle, wrapper)
''' Class Implementation for Tiger
'''
class Tiger(Mammal):
def __init__(self, handle, wrapper):
Mammal.__init__(self, handle, wrapper)
def Roar(self):
self._wrapper.checkError(self, self._wrapper.lib.rtti_tiger_roar(self._handle))
''' Class Implementation for Snake
'''
class Snake(Reptile):
def __init__(self, handle, wrapper):
Reptile.__init__(self, handle, wrapper)
''' Class Implementation for Turtle
'''
class Turtle(Reptile):
def __init__(self, handle, wrapper):
Reptile.__init__(self, handle, wrapper)
''' Class Implementation for AnimalIterator
'''
class AnimalIterator(Base):
def __init__(self, handle, wrapper):
Base.__init__(self, handle, wrapper)
def GetNextAnimal(self):
AnimalHandle = ctypes.c_void_p()
self._wrapper.checkError(self, self._wrapper.lib.rtti_animaliterator_getnextanimal(self._handle, AnimalHandle))
if AnimalHandle:
AnimalObject = self._wrapper._polymorphicFactory(AnimalHandle)
else:
AnimalObject = None
return AnimalObject
def GetNextOptinalAnimal(self, AnimalObject = None):
AnimalHandle = ctypes.c_void_p()
if AnimalObject is not None:
AnimalHandle = ctypes.c_void_p(AnimalObject._handle)
pError = ctypes.c_bool()
self._wrapper.checkError(self, self._wrapper.lib.rtti_animaliterator_getnextoptinalanimal(self._handle, AnimalHandle, pError))
if AnimalHandle.value:
AnimalObject = self._wrapper._polymorphicFactory(AnimalHandle.value)
else:
AnimalObject = None
return AnimalObject, pError.value
def GetNextMandatoryAnimal(self, AnimalObject = None):
AnimalHandle = ctypes.c_void_p()
if AnimalObject is not None:
AnimalHandle = ctypes.c_void_p(AnimalObject._handle)
pError = ctypes.c_bool()
self._wrapper.checkError(self, self._wrapper.lib.rtti_animaliterator_getnextmandatoryanimal(self._handle, AnimalHandle, pError))
if AnimalHandle.value:
AnimalObject = self._wrapper._polymorphicFactory(AnimalHandle.value)
else:
AnimalObject = None
return AnimalObject, pError.value
''' Class Implementation for Zoo
'''
class Zoo(Base):
def __init__(self, handle, wrapper):
Base.__init__(self, handle, wrapper)
def Iterator(self):
IteratorHandle = ctypes.c_void_p()
self._wrapper.checkError(self, self._wrapper.lib.rtti_zoo_iterator(self._handle, IteratorHandle))
if IteratorHandle:
IteratorObject = self._wrapper._polymorphicFactory(IteratorHandle)
else:
raise ERTTIException(ErrorCodes.INVALIDCAST, 'Invalid return/output value')
return IteratorObject