| 434 | * Generic object base |
| 435 | */ |
| 436 | export class TVMObject implements Disposable { |
| 437 | protected handle: Pointer; |
| 438 | protected lib: FFILibrary; |
| 439 | protected ctx: RuntimeContext; |
| 440 | |
| 441 | constructor( |
| 442 | handle: Pointer, |
| 443 | lib: FFILibrary, |
| 444 | ctx: RuntimeContext |
| 445 | ) { |
| 446 | this.handle = handle; |
| 447 | this.lib = lib; |
| 448 | this.ctx = ctx; |
| 449 | } |
| 450 | |
| 451 | dispose(): void { |
| 452 | if (this.handle != 0) { |
| 453 | this.lib.checkCall( |
| 454 | (this.lib.exports.TVMFFIObjectDecRef as ctypes.FTVMFFIObjectDecRef)(this.handle) |
| 455 | ); |
| 456 | this.handle = 0; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Get handle of module, check it is not null. |
| 462 | * |
| 463 | * @param requireNotNull require handle is not null. |
| 464 | * @returns The handle. |
| 465 | */ |
| 466 | getHandle(requireNotNull = true): Pointer { |
| 467 | if (requireNotNull && this.handle === 0) { |
| 468 | throw Error("Object has already been disposed"); |
| 469 | } |
| 470 | return this.handle; |
| 471 | } |
| 472 | |
| 473 | /** get the type index of the object */ |
| 474 | typeIndex(): number { |
| 475 | if (this.handle === 0) { |
| 476 | throw Error("The current Object has already been disposed"); |
| 477 | } |
| 478 | return this.lib.memory.loadObjectTypeIndex(this.handle); |
| 479 | } |
| 480 | |
| 481 | /** get the type key of the object */ |
| 482 | typeKey(): string { |
| 483 | const type_index = this.typeIndex(); |
| 484 | const typeInfoPtr = (this.lib.exports.TVMFFIGetTypeInfo as ctypes.FTVMFFIGetTypeInfo)( |
| 485 | type_index |
| 486 | ); |
| 487 | return this.lib.memory.loadTypeInfoTypeKey(typeInfoPtr); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Cell holds the PackedFunc object. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…