Repository navigation
Expand file tree
/
Copy pathSwiftSubclassCxx.swift
More file actions
248 lines (213 loc) · 13.5 KB
/
Copy pathSwiftSubclassCxx.swift
File metadata and controls
248 lines (213 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//===----------------------------------------------------------------------===//
// This source file is part of github.com/apple/SwiftUsd
//
// Copyright © 2025 Apple Inc. and the SwiftUsd project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//===----------------------------------------------------------------------===//
// This file was generated by SwiftUsd-ast-answerer. Do not edit!
public enum __OverlaySwift{}
#if canImport(SwiftUsd_PXR_ENABLE_IMAGING_SUPPORT)
// MARK: pxr.HioImage subclassing
extension __Overlay.HioImage.CxxAdapter {
public var swift: Overlay.HioImageSubclass {
Unmanaged<__OverlaySwift.HioImage.SwiftAdapter>.fromOpaque(__swiftSubclass!).takeUnretainedValue() as! Overlay.HioImageSubclass
}
}
// Conditional downcasting
extension pxr.HioImage {
public func `as`<T: Overlay.HioImageSubclass>(_ t: T.Type = T.self) -> T? {
__Overlay.HioImage.CxxAdapter.__dynamic_cast(self)?.swift as? T
}
}
// Public destructor of pxr.HioImage will be exposed to Swift
extension pxr.HioImage {
/// Deletes the argument using `delete x;` in C++.
///
/// The caller is responsible for ensuring that the argument
/// is not used after this function returns.
public static func delete(_ x: consuming pxr.HioImage) {
__Overlay.HioImage.CxxAdapter.__swiftDeleteBase(x)
}
}
public extension __OverlaySwift {
public enum HioImage {
open class SwiftAdapter {
private typealias UnmanagedSelf = Unmanaged<__OverlaySwift.HioImage.SwiftAdapter>
// Detect calling __wireToCxx more than once, which is against core invariants
private var __swiftHasWired: Bool
// Detect if we're a zombie object to avoid setting __swiftDidDeinit.pointee in deinit after __releaseSwiftSubclass_FP deallocated it
private var __swiftIsZombie: Bool
// Detect whether or not a call to Unmanaged.release() deinitialized us
// or if there's an outstanding strong pointer, making us a zombie
private var __swiftDidDeinit: UnsafeMutablePointer<Bool>
public required init() {
self.__swiftHasWired = false
self.__swiftIsZombie = false
self.__swiftDidDeinit = UnsafeMutablePointer<Bool>.allocate(capacity: 1)
self.__swiftDidDeinit.initialize(to: false)
}
// Cxx pointer
private var __cxxSubclass: __Overlay.HioImage.CxxAdapter!
public func get_cxx() -> __Overlay.HioImage.CxxAdapter? { __cxxSubclass }
// Unconditional upcasting
public func `as`(_ t: pxr.HioImage.Type) -> pxr.HioImage {
__Overlay.HioImage.CxxAdapter.__static_cast(__cxxSubclass, nil)
}
// Pointer/ref-returning method allocations
private var __returnIndirectionAllocation_GetFilename: UnsafeMutablePointer<std.string>?
private func __wireToCxx(_ __cxxSubclass: __Overlay.HioImage.CxxAdapter) {
func slf(_ raw: UnsafeMutableRawPointer?) -> Overlay.HioImageSubclass {
UnmanagedSelf.fromOpaque(raw!).takeUnretainedValue() as! Overlay.HioImageSubclass
}
if self.__swiftHasWired {
fatalError("Cannot call __wireToCxx more than once on a given instance. Don't call this from user code.")
} else {
self.__swiftHasWired = true
}
self.__cxxSubclass = __cxxSubclass
__cxxSubclass.__swiftSubclass = UnmanagedSelf.passRetained(self).toOpaque()
__cxxSubclass.__releaseSwiftSubclass_FP = {
let swiftDidDeinitPointer = slf($0).__swiftDidDeinit
let cxxSubclassPointer = slf($0).__cxxSubclass
slf($0).__cxxSubclass = nil
UnmanagedSelf.fromOpaque($0!).release()
let isZombie = !swiftDidDeinitPointer.pointee
swiftDidDeinitPointer.deallocate()
if isZombie {
slf($0).__swiftIsZombie = true
let cppInstance: UnsafeMutableRawPointer? = if let cxxSubclassPointer { Unmanaged<__Overlay.HioImage.CxxAdapter>.passUnretained(cxxSubclassPointer).toOpaque() } else { nil }
__Overlay.SwiftSubclassCxx_zombieCreated(swiftInstance: $0, cppInstance: cppInstance, typeName: "pxr.HioImage")
}
}
// Start wire virtual methods from pxr.HioImage
__cxxSubclass.__Read_FP = { slf($0).Read($1.pointee) }
__cxxSubclass.__ReadCropped_FP = { slf($0).ReadCropped($1, $2, $3, $4, $5.pointee) }
__cxxSubclass.__Write_FP = { slf($0).Write($1.pointee, $2.pointee) }
__cxxSubclass.__GetFilename_FP = {
let newValue = slf($0).GetFilename()
if slf($0).__returnIndirectionAllocation_GetFilename?.pointee != newValue {
if let p = slf($0).__returnIndirectionAllocation_GetFilename {
p.deinitialize(count: 1).deallocate()
}
slf($0).__returnIndirectionAllocation_GetFilename = UnsafeMutablePointer<std.string>.allocate(capacity: 1)
slf($0).__returnIndirectionAllocation_GetFilename!.initialize(to: newValue)
}
return slf($0).__returnIndirectionAllocation_GetFilename
}
__cxxSubclass.__GetWidth_FP = { slf($0).GetWidth() }
__cxxSubclass.__GetHeight_FP = { slf($0).GetHeight() }
__cxxSubclass.__GetFormat_FP = { slf($0).GetFormat() }
__cxxSubclass.__GetBytesPerPixel_FP = { slf($0).GetBytesPerPixel() }
__cxxSubclass.__GetNumMipLevels_FP = { slf($0).GetNumMipLevels() }
__cxxSubclass.__IsColorSpaceSRGB_FP = { slf($0).IsColorSpaceSRGB() }
__cxxSubclass.__GetMetadata_FP = { slf($0).GetMetadata($1.pointee, $2) }
__cxxSubclass.__GetSamplerMetadata_FP = { slf($0).GetSamplerMetadata($1, $2) }
__cxxSubclass.___OpenForReading_FP = { slf($0)._OpenForReading($1.pointee, $2, $3, $4, $5) }
__cxxSubclass.___OpenForWriting_FP = { slf($0)._OpenForWriting($1.pointee) }
// End wire virtual methods from pxr.HioImage
} // public func __wireToCxx
deinit {
// __releaseSwiftSubclass_FP, which is run by the C++ destructor, sets __cxxSubclass to nil.
// CxxAdapter has a strong pointer to SwiftAdapter, so SwiftAdapter.deinit running before ~CxxAdapter is a user-induced memory-safety issue
if self.__cxxSubclass != nil {
fatalError("Swift deinit running before C++ destructor ran violates invariants. Did you overrelease the Swift subclass instance?")
}
__returnIndirectionAllocation_GetFilename?.deinitialize(count: 1).deallocate()
if !self.__swiftIsZombie {
// Set the flag but don't deallocate. The releaseFP will deallocate after checking if this flag was set
self.__swiftDidDeinit.pointee = true
}
} // deinit
// Non-private constructors of pxr.HioImage will be exposed to Swift
/// Creates a new instance of this subclass using `new pxr::HioImage(...);` in C++.
///
/// The caller is responsible for deleting the instance in one of the following ways:
/// - Using `Overlay.HioImageSubclass.delete(_:)` in Swift
/// - Using `pxr.HioImage.delete(_:)` on the value returned by `self.get_cxx()`
/// - Using `delete p;` in C++ on the value returned by `self.get_cxx()`
/// - Passing the value returned by `self.get_cxx()` to something that will ensure it is eventually deleted, like `std::unique_ptr` or `std::shared_ptr`
/// Note that Swift ARC will _not_ automatically free the returned instance. Dropping the last strong reference in user code to the instance can result in memory leaks.
public static func new() -> Overlay.HioImageSubclass {
let swiftAdapter = Self.init()
if type(of: swiftAdapter) == __OverlaySwift.HioImage.SwiftAdapter.self {
fatalError("Cannot construct instance of abstract base class Overlay.HioImageSubclass")
}
guard swiftAdapter is Overlay.HioImageSubclass else {
fatalError("Subclass \(type(of: swiftAdapter)) of pxr.HioImage must inherit from Overlay.HioImageSubclass")
}
let cxxAdapter = __Overlay.HioImage.CxxAdapter.__swiftNew()
swiftAdapter.__wireToCxx(cxxAdapter)
return swiftAdapter as! Overlay.HioImageSubclass
}
// Non-private destructor of CxxAdapter will be exposed to Swift
/// Deletes an instance of this subclass using `delete p;` in C++ on the pointer
/// returned by `self.get_cxx()`.
///
/// The caller is responsible for ensuring that the pointer returned by
/// `self.get_cxx()` is not used after this function returns.
///
/// Due to the way that SwiftUsd's mechanisms for subclassing C++ types from Swift are implemented,
/// this Swift instance may become a "zombie" if there is a strong reference keeping it
/// alive after this function returns. By default, SwiftUsd will print a warning to stdout
/// when this occurs. You can change this behavior by setting the environment variable
/// `SWIFTUSD_SWIFT_SUBCLASS_CXX_ZOMBIE_CREATION_BEHAVIOR` to `ignore` to suppress the warning,
/// or `terminate` to immediately exit the program.
/// After a zombie is created, any use of it might safely terminate the program.
public static func delete(_ swiftAdapter: consuming __OverlaySwift.HioImage.SwiftAdapter) {
let cxxAdapter = swiftAdapter.__cxxSubclass
_ = consume swiftAdapter
cxxAdapter?.__swiftDeleteCxxAdapter()
}
// Start total inheritance from pxr.HioImage
// Start fields from pxr::HioImage
// End fields from pxr::HioImage
// Start methods from pxr::HioImage
public static func IsSupportedImageFile(_ filename: std.string) -> CBool {
__Overlay.HioImage.CxxAdapter.__IsSupportedImageFile_forward(filename)
}
public static func OpenForReading(_ filename: std.string, _ subimage: CInt, _ mip: CInt, _ sourceColorSpace: pxr.HioImage.SourceColorSpace, _ suppressErrors: CBool) -> pxr.HioImageSharedPtr {
__Overlay.HioImage.CxxAdapter.__OpenForReading_forward(filename, subimage, mip, sourceColorSpace, suppressErrors)
}
public static func OpenForWriting(_ filename: std.string) -> pxr.HioImageSharedPtr {
__Overlay.HioImage.CxxAdapter.__OpenForWriting_forward(filename)
}
// End methods from pxr::HioImage
// End total inheritance from pxr.HioImage
public protocol PureVirtuals {
// Start methods from pxr.HioImage
func Read(_ storage: pxr.HioImage.StorageSpec) -> CBool
func ReadCropped(_ cropTop: CInt, _ cropBottom: CInt, _ cropLeft: CInt, _ cropRight: CInt, _ storage: pxr.HioImage.StorageSpec) -> CBool
func Write(_ storage: pxr.HioImage.StorageSpec, _ metadata: pxr.VtDictionary) -> CBool
func GetFilename() -> std.string
func GetWidth() -> CInt
func GetHeight() -> CInt
func GetFormat() -> pxr.HioFormat
func GetBytesPerPixel() -> CInt
func GetNumMipLevels() -> CInt
func IsColorSpaceSRGB() -> CBool
func GetMetadata(_ key: pxr.TfToken, _ value: UnsafeMutablePointer<pxr.VtValue>?) -> CBool
func GetSamplerMetadata(_ dim: pxr.HioAddressDimension, _ param: UnsafeMutablePointer<pxr.HioAddressMode>?) -> CBool
func _OpenForReading(_ filename: std.string, _ subimage: CInt, _ mip: CInt, _ sourceColorSpace: pxr.HioImage.SourceColorSpace, _ suppressErrors: CBool) -> CBool
func _OpenForWriting(_ filename: std.string) -> CBool
// End methods from pxr.HioImage
} // public protocol PureVirtuals
}
}
}
extension Overlay {
public typealias HioImageSubclass = __OverlaySwift.HioImage.SwiftAdapter & __OverlaySwift.HioImage.SwiftAdapter.PureVirtuals
}
#endif // #if canImport(SwiftUsd_PXR_ENABLE_IMAGING_SUPPORT)