-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CStyleEnum[Binding] and support [Flags] bitwise ops
- Loading branch information
1 parent
a114ac7
commit 37c6a8e
Showing
11 changed files
with
75 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// Protocol for Swift structs which represent C-style enums: | ||
/// backed by a fixed-width integer, and allowing for arbitrary values. | ||
public protocol CStyleEnum: RawRepresentable, Codable, Hashable, Sendable | ||
where RawValue: FixedWidthInteger { | ||
init(rawValue value: RawValue) | ||
} | ||
|
||
// Bitwise operators for C-style enums used as bitfields. | ||
extension CStyleEnum where Self: OptionSet { | ||
public static prefix func~(value: Self) -> Self { | ||
Self(rawValue: ~value.rawValue) | ||
} | ||
|
||
public static func|(lhs: Self, rhs: Self) -> Self { | ||
Self(rawValue: lhs.rawValue | rhs.rawValue) | ||
} | ||
|
||
public static func&(lhs: Self, rhs: Self) -> Self { | ||
Self(rawValue: lhs.rawValue & rhs.rawValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// Binding for an a type implementing CStyleEnum | ||
public protocol CStyleEnumBinding: CStyleEnum, PODBinding | ||
where ABIValue == RawValue, SwiftValue == Self { | ||
} | ||
|
||
extension CStyleEnumBinding { | ||
public static var abiDefaultValue: RawValue { RawValue.zero } | ||
public static func fromABI(_ value: RawValue) -> Self { Self(rawValue: value) } | ||
public static func toABI(_ value: Self) -> RawValue { value.rawValue } | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
Support/Sources/WindowsRuntime/BindingProtocols+extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// Protocol for Swift enums which represent WinRT enums but do not allow arbitrary values. | ||
public protocol ClosedEnum: RawRepresentable, Codable, Hashable, Sendable | ||
where RawValue: FixedWidthInteger {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import WindowsRuntime_ABI | ||
import COM | ||
|
||
public struct TrustLevel: Hashable, RawRepresentable, Sendable { | ||
/// Represents the trust level of an activatable class. | ||
public struct TrustLevel: CStyleEnum { | ||
public var rawValue: Int32 | ||
public init(rawValue: Int32 = 0) { self.rawValue = rawValue } | ||
|
||
/// The component has access to resources that are not protected. | ||
public static let base = Self(rawValue: 0) | ||
|
||
/// The component has access to resources requested in the app manifest and approved by the user. | ||
public static let partial = Self(rawValue: 1) | ||
|
||
/// The component requires the full privileges of the user. | ||
public static let full = Self(rawValue: 2) | ||
} | ||
|
||
extension TrustLevel: COM.OpenEnumBinding { | ||
} | ||
extension TrustLevel: CStyleEnumBinding {} |
2 changes: 1 addition & 1 deletion
2
.../Sources/WindowsRuntime/Projection/WindowsFoundation/WindowsFoundation_PropertyType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters