Skip to content

Commit

Permalink
feat!: wrap struct fields (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Jul 22, 2023
1 parent 9598dc5 commit a2094b3
Show file tree
Hide file tree
Showing 149 changed files with 3,034 additions and 1,476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ILearningModelDevice extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class IAppDisplayInfo extends IInspectable {
Pointer<COMObject> value)>()(
ptr.ref.lpVtbl, sizeNativeStructPtr.ref, value);

free(sizeNativeStructPtr);
sizeNativeStructPtr.free();

if (FAILED(hr)) {
free(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class IAppInstallerInfo2 extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/windows_applicationmodel/lib/src/ipackage8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class IPackage8 extends IInspectable {
Pointer<COMObject> result)>()(
ptr.ref.lpVtbl, sizeNativeStructPtr.ref, result);

free(sizeNativeStructPtr);
sizeNativeStructPtr.free();

if (FAILED(hr)) {
free(result);
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_applicationmodel/lib/src/ipackageid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class IPackageId extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand Down
19 changes: 18 additions & 1 deletion packages/windows_applicationmodel/lib/src/packageversion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: unnecessary_import, unused_import

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

Expand Down Expand Up @@ -45,10 +48,24 @@ final class PackageVersion implements WinRTStruct {
major.hashCode ^ minor.hashCode ^ build.hashCode ^ revision.hashCode;
}

/// @nodoc
extension NativePackageVersionConversion on NativePackageVersion {
/// Converts this [NativePackageVersion] into a Dart [PackageVersion].
PackageVersion toDart() {
return PackageVersion(major, minor, build, revision);
}
}

/// @nodoc
extension PointerNativePackageVersionConversion
on Pointer<NativePackageVersion> {
/// Converts this [NativePackageVersion] to a Dart [PackageVersion].
/// Frees the allocated memory for [NativePackageVersion].
void free() {
calloc.free(this);
}

/// Converts the referenced [NativePackageVersion] into a Dart
/// [PackageVersion].
PackageVersion toDart() {
final ref = this.ref;
return PackageVersion(ref.major, ref.minor, ref.build, ref.revision);
Expand Down
18 changes: 17 additions & 1 deletion packages/windows_data/lib/src/text/textsegment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: unnecessary_import, unused_import

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

Expand Down Expand Up @@ -41,9 +44,22 @@ final class TextSegment implements WinRTStruct {
int get hashCode => startPosition.hashCode ^ length.hashCode;
}

/// @nodoc
extension NativeTextSegmentConversion on NativeTextSegment {
/// Converts this [NativeTextSegment] into a Dart [TextSegment].
TextSegment toDart() {
return TextSegment(startPosition, length);
}
}

/// @nodoc
extension PointerNativeTextSegmentConversion on Pointer<NativeTextSegment> {
/// Converts this [NativeTextSegment] to a Dart [TextSegment].
/// Frees the allocated memory for [NativeTextSegment].
void free() {
calloc.free(this);
}

/// Converts the referenced [NativeTextSegment] into a Dart [TextSegment].
TextSegment toDart() {
final ref = this.ref;
return TextSegment(ref.startPosition, ref.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: unnecessary_import, unused_import

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart' hide DocumentProperties;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

Expand All @@ -16,15 +19,15 @@ final class DisplayPresentationRate implements WinRTStruct {
DisplayPresentationRate(
this.verticalSyncRate, this.verticalSyncsPerPresentation);

final NativeRational verticalSyncRate;
final Rational verticalSyncRate;
final int verticalSyncsPerPresentation;

@override
Pointer<NativeDisplayPresentationRate> toNative(
{Allocator allocator = malloc}) {
final nativeStructPtr = allocator<NativeDisplayPresentationRate>();
nativeStructPtr.ref
..verticalSyncRate = verticalSyncRate
..verticalSyncRate = verticalSyncRate.toNative(allocator: allocator).ref
..verticalSyncsPerPresentation = verticalSyncsPerPresentation;
return nativeStructPtr;
}
Expand All @@ -42,15 +45,31 @@ final class DisplayPresentationRate implements WinRTStruct {
verticalSyncRate.hashCode ^ verticalSyncsPerPresentation.hashCode;
}

/// @nodoc
extension NativeDisplayPresentationRateConversion
on NativeDisplayPresentationRate {
/// Converts this [NativeDisplayPresentationRate] into a Dart
/// [DisplayPresentationRate].
DisplayPresentationRate toDart() {
return DisplayPresentationRate(
verticalSyncRate.toDart(), verticalSyncsPerPresentation);
}
}

/// @nodoc
extension PointerNativeDisplayPresentationRateConversion
on Pointer<NativeDisplayPresentationRate> {
/// Converts this [NativeDisplayPresentationRate] to a Dart
/// Frees the allocated memory for [NativeDisplayPresentationRate].
void free() {
calloc.free(this);
}

/// Converts the referenced [NativeDisplayPresentationRate] into a Dart
/// [DisplayPresentationRate].
DisplayPresentationRate toDart() {
final ref = this.ref;
return DisplayPresentationRate(
ref.verticalSyncRate, ref.verticalSyncsPerPresentation);
ref.verticalSyncRate.toDart(), ref.verticalSyncsPerPresentation);
}

/// Creates a `List<DisplayPresentationRate>` from
Expand Down
12 changes: 6 additions & 6 deletions packages/windows_devices/lib/src/display/idisplaymonitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class IDisplayMonitor extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand Down Expand Up @@ -247,7 +247,7 @@ class IDisplayMonitor extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand Down Expand Up @@ -349,7 +349,7 @@ class IDisplayMonitor extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -373,7 +373,7 @@ class IDisplayMonitor extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -397,7 +397,7 @@ class IDisplayMonitor extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -421,7 +421,7 @@ class IDisplayMonitor extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class IDevicePicker extends IInspectable {
int Function(VTablePointer lpVtbl, NativeRect selection)>()(
ptr.ref.lpVtbl, selectionNativeStructPtr.ref);

free(selectionNativeStructPtr);
selectionNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -277,7 +277,7 @@ class IDevicePicker extends IInspectable {
int placement)>()(
ptr.ref.lpVtbl, selectionNativeStructPtr.ref, placement.value);

free(selectionNativeStructPtr);
selectionNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -302,7 +302,7 @@ class IDevicePicker extends IInspectable {
Pointer<COMObject> operation)>()(
ptr.ref.lpVtbl, selectionNativeStructPtr.ref, operation);

free(selectionNativeStructPtr);
selectionNativeStructPtr.free();

if (FAILED(hr)) {
free(operation);
Expand Down Expand Up @@ -340,7 +340,7 @@ class IDevicePicker extends IInspectable {
placement.value,
operation);

free(selectionNativeStructPtr);
selectionNativeStructPtr.free();

if (FAILED(hr)) {
free(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class IDevicePickerAppearance extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -111,7 +111,7 @@ class IDevicePickerAppearance extends IInspectable {
int Function(VTablePointer lpVtbl, NativeColor value)>()(
ptr.ref.lpVtbl, valueNativeStructPtr.ref);

free(valueNativeStructPtr);
valueNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -136,7 +136,7 @@ class IDevicePickerAppearance extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -155,7 +155,7 @@ class IDevicePickerAppearance extends IInspectable {
int Function(VTablePointer lpVtbl, NativeColor value)>()(
ptr.ref.lpVtbl, valueNativeStructPtr.ref);

free(valueNativeStructPtr);
valueNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -180,7 +180,7 @@ class IDevicePickerAppearance extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -199,7 +199,7 @@ class IDevicePickerAppearance extends IInspectable {
int Function(VTablePointer lpVtbl, NativeColor value)>()(
ptr.ref.lpVtbl, valueNativeStructPtr.ref);

free(valueNativeStructPtr);
valueNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -224,7 +224,7 @@ class IDevicePickerAppearance extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -243,7 +243,7 @@ class IDevicePickerAppearance extends IInspectable {
int Function(VTablePointer lpVtbl, NativeColor value)>()(
ptr.ref.lpVtbl, valueNativeStructPtr.ref);

free(valueNativeStructPtr);
valueNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -268,7 +268,7 @@ class IDevicePickerAppearance extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -287,7 +287,7 @@ class IDevicePickerAppearance extends IInspectable {
int Function(VTablePointer lpVtbl, NativeColor value)>()(
ptr.ref.lpVtbl, valueNativeStructPtr.ref);

free(valueNativeStructPtr);
valueNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand All @@ -312,7 +312,7 @@ class IDevicePickerAppearance extends IInspectable {

return value.toDart();
} finally {
free(value);
value.free();
}
}

Expand All @@ -331,7 +331,7 @@ class IDevicePickerAppearance extends IInspectable {
int Function(VTablePointer lpVtbl, NativeColor value)>()(
ptr.ref.lpVtbl, valueNativeStructPtr.ref);

free(valueNativeStructPtr);
valueNativeStructPtr.free();

if (FAILED(hr)) throwWindowsException(hr);
}
Expand Down
1 change: 1 addition & 0 deletions packages/windows_devices/lib/src/exports.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export 'geolocation/positionsource.dart';
export 'geolocation/positionstatus.dart';
export 'geolocation/venuedata.dart';
export 'gpio/gpiochangerecord.dart';
export 'gpio/gpiopinedge.dart';
export 'input/pointerdeviceusage.dart';
export 'pointofservice/sizeuint32.dart';
export 'power/battery.dart';
Expand Down

0 comments on commit a2094b3

Please sign in to comment.