blob: 13097738d755c09c87134b198c94ef5774be9b57 [file] [log] [blame]
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
/// An implementation detail used to implement support importing
/// (Objective-)C entities marked with the swift_newtype Clang
/// attribute.
public protocol _SwiftNewtypeWrapper : RawRepresentable { }
extension _SwiftNewtypeWrapper where Self.RawValue : Hashable {
public var hashValue: Int {
return rawValue.hashValue
}
}
% for op in ['<', '>', '<=', '>=']:
public func ${op} <T: _SwiftNewtypeWrapper>(lhs: T, rhs: T) -> Bool
where T.RawValue : Comparable {
return lhs.rawValue ${op} rhs.rawValue
}
% end
#if _runtime(_ObjC)
extension _SwiftNewtypeWrapper where Self.RawValue : _ObjectiveCBridgeable {
public func _bridgeToObjectiveC() -> Self.RawValue._ObjectiveCType {
return rawValue._bridgeToObjectiveC()
}
public static func _forceBridgeFromObjectiveC(
_ source: Self.RawValue._ObjectiveCType,
result: inout Self?
) {
var innerResult: Self.RawValue?
Self.RawValue._forceBridgeFromObjectiveC(source, result: &innerResult)
result = innerResult.flatMap { Self(rawValue: $0) }
}
public static func _conditionallyBridgeFromObjectiveC(
_ source: Self.RawValue._ObjectiveCType,
result: inout Self?
) -> Bool {
var innerResult: Self.RawValue?
let success = Self.RawValue._conditionallyBridgeFromObjectiveC(
source,
result: &innerResult)
result = innerResult.flatMap { Self(rawValue: $0) }
return success
}
public static func _unconditionallyBridgeFromObjectiveC(
_ source: Self.RawValue._ObjectiveCType?
) -> Self {
return Self(
rawValue: Self.RawValue._unconditionallyBridgeFromObjectiveC(source))!
}
}
#endif