-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support IMap
and IMapView
#530
Changes from 28 commits
930d179
6521269
ca7fa45
85805c8
59a09bd
558d110
9d03586
bc5bdc4
92ccaa3
731f183
7e60bb9
320d85d
2682f68
572b87a
b6442a8
679e209
1002117
e564c6f
cd5a2be
4513225
5ec4a88
87015c1
6f4bb6e
2bef102
7b08ecb
dcefcd5
6f0251b
142a590
2e6c716
23ccda3
953ed0c
030b2bc
2e47dc2
b4f6ecc
209eda6
6ef6068
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2020, the Dart project authors. 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. | ||
|
||
// Dart representations of common enumerations used in the Windows Runtime APIs. | ||
|
||
// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY. | ||
|
||
// ignore_for_file: constant_identifier_names | ||
|
||
import '../../../winrt/foundation/winrt_enum.dart'; | ||
|
||
/// The type of step taken according to the pedometer. | ||
/// | ||
/// {@category Enum} | ||
enum PedometerStepKind implements WinRTEnum { | ||
unknown(0), | ||
walking(1), | ||
running(2); | ||
|
||
@override | ||
final int value; | ||
|
||
const PedometerStepKind(this.value); | ||
|
||
factory PedometerStepKind.from(int value) => | ||
PedometerStepKind.values.firstWhere((e) => e.value == value, | ||
orElse: () => throw ArgumentError.value( | ||
value, 'value', 'No enum value with that value')); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
// ikeyvaluepair.dart | ||
|
||
// ignore_for_file: constant_identifier_names, non_constant_identifier_names | ||
|
||
import 'dart:ffi'; | ||
|
||
import 'package:ffi/ffi.dart'; | ||
|
||
import '../../../api_ms_win_core_winrt_string_l1_1_0.dart'; | ||
import '../../../com/iinspectable.dart'; | ||
import '../../../combase.dart'; | ||
import '../../../exceptions.dart'; | ||
import '../../../guid.dart'; | ||
import '../../../macros.dart'; | ||
import '../../../types.dart'; | ||
import '../../../utils.dart'; | ||
import '../../../winrt_helpers.dart'; | ||
import '../../devices/sensors/enums.g.dart'; | ||
import '../../internal/map_helpers.dart'; | ||
import '../ipropertyvalue.dart'; | ||
|
||
/// Represents a key-value pair. | ||
/// | ||
/// This is typically used as a constraint type when you need to encapsulate | ||
/// two type parameters into one to satisfy the constraints of another generic | ||
/// interface. | ||
/// | ||
/// {@category Interface} | ||
/// {@category winrt} | ||
class IKeyValuePair<K, V> extends IInspectable { | ||
// vtable begins at 6, is 2 entries long. | ||
final V Function(Pointer<COMObject>)? _creator; | ||
final V Function(int)? _enumCreator; | ||
|
||
/// Creates an instance of [IKeyValuePair] using the given [ptr]. | ||
/// | ||
/// [K] must be of type `GUID`, `int`, `Object`, `String`, or `WinRTEnum` | ||
/// (e.g. `PedometerStepKind`). | ||
/// | ||
/// [V] must be of type `Object`, `String`, or `WinRT` (e.g. `IJsonValue`, | ||
/// `ProductLicense`). | ||
/// | ||
/// [creator] must be specified if [V] is a `WinRT` type. | ||
/// ```dart | ||
/// final keyValuePair = | ||
/// IKeyValuePair<String, IJsonValue?>.fromRawPointer(ptr, | ||
/// creator: IJsonValue.fromRawPointer); | ||
/// ``` | ||
/// | ||
/// [enumCreator] must be specified if [V] is a `WinRTEnum` type. | ||
/// ```dart | ||
/// final keyValuePair = | ||
/// IKeyValuePair<String, ChatMessageStatus?>.fromRawPointer(ptr, | ||
/// enumCreator: ChatMessageStatus.from); | ||
/// ``` | ||
IKeyValuePair.fromRawPointer( | ||
super.ptr, { | ||
V Function(Pointer<COMObject>)? creator, | ||
V Function(int)? enumCreator, | ||
}) : _creator = creator, | ||
_enumCreator = enumCreator { | ||
if (!isSupportedKeyValuePair<K, V>()) { | ||
throw ArgumentError('Unsupported key-value pair: IKeyValuePair<$K, $V>'); | ||
} | ||
|
||
if (isSubtypeOfInspectable<V>() && creator == null) { | ||
throw ArgumentError.notNull('creator'); | ||
} | ||
|
||
if (isSubtypeOfWinRTEnum<V>() && enumCreator == null) { | ||
throw ArgumentError.notNull('enumCreator'); | ||
} | ||
} | ||
|
||
/// Gets the key of the key-value pair. | ||
K get key { | ||
if (isSameType<K, GUID>()) return _key_GUID as K; | ||
if (isSameType<K, int>()) return _key_Uint32 as K; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used |
||
if (isSameType<K, PedometerStepKind>()) { | ||
return _key_PedometerStepKind as K; | ||
} | ||
if (isSameType<K, String>()) return _key_String as K; | ||
|
||
return _key_Object; | ||
} | ||
|
||
GUID get _key_GUID { | ||
final retValuePtr = calloc<GUID>(); | ||
|
||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(6) | ||
.cast< | ||
Pointer<NativeFunction<HRESULT Function(Pointer, Pointer<GUID>)>>>() | ||
.value | ||
.asFunction< | ||
int Function( | ||
Pointer, Pointer<GUID>)>()(ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return retValuePtr.ref; | ||
} | ||
|
||
int get _key_Uint32 { | ||
final retValuePtr = calloc<Uint32>(); | ||
|
||
try { | ||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(6) | ||
.cast< | ||
Pointer< | ||
NativeFunction<HRESULT Function(Pointer, Pointer<Uint32>)>>>() | ||
.value | ||
.asFunction< | ||
int Function( | ||
Pointer, Pointer<Uint32>)>()(ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return retValuePtr.value; | ||
} finally { | ||
free(retValuePtr); | ||
} | ||
} | ||
|
||
PedometerStepKind get _key_PedometerStepKind { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgive me, but this seems weird here. Why would such a specific type as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are the supported key-value pairs of According to these, there is only one enum type ( I can modify the implementation to handle these types with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the best thing is to make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've created extension methods for the
I don't think there are. |
||
final retValuePtr = calloc<Int32>(); | ||
|
||
try { | ||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(6) | ||
.cast< | ||
Pointer< | ||
NativeFunction<HRESULT Function(Pointer, Pointer<Int32>)>>>() | ||
.value | ||
.asFunction< | ||
int Function( | ||
Pointer, Pointer<Int32>)>()(ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return PedometerStepKind.from(retValuePtr.value); | ||
} finally { | ||
free(retValuePtr); | ||
} | ||
} | ||
|
||
String get _key_String { | ||
final retValuePtr = calloc<HSTRING>(); | ||
|
||
try { | ||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(6) | ||
.cast< | ||
Pointer< | ||
NativeFunction< | ||
HRESULT Function(Pointer, Pointer<HSTRING>)>>>() | ||
.value | ||
.asFunction<int Function(Pointer, Pointer<HSTRING>)>()( | ||
ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
final retValue = retValuePtr.toDartString(); | ||
return retValue; | ||
} finally { | ||
WindowsDeleteString(retValuePtr.value); | ||
free(retValuePtr); | ||
} | ||
} | ||
|
||
K get _key_Object { | ||
final retValuePtr = calloc<COMObject>(); | ||
|
||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(6) | ||
.cast< | ||
Pointer< | ||
NativeFunction< | ||
HRESULT Function(Pointer, Pointer<COMObject>)>>>() | ||
.value | ||
.asFunction<int Function(Pointer, Pointer<COMObject>)>()( | ||
ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return IPropertyValue.fromRawPointer(retValuePtr).value as K; | ||
} | ||
|
||
/// Gets the value of the key-value pair. | ||
V get value { | ||
if (isSimilarType<V, String>()) return _value_String as V; | ||
if (isSubtypeOfInspectable<V>()) return _value_COMObject; | ||
if (isSubtypeOfWinRTEnum<V>()) return _value_enum; | ||
|
||
return _value_Object as V; | ||
} | ||
|
||
V get _value_COMObject { | ||
final retValuePtr = calloc<COMObject>(); | ||
|
||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(7) | ||
.cast< | ||
Pointer< | ||
NativeFunction< | ||
HRESULT Function(Pointer, Pointer<COMObject>)>>>() | ||
.value | ||
.asFunction<int Function(Pointer, Pointer<COMObject>)>()( | ||
ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return _creator!(retValuePtr); | ||
} | ||
|
||
V get _value_enum { | ||
final retValuePtr = calloc<Int32>(); | ||
Comment on lines
+195
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used |
||
|
||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(7) | ||
.cast< | ||
Pointer< | ||
NativeFunction<HRESULT Function(Pointer, Pointer<Int32>)>>>() | ||
.value | ||
.asFunction< | ||
int Function( | ||
Pointer, Pointer<Int32>)>()(ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return _enumCreator!(retValuePtr.value); | ||
} | ||
|
||
Object? get _value_Object { | ||
final retValuePtr = calloc<COMObject>(); | ||
|
||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(7) | ||
.cast< | ||
Pointer< | ||
NativeFunction< | ||
HRESULT Function(Pointer, Pointer<COMObject>)>>>() | ||
.value | ||
.asFunction<int Function(Pointer, Pointer<COMObject>)>()( | ||
ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
return IPropertyValue.fromRawPointer(retValuePtr).value; | ||
} | ||
|
||
String? get _value_String { | ||
final retValuePtr = calloc<HSTRING>(); | ||
|
||
try { | ||
final hr = ptr.ref.lpVtbl.value | ||
.elementAt(7) | ||
.cast< | ||
Pointer< | ||
NativeFunction< | ||
HRESULT Function(Pointer, Pointer<HSTRING>)>>>() | ||
.value | ||
.asFunction<int Function(Pointer, Pointer<HSTRING>)>()( | ||
ptr.ref.lpVtbl, retValuePtr); | ||
|
||
if (FAILED(hr)) throw WindowsException(hr); | ||
|
||
if (retValuePtr.value == 0) return null; | ||
|
||
final retValue = retValuePtr.toDartString(); | ||
return retValue; | ||
} finally { | ||
WindowsDeleteString(retValuePtr.value); | ||
free(retValuePtr); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These overrides are required for
Map<GUID, XX>
types (e.g.Map<GUID, Object?>
) to work properly.