| // AUTO GENERATED FILE, DO NOT EDIT. |
| // |
| // Generated by `package:ffigen`. |
| // ignore_for_file: type=lint, unused_import, unused_element, deprecated_member_use_from_same_package |
| @ffi.DefaultAsset('package:ffigen/cpp_test') |
| library; |
| |
| import 'dart:ffi' as ffi; |
| |
| class AccessBase implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_AccessBase_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| AccessBase.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_AccessBase_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_AccessBase_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| int value() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _AccessBase_value(_ptr); |
| } |
| |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>(symbol: 'AccessBase_value') |
| external int _AccessBase_value(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'AccessBase_delete', |
| ) |
| external void _AccessBase_delete(ffi.Pointer<ffi.Void> self); |
| |
| class Circle implements ffi.Finalizable, Shape { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Circle_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| Circle.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Circle_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Circle_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory Circle(double x, double y, double radius) { |
| return Circle.fromPointer(_Circle_new(x, y, radius), takeOwnership: true); |
| } |
| double area() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Circle_area(_ptr); |
| } |
| |
| double getX() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Circle_getX(_ptr); |
| } |
| |
| double getY() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Circle_getY(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function(ffi.Double, ffi.Double, ffi.Double)>( |
| symbol: 'Circle_new', |
| ) |
| external ffi.Pointer<ffi.Void> _Circle_new(double x, double y, double radius); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Circle_area') |
| external double _Circle_area(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Circle_getX') |
| external double _Circle_getX(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Circle_getY') |
| external double _Circle_getY(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(symbol: 'Circle_delete') |
| external void _Circle_delete(ffi.Pointer<ffi.Void> self); |
| |
| class ColoredCircle implements ffi.Finalizable, Circle, Drawable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_ColoredCircle_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| ColoredCircle.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_ColoredCircle_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_ColoredCircle_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory ColoredCircle(double x, double y, double radius, int color) { |
| return ColoredCircle.fromPointer( |
| _ColoredCircle_new(x, y, radius, color), |
| takeOwnership: true, |
| ); |
| } |
| int getColor() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _ColoredCircle_getColor(_ptr); |
| } |
| |
| double area() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _ColoredCircle_area(_ptr); |
| } |
| |
| double getX() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _ColoredCircle_getX(_ptr); |
| } |
| |
| double getY() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _ColoredCircle_getY(_ptr); |
| } |
| |
| int draw() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _ColoredCircle_draw(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native< |
| ffi.Pointer<ffi.Void> Function(ffi.Double, ffi.Double, ffi.Double, ffi.Int) |
| >(symbol: 'ColoredCircle_new') |
| external ffi.Pointer<ffi.Void> _ColoredCircle_new( |
| double x, |
| double y, |
| double radius, |
| int color, |
| ); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ColoredCircle_getColor', |
| ) |
| external int _ColoredCircle_getColor(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ColoredCircle_area', |
| ) |
| external double _ColoredCircle_area(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ColoredCircle_getX', |
| ) |
| external double _ColoredCircle_getX(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ColoredCircle_getY', |
| ) |
| external double _ColoredCircle_getY(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ColoredCircle_draw', |
| ) |
| external int _ColoredCircle_draw(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ColoredCircle_delete', |
| ) |
| external void _ColoredCircle_delete(ffi.Pointer<ffi.Void> self); |
| |
| class DiamondBase implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondBase_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| DiamondBase.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondBase_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondBase_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory DiamondBase() { |
| return DiamondBase.fromPointer(_DiamondBase_new(), takeOwnership: true); |
| } |
| int baseVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondBase_baseVal(_ptr); |
| } |
| |
| int virtVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondBase_virtVal(_ptr); |
| } |
| |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'DiamondBase_new') |
| external ffi.Pointer<ffi.Void> _DiamondBase_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondBase_baseVal', |
| ) |
| external int _DiamondBase_baseVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondBase_virtVal', |
| ) |
| external int _DiamondBase_virtVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondBase_delete', |
| ) |
| external void _DiamondBase_delete(ffi.Pointer<ffi.Void> self); |
| |
| class DiamondDerived implements ffi.Finalizable, DiamondLeft, DiamondRight { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondDerived_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| DiamondDerived.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondDerived_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondDerived_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory DiamondDerived() { |
| return DiamondDerived.fromPointer( |
| _DiamondDerived_new(), |
| takeOwnership: true, |
| ); |
| } |
| int virtVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondDerived_virtVal(_ptr); |
| } |
| |
| int baseVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondDerived_baseVal(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'DiamondDerived_new') |
| external ffi.Pointer<ffi.Void> _DiamondDerived_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondDerived_virtVal', |
| ) |
| external int _DiamondDerived_virtVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondDerived_baseVal', |
| ) |
| external int _DiamondDerived_baseVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondDerived_delete', |
| ) |
| external void _DiamondDerived_delete(ffi.Pointer<ffi.Void> self); |
| |
| class DiamondLeft implements ffi.Finalizable, DiamondBase { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondLeft_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| DiamondLeft.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondLeft_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondLeft_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory DiamondLeft() { |
| return DiamondLeft.fromPointer(_DiamondLeft_new(), takeOwnership: true); |
| } |
| int virtVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondLeft_virtVal(_ptr); |
| } |
| |
| int baseVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondLeft_baseVal(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'DiamondLeft_new') |
| external ffi.Pointer<ffi.Void> _DiamondLeft_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondLeft_virtVal', |
| ) |
| external int _DiamondLeft_virtVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondLeft_baseVal', |
| ) |
| external int _DiamondLeft_baseVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondLeft_delete', |
| ) |
| external void _DiamondLeft_delete(ffi.Pointer<ffi.Void> self); |
| |
| class DiamondRight implements ffi.Finalizable, DiamondBase { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondRight_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| DiamondRight.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondRight_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_DiamondRight_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory DiamondRight() { |
| return DiamondRight.fromPointer(_DiamondRight_new(), takeOwnership: true); |
| } |
| int baseVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondRight_baseVal(_ptr); |
| } |
| |
| int virtVal() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _DiamondRight_virtVal(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'DiamondRight_new') |
| external ffi.Pointer<ffi.Void> _DiamondRight_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondRight_baseVal', |
| ) |
| external int _DiamondRight_baseVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondRight_virtVal', |
| ) |
| external int _DiamondRight_virtVal(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'DiamondRight_delete', |
| ) |
| external void _DiamondRight_delete(ffi.Pointer<ffi.Void> self); |
| |
| class Drawable implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Drawable_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| Drawable.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Drawable_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Drawable_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory Drawable() { |
| return Drawable.fromPointer(_Drawable_new(), takeOwnership: true); |
| } |
| int draw() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Drawable_draw(_ptr); |
| } |
| |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'Drawable_new') |
| external ffi.Pointer<ffi.Void> _Drawable_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>(symbol: 'Drawable_draw') |
| external int _Drawable_draw(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(symbol: 'Drawable_delete') |
| external void _Drawable_delete(ffi.Pointer<ffi.Void> self); |
| |
| class OverloadBase implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_OverloadBase_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| OverloadBase.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_OverloadBase_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_OverloadBase_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory OverloadBase() { |
| return OverloadBase.fromPointer(_OverloadBase_new(), takeOwnership: true); |
| } |
| int getValue(int x) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _OverloadBase_getValue(_ptr, x); |
| } |
| |
| double getValueDouble(double x) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _OverloadBase_getValueDouble(_ptr, x); |
| } |
| |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'OverloadBase_new') |
| external ffi.Pointer<ffi.Void> _OverloadBase_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>, ffi.Int)>( |
| symbol: 'OverloadBase_getValue', |
| ) |
| external int _OverloadBase_getValue(ffi.Pointer<ffi.Void> self, int x); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>, ffi.Double)>( |
| symbol: 'OverloadBase_getValueDouble', |
| ) |
| external double _OverloadBase_getValueDouble( |
| ffi.Pointer<ffi.Void> self, |
| double x, |
| ); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'OverloadBase_delete', |
| ) |
| external void _OverloadBase_delete(ffi.Pointer<ffi.Void> self); |
| |
| class OverloadDerived implements ffi.Finalizable, OverloadBase { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_OverloadDerived_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| OverloadDerived.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_OverloadDerived_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_OverloadDerived_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory OverloadDerived() { |
| return OverloadDerived.fromPointer( |
| _OverloadDerived_new(), |
| takeOwnership: true, |
| ); |
| } |
| int getValue(int x) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _OverloadDerived_getValue(_ptr, x); |
| } |
| |
| double getValueDouble(double x) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _OverloadDerived_getValueDouble(_ptr, x); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'OverloadDerived_new') |
| external ffi.Pointer<ffi.Void> _OverloadDerived_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>, ffi.Int)>( |
| symbol: 'OverloadDerived_getValue', |
| ) |
| external int _OverloadDerived_getValue(ffi.Pointer<ffi.Void> self, int x); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>, ffi.Double)>( |
| symbol: 'OverloadDerived_getValueDouble', |
| ) |
| external double _OverloadDerived_getValueDouble( |
| ffi.Pointer<ffi.Void> self, |
| double x, |
| ); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'OverloadDerived_delete', |
| ) |
| external void _OverloadDerived_delete(ffi.Pointer<ffi.Void> self); |
| |
| class PrivateDerived implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_PrivateDerived_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| PrivateDerived.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_PrivateDerived_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_PrivateDerived_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory PrivateDerived() { |
| return PrivateDerived.fromPointer( |
| _PrivateDerived_new(), |
| takeOwnership: true, |
| ); |
| } |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'PrivateDerived_new') |
| external ffi.Pointer<ffi.Void> _PrivateDerived_new(); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'PrivateDerived_delete', |
| ) |
| external void _PrivateDerived_delete(ffi.Pointer<ffi.Void> self); |
| |
| class ProtectedDerived implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_ProtectedDerived_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| ProtectedDerived.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_ProtectedDerived_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_ProtectedDerived_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory ProtectedDerived() { |
| return ProtectedDerived.fromPointer( |
| _ProtectedDerived_new(), |
| takeOwnership: true, |
| ); |
| } |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'ProtectedDerived_new') |
| external ffi.Pointer<ffi.Void> _ProtectedDerived_new(); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'ProtectedDerived_delete', |
| ) |
| external void _ProtectedDerived_delete(ffi.Pointer<ffi.Void> self); |
| |
| class PublicDerived implements ffi.Finalizable, AccessBase { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_PublicDerived_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| PublicDerived.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_PublicDerived_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_PublicDerived_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory PublicDerived() { |
| return PublicDerived.fromPointer(_PublicDerived_new(), takeOwnership: true); |
| } |
| int value() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _PublicDerived_value(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function()>(symbol: 'PublicDerived_new') |
| external ffi.Pointer<ffi.Void> _PublicDerived_new(); |
| |
| @ffi.Native<ffi.Int Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'PublicDerived_value', |
| ) |
| external int _PublicDerived_value(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| symbol: 'PublicDerived_delete', |
| ) |
| external void _PublicDerived_delete(ffi.Pointer<ffi.Void> self); |
| |
| class Shape implements ffi.Finalizable { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Shape_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| Shape.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Shape_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Shape_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory Shape(double x, double y) { |
| return Shape.fromPointer(_Shape_new(x, y), takeOwnership: true); |
| } |
| double getX() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Shape_getX(_ptr); |
| } |
| |
| double getY() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Shape_getY(_ptr); |
| } |
| |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function(ffi.Double, ffi.Double)>( |
| symbol: 'Shape_new', |
| ) |
| external ffi.Pointer<ffi.Void> _Shape_new(double x, double y); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Shape_getX') |
| external double _Shape_getX(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Shape_getY') |
| external double _Shape_getY(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(symbol: 'Shape_delete') |
| external void _Shape_delete(ffi.Pointer<ffi.Void> self); |
| |
| class Square implements ffi.Finalizable, Shape { |
| ffi.Pointer<ffi.Void> _ptr; |
| static final _defaultFinalizer = ffi.NativeFinalizer( |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Square_delete), |
| ); |
| |
| /// The finalizer currently attached for this instance, or [null] if this |
| /// object does not own its pointer. |
| ffi.NativeFinalizer? _activeFinalizer; |
| |
| /// The native function pointer used by [_activeFinalizer], stored so that |
| /// [dispose] can call the correct destructor directly. |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| _activeFinalizerFn; |
| |
| Square.fromPointer(this._ptr, {bool takeOwnership = false}) { |
| if (takeOwnership) { |
| _defaultFinalizer.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = _defaultFinalizer; |
| _activeFinalizerFn = |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Square_delete); |
| } |
| } |
| |
| /// Attaches a finalizer so this object takes ownership of the underlying |
| /// C++ pointer. If [customFinalizer] is provided it is used instead of the |
| /// default `delete` finalizer, which is useful when the object was not |
| /// allocated with `new` (e.g. `malloc` or a custom allocator). |
| /// |
| /// Both [customFinalizer] and [customFinalizerFn] must be provided together. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object already owns the pointer. |
| void retainOwnership([ |
| ffi.NativeFinalizer? customFinalizer, |
| ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>? |
| customFinalizerFn, |
| ]) { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer != null) { |
| throw StateError('This object already owns its pointer.'); |
| } |
| if ((customFinalizer == null) != (customFinalizerFn == null)) { |
| throw ArgumentError( |
| 'Both customFinalizer and customFinalizerFn must be provided together.', |
| ); |
| } |
| final fin = customFinalizer ?? _defaultFinalizer; |
| final fnPtr = |
| customFinalizerFn ?? |
| ffi.Native.addressOf< |
| ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)> |
| >(_Square_delete); |
| fin.attach(this, _ptr.cast(), detach: this); |
| _activeFinalizer = fin; |
| _activeFinalizerFn = fnPtr; |
| } |
| |
| /// Detaches the finalizer so this object releases ownership of the |
| /// underlying C++ pointer. The caller becomes responsible for freeing |
| /// the memory. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| void releaseOwnership() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError('This object does not own its pointer.'); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn = null; |
| } |
| |
| /// Detaches the finalizer and invalidates this object, returning the |
| /// underlying C++ pointer. |
| /// |
| /// Throws a [StateError] if the object has already been disposed, or if |
| /// this object does not own the pointer. |
| ffi.Pointer<ffi.Void> detachPointer() { |
| final rawPtr = _ptr; |
| releaseOwnership(); |
| _ptr = ffi.nullptr; |
| return rawPtr; |
| } |
| |
| factory Square(double x, double y, double side) { |
| return Square.fromPointer(_Square_new(x, y, side), takeOwnership: true); |
| } |
| double getX() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Square_getX(_ptr); |
| } |
| |
| double area() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Square_area(_ptr); |
| } |
| |
| double getY() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| |
| return _Square_getY(_ptr); |
| } |
| |
| @override |
| void dispose() { |
| if (_ptr == ffi.nullptr) { |
| throw StateError('This object has already been disposed.'); |
| } |
| if (_activeFinalizer == null) { |
| throw StateError( |
| 'Cannot dispose a non-owning wrapper. ' |
| 'Call retainOwnership() first to take ownership.', |
| ); |
| } |
| _activeFinalizer!.detach(this); |
| _activeFinalizer = null; |
| _activeFinalizerFn?.asFunction<void Function(ffi.Pointer<ffi.Void>)>()( |
| _ptr, |
| ); |
| _activeFinalizerFn = null; |
| _ptr = ffi.nullptr; |
| } |
| } |
| |
| @ffi.Native<ffi.Pointer<ffi.Void> Function(ffi.Double, ffi.Double, ffi.Double)>( |
| symbol: 'Square_new', |
| ) |
| external ffi.Pointer<ffi.Void> _Square_new(double x, double y, double side); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Square_getX') |
| external double _Square_getX(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Square_area') |
| external double _Square_area(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Double Function(ffi.Pointer<ffi.Void>)>(symbol: 'Square_getY') |
| external double _Square_getY(ffi.Pointer<ffi.Void> self); |
| |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(symbol: 'Square_delete') |
| external void _Square_delete(ffi.Pointer<ffi.Void> self); |