Skip to content

Commit

Permalink
feat: support WinRTStruct type arguments in Vectors (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Jul 5, 2023
1 parent 02c5e79 commit 486f0de
Show file tree
Hide file tree
Showing 34 changed files with 13,080 additions and 1,427 deletions.
3 changes: 3 additions & 0 deletions packages/windows_devices/lib/src/exports.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export 'geolocation/positionaccuracy.dart';
export 'geolocation/positionsource.dart';
export 'geolocation/positionstatus.dart';
export 'geolocation/venuedata.dart';
export 'gpio/gpiochangerecord.dart';
export 'input/pointerdeviceusage.dart';
export 'pointofservice/sizeuint32.dart';
export 'power/battery.dart';
export 'power/batteryreport.dart';
export 'power/ibattery.dart';
Expand Down
59 changes: 59 additions & 0 deletions packages/windows_devices/lib/src/gpio/gpiochangerecord.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

/// Stores a relative timestap of a general-purpose I/O (GPIO) pin value
/// change, and whether the pin transitioned from low to high or from high
/// to low.
final class GpioChangeRecord implements WinRTStruct {
GpioChangeRecord(this.relativeTime, this.edge);

final int relativeTime;
final int edge;

@override
Pointer<NativeGpioChangeRecord> toNative({Allocator allocator = malloc}) {
final nativeStructPtr = allocator<NativeGpioChangeRecord>();
nativeStructPtr.ref
..relativeTime = relativeTime
..edge = edge;
return nativeStructPtr;
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is GpioChangeRecord &&
relativeTime == other.relativeTime &&
edge == other.edge;
}

@override
int get hashCode => relativeTime.hashCode ^ edge.hashCode;
}

/// @nodoc
extension PointerNativeGpioChangeRecordConversion
on Pointer<NativeGpioChangeRecord> {
/// Converts this [NativeGpioChangeRecord] to a Dart [GpioChangeRecord].
GpioChangeRecord toDart() {
final ref = this.ref;
return GpioChangeRecord(ref.relativeTime, ref.edge);
}

/// Creates a `List<GpioChangeRecord>` from
/// `Pointer<NativeGpioChangeRecord>`.
///
/// [length] must not be greater than the number of elements stored inside the
/// `Pointer<NativeGpioChangeRecord>`.
List<GpioChangeRecord> toList({int length = 1}) =>
[for (var i = 0; i < length; i++) elementAt(i).toDart()];
}
100 changes: 100 additions & 0 deletions packages/windows_devices/lib/src/input/pointerdeviceusage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

/// Identifies the Human Interface Device (HID) usage details for the input
/// device.
final class PointerDeviceUsage implements WinRTStruct {
PointerDeviceUsage(
this.usagePage,
this.usage,
this.minLogical,
this.maxLogical,
this.minPhysical,
this.maxPhysical,
this.unit,
this.physicalMultiplier);

final int usagePage;
final int usage;
final int minLogical;
final int maxLogical;
final int minPhysical;
final int maxPhysical;
final int unit;
final double physicalMultiplier;

@override
Pointer<NativePointerDeviceUsage> toNative({Allocator allocator = malloc}) {
final nativeStructPtr = allocator<NativePointerDeviceUsage>();
nativeStructPtr.ref
..usagePage = usagePage
..usage = usage
..minLogical = minLogical
..maxLogical = maxLogical
..minPhysical = minPhysical
..maxPhysical = maxPhysical
..unit = unit
..physicalMultiplier = physicalMultiplier;
return nativeStructPtr;
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is PointerDeviceUsage &&
usagePage == other.usagePage &&
usage == other.usage &&
minLogical == other.minLogical &&
maxLogical == other.maxLogical &&
minPhysical == other.minPhysical &&
maxPhysical == other.maxPhysical &&
unit == other.unit &&
physicalMultiplier == other.physicalMultiplier;
}

@override
int get hashCode =>
usagePage.hashCode ^
usage.hashCode ^
minLogical.hashCode ^
maxLogical.hashCode ^
minPhysical.hashCode ^
maxPhysical.hashCode ^
unit.hashCode ^
physicalMultiplier.hashCode;
}

/// @nodoc
extension PointerNativePointerDeviceUsageConversion
on Pointer<NativePointerDeviceUsage> {
/// Converts this [NativePointerDeviceUsage] to a Dart [PointerDeviceUsage].
PointerDeviceUsage toDart() {
final ref = this.ref;
return PointerDeviceUsage(
ref.usagePage,
ref.usage,
ref.minLogical,
ref.maxLogical,
ref.minPhysical,
ref.maxPhysical,
ref.unit,
ref.physicalMultiplier);
}

/// Creates a `List<PointerDeviceUsage>` from
/// `Pointer<NativePointerDeviceUsage>`.
///
/// [length] must not be greater than the number of elements stored inside the
/// `Pointer<NativePointerDeviceUsage>`.
List<PointerDeviceUsage> toList({int length = 1}) =>
[for (var i = 0; i < length; i++) elementAt(i).toDart()];
}
55 changes: 55 additions & 0 deletions packages/windows_devices/lib/src/pointofservice/sizeuint32.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

/// Defines the height and width of an object in a two-dimensional plane.
final class SizeUInt32 implements WinRTStruct {
SizeUInt32(this.width, this.height);

final int width;
final int height;

@override
Pointer<NativeSizeUInt32> toNative({Allocator allocator = malloc}) {
final nativeStructPtr = allocator<NativeSizeUInt32>();
nativeStructPtr.ref
..width = width
..height = height;
return nativeStructPtr;
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is SizeUInt32 &&
width == other.width &&
height == other.height;
}

@override
int get hashCode => width.hashCode ^ height.hashCode;
}

/// @nodoc
extension PointerNativeSizeUInt32Conversion on Pointer<NativeSizeUInt32> {
/// Converts this [NativeSizeUInt32] to a Dart [SizeUInt32].
SizeUInt32 toDart() {
final ref = this.ref;
return SizeUInt32(ref.width, ref.height);
}

/// Creates a `List<SizeUInt32>` from `Pointer<NativeSizeUInt32>`.
///
/// [length] must not be greater than the number of elements stored inside the
/// `Pointer<NativeSizeUInt32>`.
List<SizeUInt32> toList({int length = 1}) =>
[for (var i = 0; i < length; i++) elementAt(i).toDart()];
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ interface class IIterable<T> extends IInspectable {
/// Creates an instance of [IIterable] from the given [ptr].
///
/// [T] must be of type `bool`, `double`, `Guid`, `int`, `String`, `Uri?`,
/// `IInspectable?` (e.g.`StorageFile?`) or `WinRTEnum` (e.g. `DeviceClass`).
/// `IInspectable?` (e.g.`StorageFile?`), `WinRTEnum` (e.g. `DeviceClass`),
/// or `WinRTStruct` (e.g. `BasicGeoposition`).
///
/// [doubleType] must be specified if [T] is `double`.
/// ```dart
Expand Down
55 changes: 53 additions & 2 deletions packages/windows_foundation/lib/src/collections/iiterator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';
import 'package:windows_data/windows_data.dart';
import 'package:windows_devices/windows_devices.dart';
import 'package:windows_graphics/windows_graphics.dart';
import 'package:windows_media/windows_media.dart';
import 'package:windows_networking/windows_networking.dart';
import 'package:windows_services/windows_services.dart';
import 'package:windows_storage/windows_storage.dart';
import 'package:windows_ui/windows_ui.dart';

import '../../internal.dart';
import '../point.dart';
import '../rect.dart';
import '../size.dart';
import '../types.dart';

part 'iiterator_part.dart';
Expand All @@ -19,8 +30,9 @@ abstract interface class IIterator<T> extends IInspectable {

/// Creates an instance of [IIterator] from the given [ptr].
///
/// [T] must be of type `bool`, `double` `Guid`, `int`, `String`, `Uri?`,
/// `IInspectable?` (e.g.`StorageFile?`) or `WinRTEnum` (e.g. `DeviceClass`).
/// [T] must be of type `bool`, `double`, `Guid`, `int`, `String`, `Uri?`,
/// `IInspectable?` (e.g.`StorageFile?`), `WinRTEnum` (e.g. `DeviceClass`),
/// or `WinRTStruct` (e.g. `BasicGeoposition`).
///
/// [doubleType] must be specified if [T] is `double`.
/// ```dart
Expand Down Expand Up @@ -95,6 +107,45 @@ abstract interface class IIterator<T> extends IInspectable {
return _IIteratorWinRTEnum.fromPtr(ptr, enumCreator: enumCreator);
}

if (T == AccessListEntry) {
return _IIteratorAccessListEntry.fromPtr(ptr) as IIterator<T>;
}
if (T == BackgroundTransferFileRange) {
return _IIteratorBackgroundTransferFileRange.fromPtr(ptr) as IIterator<T>;
}
if (T == BasicGeoposition) {
return _IIteratorBasicGeoposition.fromPtr(ptr) as IIterator<T>;
}
if (T == Color) return _IIteratorColor.fromPtr(ptr) as IIterator<T>;
if (T == GpioChangeRecord) {
return _IIteratorGpioChangeRecord.fromPtr(ptr) as IIterator<T>;
}
if (T == MediaTimeRange) {
return _IIteratorMediaTimeRange.fromPtr(ptr) as IIterator<T>;
}
if (T == MseTimeRange) {
return _IIteratorMseTimeRange.fromPtr(ptr) as IIterator<T>;
}
if (T == NitRange) return _IIteratorNitRange.fromPtr(ptr) as IIterator<T>;
if (T == Point) return _IIteratorPoint.fromPtr(ptr) as IIterator<T>;
if (T == PointerDeviceUsage) {
return _IIteratorPointerDeviceUsage.fromPtr(ptr) as IIterator<T>;
}
if (T == Rect) return _IIteratorRect.fromPtr(ptr) as IIterator<T>;
if (T == RectInt32) return _IIteratorRectInt32.fromPtr(ptr) as IIterator<T>;
if (T == Size) return _IIteratorSize.fromPtr(ptr) as IIterator<T>;
if (T == SizeUInt32) {
return _IIteratorSizeUInt32.fromPtr(ptr) as IIterator<T>;
}
if (T == SortEntry) return _IIteratorSortEntry.fromPtr(ptr) as IIterator<T>;
if (T == StorePackageUpdateStatus) {
return _IIteratorStorePackageUpdateStatus.fromPtr(ptr) as IIterator<T>;
}
if (T == TextSegment) {
return _IIteratorTextSegment.fromPtr(ptr) as IIterator<T>;
}
if (T == WindowId) return _IIteratorWindowId.fromPtr(ptr) as IIterator<T>;

throw ArgumentError.value(T, 'T', 'Unsupported type');
}

Expand Down

0 comments on commit 486f0de

Please sign in to comment.