Skip to content

Commit

Permalink
fix: Gen specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Dec 20, 2024
1 parent aae21d9 commit ed364cb
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ namespace margelo::nitro::image::bridge::swift {
};
}

// pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()>
Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(void* _Nonnull swiftClosureWrapper) {
auto swiftClosure = NitroImage::Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____::fromUnsafe(swiftClosureWrapper);
return [swiftClosure = std::move(swiftClosure)]() mutable -> std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>> {
auto __result = swiftClosure.call();
return __result;
};
}

// pragma MARK: std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>
Func_void_std__shared_ptr_Promise_double__ create_Func_void_std__shared_ptr_Promise_double__(void* _Nonnull swiftClosureWrapper) {
auto swiftClosure = NitroImage::Func_void_std__shared_ptr_Promise_double__::fromUnsafe(swiftClosureWrapper);
return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr<Promise<double>>& result) mutable -> void {
swiftClosure.call(result);
};
}

// pragma MARK: std::function<std::shared_ptr<Promise<std::string>>()>
Func_std__shared_ptr_Promise_std__string__ create_Func_std__shared_ptr_Promise_std__string__(void* _Nonnull swiftClosureWrapper) {
auto swiftClosure = NitroImage::Func_std__shared_ptr_Promise_std__string__::fromUnsafe(swiftClosureWrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,24 +540,17 @@ namespace margelo::nitro::image::bridge::swift {
*/
class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper final {
public:
explicit Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()>& func): _function(func) {}
explicit Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper(std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()>&& func): _function(std::move(func)) {}
explicit Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper(std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()>&& func): _function(std::make_shared<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()>>(std::move(func))) {}
inline std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>> call() const {
auto __result = _function();
auto __result = _function->operator()();
return __result;
}
private:
std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()> _function;
std::shared_ptr<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>()>> _function;
};
inline Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(void* _Nonnull closureHolder, std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>(* _Nonnull call)(void* _Nonnull /* closureHolder */), void(* _Nonnull destroy)(void* _Nonnull)) {
std::shared_ptr<void> sharedClosureHolder(closureHolder, destroy);
return Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____([sharedClosureHolder = std::move(sharedClosureHolder), call]() -> std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>> {
auto __result = call(sharedClosureHolder.get());
return __result;
});
}
inline std::shared_ptr<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper> share_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(const Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____& value) {
return std::make_shared<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper>(value);
Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(void* _Nonnull swiftClosureWrapper);
inline Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ value) {
return Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double_____Wrapper(std::move(value));
}

// pragma MARK: std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>>
Expand All @@ -568,6 +561,9 @@ namespace margelo::nitro::image::bridge::swift {
inline std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>> create_std__shared_ptr_Promise_std__shared_ptr_Promise_double____() {
return Promise<std::shared_ptr<Promise<double>>>::create();
}
inline PromiseHolder<std::shared_ptr<Promise<double>>> wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(std::shared_ptr<Promise<std::shared_ptr<Promise<double>>>> promise) {
return PromiseHolder<std::shared_ptr<Promise<double>>>(std::move(promise));
}

// pragma MARK: std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>
/**
Expand All @@ -579,22 +575,16 @@ namespace margelo::nitro::image::bridge::swift {
*/
class Func_void_std__shared_ptr_Promise_double___Wrapper final {
public:
explicit Func_void_std__shared_ptr_Promise_double___Wrapper(const std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>& func): _function(func) {}
explicit Func_void_std__shared_ptr_Promise_double___Wrapper(std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>&& func): _function(std::move(func)) {}
explicit Func_void_std__shared_ptr_Promise_double___Wrapper(std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>&& func): _function(std::make_shared<std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>>(std::move(func))) {}
inline void call(std::shared_ptr<Promise<double>> result) const {
_function(result);
_function->operator()(result);
}
private:
std::function<void(const std::shared_ptr<Promise<double>>& /* result */)> _function;
std::shared_ptr<std::function<void(const std::shared_ptr<Promise<double>>& /* result */)>> _function;
};
inline Func_void_std__shared_ptr_Promise_double__ create_Func_void_std__shared_ptr_Promise_double__(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, std::shared_ptr<Promise<double>>), void(* _Nonnull destroy)(void* _Nonnull)) {
std::shared_ptr<void> sharedClosureHolder(closureHolder, destroy);
return Func_void_std__shared_ptr_Promise_double__([sharedClosureHolder = std::move(sharedClosureHolder), call](const std::shared_ptr<Promise<double>>& result) -> void {
call(sharedClosureHolder.get(), result);
});
}
inline std::shared_ptr<Func_void_std__shared_ptr_Promise_double___Wrapper> share_Func_void_std__shared_ptr_Promise_double__(const Func_void_std__shared_ptr_Promise_double__& value) {
return std::make_shared<Func_void_std__shared_ptr_Promise_double___Wrapper>(value);
Func_void_std__shared_ptr_Promise_double__ create_Func_void_std__shared_ptr_Promise_double__(void* _Nonnull swiftClosureWrapper);
inline Func_void_std__shared_ptr_Promise_double___Wrapper wrap_Func_void_std__shared_ptr_Promise_double__(Func_void_std__shared_ptr_Promise_double__ value) {
return Func_void_std__shared_ptr_Promise_double___Wrapper(std::move(value));
}

// pragma MARK: std::function<std::shared_ptr<Promise<std::string>>()>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
///
/// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

import NitroModules

/**
* Wraps a Swift `(() -> Promise<Promise<Double>>)` as a class.
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
*/
public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ {
public typealias bridge = margelo.nitro.image.bridge.swift

private let closure: (() -> Promise<Promise<Double>>)

public init(_ closure: @escaping (() -> Promise<Promise<Double>>)) {
self.closure = closure
}

@inline(__always)
public func call() -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_double____ {
let __result: Promise<Promise<Double>> = self.closure()
return { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_double____ in
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_Promise_double____()
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_double____(__promise)
__result
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_Promise_double__ in
let __promise = bridge.create_std__shared_ptr_Promise_double__()
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__promise)
__result
.then({ __result in __promiseHolder.resolve(__result) })
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
return __promise
}()) })
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
return __promise
}()
}

/**
* Casts this instance to a retained unsafe raw pointer.
* This acquires one additional strong reference on the object!
*/
@inline(__always)
public func toUnsafe() -> UnsafeMutableRawPointer {
return Unmanaged.passRetained(self).toOpaque()
}

/**
* Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____`.
* The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____>`.
* This removes one strong reference from the object!
*/
@inline(__always)
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____ {
return Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_double____>.fromOpaque(pointer).takeRetainedValue()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
///
/// Func_void_std__shared_ptr_Promise_double__.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

import NitroModules

/**
* Wraps a Swift `((_ value: Promise<Double>) -> Void)` as a class.
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
*/
public final class Func_void_std__shared_ptr_Promise_double__ {
public typealias bridge = margelo.nitro.image.bridge.swift

private let closure: ((_ value: Promise<Double>) -> Void)

public init(_ closure: @escaping ((_ value: Promise<Double>) -> Void)) {
self.closure = closure
}

@inline(__always)
public func call(value: bridge.std__shared_ptr_Promise_double__) -> Void {
self.closure({ () -> Promise<Double> in
let __promise = Promise<Double>()
let __resolver = { (__result: Double) in
__promise.resolve(withResult: __result)
}
let __rejecter = { (__error: Error) in
__promise.reject(withError: __error)
}
let __resolverCpp = { () -> bridge.Func_void_double in
let __closureWrapper = Func_void_double(__resolver)
return bridge.create_Func_void_double(__closureWrapper.toUnsafe())
}()
let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
}()
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(value)
__promiseHolder.addOnResolvedListenerCopy(__resolverCpp)
__promiseHolder.addOnRejectedListener(__rejecterCpp)
return __promise
}())
}

/**
* Casts this instance to a retained unsafe raw pointer.
* This acquires one additional strong reference on the object!
*/
@inline(__always)
public func toUnsafe() -> UnsafeMutableRawPointer {
return Unmanaged.passRetained(self).toOpaque()
}

/**
* Casts an unsafe pointer to a `Func_void_std__shared_ptr_Promise_double__`.
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_Promise_double__>`.
* This removes one strong reference from the object!
*/
@inline(__always)
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_Promise_double__ {
return Unmanaged<Func_void_std__shared_ptr_Promise_double__>.fromOpaque(pointer).takeRetainedValue()
}
}
Loading

0 comments on commit ed364cb

Please sign in to comment.