Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
perunt committed Dec 19, 2024
1 parent 6a70a0b commit 15978bb
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 132 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ PODS:
- nanopb/encode (= 2.30908.0)
- nanopb/decode (2.30908.0)
- nanopb/encode (2.30908.0)
- NitroModules (0.18.1):
- NitroModules (0.18.2):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -3251,7 +3251,7 @@ SPEC CHECKSUMS:
MapboxMaps: e76b14f52c54c40b76ddecd04f40448e6f35a864
MapboxMobileEvents: de50b3a4de180dd129c326e09cd12c8adaaa46d6
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
NitroModules: ebe2ba2d01dc03c1f82441561fe6062b8c3c4366
NitroModules: 2f68aaf756386d1c998900de71aef4e50b37c71b
Onfido: f3af62ea1c9a419589c133e3e511e5d2c4f3f8af
onfido-react-native-sdk: 4ccfdeb10f9ccb4a5799d2555cdbc2a068a42c0d
Plaid: c32f22ffce5ec67c9e6147eaf6c4d7d5f8086d89
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
// Include C++ implementation defined types
#include "ContactsModule-Swift-Cxx-Umbrella.hpp"
#include "HybridContactsModuleSpecSwift.hpp"
#include <NitroModules/HybridContext.hpp>

namespace margelo::nitro::contacts::bridge::swift {

// pragma MARK: std::shared_ptr<margelo::nitro::contacts::HybridContactsModuleSpec>
std::shared_ptr<margelo::nitro::contacts::HybridContactsModuleSpec> create_std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_(void* _Nonnull swiftUnsafePointer) {
ContactsModule::HybridContactsModuleSpecCxx swiftPart = ContactsModule::HybridContactsModuleSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer);
return HybridContext::getOrCreate<margelo::nitro::contacts::HybridContactsModuleSpecSwift>(swiftPart);
ContactsModule::HybridContactsModuleSpec_cxx swiftPart = ContactsModule::HybridContactsModuleSpec_cxx::fromUnsafe(swiftUnsafePointer);
return std::make_shared<margelo::nitro::contacts::HybridContactsModuleSpecSwift>(swiftPart);
}
void* _Nonnull get_std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_(std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ cppType) {
std::shared_ptr<margelo::nitro::contacts::HybridContactsModuleSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::contacts::HybridContactsModuleSpecSwift>(cppType);
Expand All @@ -26,8 +25,8 @@ namespace margelo::nitro::contacts::bridge::swift {
throw std::runtime_error("Class \"HybridContactsModuleSpec\" is not implemented in Swift!");
}
#endif
ContactsModule::HybridContactsModuleSpecCxx swiftPart = swiftWrapper->getSwiftPart();
return ContactsModule::HybridContactsModuleSpecCxxUnsafe::toUnsafe(swiftPart);
ContactsModule::HybridContactsModuleSpec_cxx swiftPart = swiftWrapper->getSwiftPart();
return swiftPart.toUnsafe();
}

} // namespace margelo::nitro::contacts::bridge::swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ namespace margelo::nitro::contacts { class HybridContactsModuleSpec; }
namespace margelo::nitro::contacts { struct StringHolder; }

// Forward declarations of Swift defined types
// Forward declaration of `HybridContactsModuleSpecCxx` to properly resolve imports.
namespace ContactsModule { class HybridContactsModuleSpecCxx; }
// Forward declaration of `HybridContactsModuleSpec_cxx` to properly resolve imports.
namespace ContactsModule { class HybridContactsModuleSpec_cxx; }

// Include C++ defined types
#include "Contact.hpp"
#include "ContactFields.hpp"
#include "HybridContactsModuleSpec.hpp"
#include "StringHolder.hpp"
#include <NitroModules/Promise.hpp>
#include <NitroModules/Result.hpp>
#include <exception>
#include <functional>
#include <memory>
Expand Down Expand Up @@ -163,5 +164,18 @@ namespace margelo::nitro::contacts::bridge::swift {
using std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ = std::shared_ptr<margelo::nitro::contacts::HybridContactsModuleSpec>;
std::shared_ptr<margelo::nitro::contacts::HybridContactsModuleSpec> create_std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_(void* _Nonnull swiftUnsafePointer);
void* _Nonnull get_std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_(std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ cppType);

// pragma MARK: std::weak_ptr<margelo::nitro::contacts::HybridContactsModuleSpec>
using std__weak_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ = std::weak_ptr<margelo::nitro::contacts::HybridContactsModuleSpec>;
inline std__weak_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ weakify_std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_(const std::shared_ptr<margelo::nitro::contacts::HybridContactsModuleSpec>& strong) { return strong; }

// pragma MARK: Result<std::shared_ptr<Promise<std::vector<Contact>>>>
using Result_std__shared_ptr_Promise_std__vector_Contact____ = Result<std::shared_ptr<Promise<std::vector<Contact>>>>;
inline Result_std__shared_ptr_Promise_std__vector_Contact____ create_Result_std__shared_ptr_Promise_std__vector_Contact____(const std::shared_ptr<Promise<std::vector<Contact>>>& value) {
return Result<std::shared_ptr<Promise<std::vector<Contact>>>>::withValue(value);
}
inline Result_std__shared_ptr_Promise_std__vector_Contact____ create_Result_std__shared_ptr_Promise_std__vector_Contact____(const std::exception_ptr& error) {
return Result<std::shared_ptr<Promise<std::vector<Contact>>>>::withError(error);
}

} // namespace margelo::nitro::contacts::bridge::swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace margelo::nitro::contacts { struct StringHolder; }
#include "HybridContactsModuleSpec.hpp"
#include "StringHolder.hpp"
#include <NitroModules/Promise.hpp>
#include <NitroModules/Result.hpp>
#include <exception>
#include <memory>
#include <optional>
#include <string>
Expand All @@ -38,8 +40,8 @@ namespace margelo::nitro::contacts { struct StringHolder; }
#include <NitroModules/RuntimeError.hpp>

// Forward declarations of Swift defined types
// Forward declaration of `HybridContactsModuleSpecCxx` to properly resolve imports.
namespace ContactsModule { class HybridContactsModuleSpecCxx; }
// Forward declaration of `HybridContactsModuleSpec_cxx` to properly resolve imports.
namespace ContactsModule { class HybridContactsModuleSpec_cxx; }

// Include Swift defined types
#if __has_include("ContactsModule-Swift.h")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ public final class ContactsModuleAutolinking {

/**
* Creates an instance of a Swift class that implements `HybridContactsModuleSpec`,
* and wraps it in a Swift class that can directly interop with C++ (`HybridContactsModuleSpecCxx`)
* and wraps it in a Swift class that can directly interop with C++ (`HybridContactsModuleSpec_cxx`)
*
* This is generated by Nitrogen and will initialize the class specified
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridContactsModule`).
*/
public static func createContactsModule() -> bridge.std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ {
let hybridObject = HybridContactsModule()
return { () -> bridge.std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_ in
let __cxxWrapped = HybridContactsModuleSpecCxx(hybridObject)
let __pointer = HybridContactsModuleSpecCxxUnsafe.toUnsafe(__cxxWrapped)
return bridge.create_std__shared_ptr_margelo__nitro__contacts__HybridContactsModuleSpec_(__pointer)
let __cxxWrapped = hybridObject.getCxxWrapper()
return __cxxWrapped.getCxxPart()
}()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include "HybridContactsModuleSpec.hpp"

// Forward declaration of `HybridContactsModuleSpecCxx` to properly resolve imports.
namespace ContactsModule { class HybridContactsModuleSpecCxx; }
// Forward declaration of `HybridContactsModuleSpec_cxx` to properly resolve imports.
namespace ContactsModule { class HybridContactsModuleSpec_cxx; }

// Forward declaration of `Contact` to properly resolve imports.
namespace margelo::nitro::contacts { struct Contact; }
Expand All @@ -27,36 +27,30 @@ namespace margelo::nitro::contacts { enum class ContactFields; }
#include "StringHolder.hpp"
#include "ContactFields.hpp"

#if __has_include(<NitroModules/HybridContext.hpp>)
#include <NitroModules/HybridContext.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif

#include "ContactsModule-Swift-Cxx-Umbrella.hpp"

namespace margelo::nitro::contacts {

/**
* The C++ part of HybridContactsModuleSpecCxx.swift.
* The C++ part of HybridContactsModuleSpec_cxx.swift.
*
* HybridContactsModuleSpecSwift (C++) accesses HybridContactsModuleSpecCxx (Swift), and might
* HybridContactsModuleSpecSwift (C++) accesses HybridContactsModuleSpec_cxx (Swift), and might
* contain some additional bridging code for C++ <> Swift interop.
*
* Since this obviously introduces an overhead, I hope at some point in
* the future, HybridContactsModuleSpecCxx can directly inherit from the C++ class HybridContactsModuleSpec
* the future, HybridContactsModuleSpec_cxx can directly inherit from the C++ class HybridContactsModuleSpec
* to simplify the whole structure and memory management.
*/
class HybridContactsModuleSpecSwift: public virtual HybridContactsModuleSpec {
public:
// Constructor from a Swift instance
explicit HybridContactsModuleSpecSwift(const ContactsModule::HybridContactsModuleSpecCxx& swiftPart):
explicit HybridContactsModuleSpecSwift(const ContactsModule::HybridContactsModuleSpec_cxx& swiftPart):
HybridObject(HybridContactsModuleSpec::TAG),
_swiftPart(swiftPart) { }

public:
// Get the Swift part
inline ContactsModule::HybridContactsModuleSpecCxx getSwiftPart() noexcept { return _swiftPart; }
inline ContactsModule::HybridContactsModuleSpec_cxx getSwiftPart() noexcept { return _swiftPart; }

public:
// Get memory pressure
Expand All @@ -72,11 +66,15 @@ namespace margelo::nitro::contacts {
// Methods
inline std::shared_ptr<Promise<std::vector<Contact>>> getAll(const std::vector<ContactFields>& keys) override {
auto __result = _swiftPart.getAll(keys);
return __result;
if (__result.hasError()) [[unlikely]] {
std::rethrow_exception(__result.error());
}
auto __value = std::move(__result.value());
return __value;
}

private:
ContactsModule::HybridContactsModuleSpecCxx _swiftPart;
ContactsModule::HybridContactsModuleSpec_cxx _swiftPart;
};

} // namespace margelo::nitro::contacts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,42 @@
import Foundation
import NitroModules

/**
* A Swift protocol representing the ContactsModule HybridObject.
* Implement this protocol to create Swift-based instances of ContactsModule.
*
* When implementing this protocol, make sure to initialize `hybridContext` - example:
* ```
* public class HybridContactsModule : HybridContactsModuleSpec {
* // Initialize HybridContext
* var hybridContext = margelo.nitro.HybridContext()
*
* // Return size of the instance to inform JS GC about memory pressure
* var memorySize: Int {
* return getSizeOf(self)
* }
*
* // ...
* }
* ```
*/
public protocol HybridContactsModuleSpec: AnyObject, HybridObjectSpec {
/// See ``HybridContactsModuleSpec``
public protocol HybridContactsModuleSpec_protocol: AnyObject {
// Properties


// Methods
func getAll(keys: [ContactFields]) throws -> Promise<[Contact]>
}

/// See ``HybridContactsModuleSpec``
public class HybridContactsModuleSpec_base: HybridObjectSpec {
private weak var cxxWrapper: HybridContactsModuleSpec_cxx? = nil
public func getCxxWrapper() -> HybridContactsModuleSpec_cxx {
#if DEBUG
guard self is HybridContactsModuleSpec else {
fatalError("`self` is not a `HybridContactsModuleSpec`! Did you accidentally inherit from `HybridContactsModuleSpec_base` instead of `HybridContactsModuleSpec`?")
}
#endif
if let cxxWrapper = self.cxxWrapper {
return cxxWrapper
} else {
let cxxWrapper = HybridContactsModuleSpec_cxx(self as! HybridContactsModuleSpec)
self.cxxWrapper = cxxWrapper
return cxxWrapper
}
}
public var memorySize: Int { return 0 }
}

/**
* A Swift base-protocol representing the ContactsModule HybridObject.
* Implement this protocol to create Swift-based instances of ContactsModule.
* ```swift
* class HybridContactsModule : HybridContactsModuleSpec {
* // ...
* }
* ```
*/
public typealias HybridContactsModuleSpec = HybridContactsModuleSpec_protocol & HybridContactsModuleSpec_base
Loading

0 comments on commit 15978bb

Please sign in to comment.