Skip to content

Commit

Permalink
Renamed auto-implement bool properties to "ImplementIXxx".
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Mar 21, 2024
1 parent d276902 commit 70c84e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Support/Sources/COM/COMExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ open class COMExportBase: IUnknownProtocol {

/// Base for classes exported to COM.
open class COMExport<Projection: COMTwoWayProjection>: COMExportBase {
open class var agile: Bool { true }
open class var implementIAgileObject: Bool { true }

open var implementation: Projection.SwiftObject { self as! Projection.SwiftObject }
public var comPointer: Projection.COMPointer {
Expand All @@ -78,7 +78,7 @@ open class COMExport<Projection: COMTwoWayProjection>: COMExportBase {
open override func _queryInterface(_ id: COMInterfaceID) throws -> IUnknownReference {
switch id {
case Projection.interfaceID: return .init(addingRef: unknownPointer)
case IAgileObjectProjection.interfaceID where Self.agile: return .init(addingRef: unknownPointer)
case IAgileObjectProjection.interfaceID where Self.implementIAgileObject: return .init(addingRef: unknownPointer)
default: return try super._queryInterface(id)
}
}
Expand Down
14 changes: 7 additions & 7 deletions Support/Sources/WindowsRuntime/WinRTExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ open class WinRTExport<Projection: WinRTTwoWayProjection>
: COMExport<Projection>, IInspectableProtocol {
open class var _runtimeClassName: String { String(describing: Self.self) }
open class var _trustLevel: TrustLevel { .base }
open class var autoStringable: Bool { true }
open class var weakReferenceSource: Bool { true }
open class var implementIStringable: Bool { true }
open class var implementIWeakReferenceSource: Bool { true }

public var inspectablePointer: IInspectableProjection.COMPointer {
unknownPointer.withMemoryRebound(to: IInspectableProjection.COMInterface.self, capacity: 1) { $0 }
Expand All @@ -16,12 +16,12 @@ open class WinRTExport<Projection: WinRTTwoWayProjection>
switch id {
// QI for IInspectable should return the identity interface just like IUnknown.
case IInspectableProjection.interfaceID: return .init(addingRef: unknownPointer)
case IWeakReferenceSourceProjection.interfaceID where Self.weakReferenceSource:
case IWeakReferenceSourceProjection.interfaceID where Self.implementIWeakReferenceSource:
let export = createSecondaryExport(
projection: IWeakReferenceSourceProjection.self,
implementation: WeakReferenceSource(target: self))
return .init(addingRef: export.unknownPointer)
case IStringableProjection.interfaceID where Self.autoStringable:
case IStringableProjection.interfaceID where Self.implementIStringable:
if let customStringConvertible = self as? any CustomStringConvertible {
let export = createSecondaryExport(
projection: IStringableProjection.self,
Expand All @@ -42,9 +42,9 @@ open class WinRTExport<Projection: WinRTTwoWayProjection>

open func getIids() throws -> [COMInterfaceID] {
var iids = Self.implements.map { $0.id }
if Self.agile { iids.append(IAgileObjectProjection.interfaceID) }
if Self.weakReferenceSource { iids.append(IWeakReferenceSourceProjection.interfaceID) }
if Self.autoStringable, self is CustomStringConvertible { iids.append(IStringableProjection.interfaceID) }
if Self.implementIAgileObject { iids.append(IAgileObjectProjection.interfaceID) }
if Self.implementIWeakReferenceSource { iids.append(IWeakReferenceSourceProjection.interfaceID) }
if Self.implementIStringable, self is CustomStringConvertible { iids.append(IStringableProjection.interfaceID) }
return iids
}

Expand Down
14 changes: 7 additions & 7 deletions Support/Tests/WinRTExportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ internal final class WinRTExportTests: XCTestCase {

func testIAgileObject() throws {
final class AgileObject: WinRTExport<IInspectableProjection> {
override class var agile: Bool { true }
override class var implementIAgileObject: Bool { true }
}

final class NonAgileObject: WinRTExport<IInspectableProjection> {
override class var agile: Bool { false }
override class var implementIAgileObject: Bool { false }
}

let _ = try AgileObject().queryInterface(IAgileObjectProjection.self)
Expand All @@ -62,17 +62,17 @@ internal final class WinRTExportTests: XCTestCase {

func testIWeakReferenceSource() throws {
final class WeakReferenceSource: WinRTExport<IInspectableProjection> {
override class var weakReferenceSource: Bool { true }
override class var implementIWeakReferenceSource: Bool { true }
}

final class NonWeakReferenceSource: WinRTExport<IInspectableProjection> {
override class var weakReferenceSource: Bool { false }
override class var implementIWeakReferenceSource: Bool { false }
}

var weakReferenceSource: WeakReferenceSource? = WeakReferenceSource()
let weakReference: IWeakReference = try weakReferenceSource!.queryInterface(IWeakReferenceSourceProjection.self).getWeakReference()
var implementIWeakReferenceSource: WeakReferenceSource? = WeakReferenceSource()
let weakReference: IWeakReference = try implementIWeakReferenceSource!.queryInterface(IWeakReferenceSourceProjection.self).getWeakReference()
XCTAssertNotNil(try weakReference.resolve())
weakReferenceSource = nil
implementIWeakReferenceSource = nil
XCTAssertNil(try weakReference.resolve())

XCTAssertThrowsError(try NonWeakReferenceSource().queryInterface(IWeakReferenceSourceProjection.self))
Expand Down

0 comments on commit 70c84e8

Please sign in to comment.