@nitro-mlkit/object-detection 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/NitroMLKitObjects.podspec +34 -0
  3. package/README.md +57 -0
  4. package/android/CMakeLists.txt +12 -0
  5. package/android/build.gradle +77 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  8. package/android/src/main/kotlin/com/margelo/nitro/nitromlkit/objects/HybridObjectDetector.kt +102 -0
  9. package/android/src/main/kotlin/com/nitromlkit/objects/NitroMLKitObjectsPackage.kt +19 -0
  10. package/expo-module.config.json +9 -0
  11. package/ios/HybridObjectDetector.swift +125 -0
  12. package/nitro.json +16 -0
  13. package/nitrogen/generated/.gitattributes +1 -0
  14. package/nitrogen/generated/android/NitroMLKitObjects+autolinking.cmake +81 -0
  15. package/nitrogen/generated/android/NitroMLKitObjects+autolinking.gradle +27 -0
  16. package/nitrogen/generated/android/NitroMLKitObjectsOnLoad.cpp +54 -0
  17. package/nitrogen/generated/android/NitroMLKitObjectsOnLoad.hpp +34 -0
  18. package/nitrogen/generated/android/c++/JBatchObjectResult.hpp +95 -0
  19. package/nitrogen/generated/android/c++/JDetectedObject.hpp +88 -0
  20. package/nitrogen/generated/android/c++/JHybridObjectDetectorSpec.cpp +131 -0
  21. package/nitrogen/generated/android/c++/JHybridObjectDetectorSpec.hpp +65 -0
  22. package/nitrogen/generated/android/c++/JObjectLabel.hpp +65 -0
  23. package/nitrogen/generated/android/c++/JObjectRect.hpp +69 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/BatchObjectResult.kt +66 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/DetectedObject.kt +61 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/HybridObjectDetectorSpec.kt +63 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/NitroMLKitObjectsOnLoad.kt +35 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/ObjectLabel.kt +61 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/ObjectRect.kt +66 -0
  30. package/nitrogen/generated/ios/NitroMLKitObjects+autolinking.rb +62 -0
  31. package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Bridge.cpp +57 -0
  32. package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Bridge.hpp +236 -0
  33. package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Umbrella.hpp +59 -0
  34. package/nitrogen/generated/ios/NitroMLKitObjectsAutolinking.mm +33 -0
  35. package/nitrogen/generated/ios/NitroMLKitObjectsAutolinking.swift +26 -0
  36. package/nitrogen/generated/ios/c++/HybridObjectDetectorSpecSwift.cpp +11 -0
  37. package/nitrogen/generated/ios/c++/HybridObjectDetectorSpecSwift.hpp +112 -0
  38. package/nitrogen/generated/ios/swift/BatchObjectResult.swift +63 -0
  39. package/nitrogen/generated/ios/swift/DetectedObject.swift +45 -0
  40. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  41. package/nitrogen/generated/ios/swift/Func_void_std__vector_BatchObjectResult_.swift +46 -0
  42. package/nitrogen/generated/ios/swift/Func_void_std__vector_DetectedObject_.swift +46 -0
  43. package/nitrogen/generated/ios/swift/HybridObjectDetectorSpec.swift +57 -0
  44. package/nitrogen/generated/ios/swift/HybridObjectDetectorSpec_cxx.swift +188 -0
  45. package/nitrogen/generated/ios/swift/ObjectLabel.swift +39 -0
  46. package/nitrogen/generated/ios/swift/ObjectRect.swift +44 -0
  47. package/nitrogen/generated/shared/c++/BatchObjectResult.hpp +99 -0
  48. package/nitrogen/generated/shared/c++/DetectedObject.hpp +96 -0
  49. package/nitrogen/generated/shared/c++/HybridObjectDetectorSpec.cpp +23 -0
  50. package/nitrogen/generated/shared/c++/HybridObjectDetectorSpec.hpp +71 -0
  51. package/nitrogen/generated/shared/c++/ObjectLabel.hpp +91 -0
  52. package/nitrogen/generated/shared/c++/ObjectRect.hpp +95 -0
  53. package/package.json +53 -0
  54. package/src/index.ts +20 -0
  55. package/src/specs/ObjectDetector.nitro.ts +54 -0
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// NitroMLKitObjectsAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ // TODO: Use empty enums once Swift supports exporting them as namespaces
11
+ // See: https://github.com/swiftlang/swift/pull/83616
12
+ public final class NitroMLKitObjectsAutolinking {
13
+ public typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
14
+
15
+ public static func createObjectDetector() -> bridge.std__shared_ptr_HybridObjectDetectorSpec_ {
16
+ let hybridObject = HybridObjectDetector()
17
+ return { () -> bridge.std__shared_ptr_HybridObjectDetectorSpec_ in
18
+ let __cxxWrapped = hybridObject.getCxxWrapper()
19
+ return __cxxWrapped.getCxxPart()
20
+ }()
21
+ }
22
+
23
+ public static func isObjectDetectorRecyclable() -> Bool {
24
+ return HybridObjectDetector.self is any RecyclableView.Type
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridObjectDetectorSpecSwift.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridObjectDetectorSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::mlkit::objects {
11
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,112 @@
1
+ ///
2
+ /// HybridObjectDetectorSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridObjectDetectorSpec.hpp"
11
+
12
+ // Forward declaration of `HybridObjectDetectorSpec_cxx` to properly resolve imports.
13
+ namespace NitroMLKitObjects { class HybridObjectDetectorSpec_cxx; }
14
+
15
+ // Forward declaration of `DetectedObject` to properly resolve imports.
16
+ namespace margelo::nitro::mlkit::objects { struct DetectedObject; }
17
+ // Forward declaration of `ObjectRect` to properly resolve imports.
18
+ namespace margelo::nitro::mlkit::objects { struct ObjectRect; }
19
+ // Forward declaration of `ObjectLabel` to properly resolve imports.
20
+ namespace margelo::nitro::mlkit::objects { struct ObjectLabel; }
21
+ // Forward declaration of `BatchObjectResult` to properly resolve imports.
22
+ namespace margelo::nitro::mlkit::objects { struct BatchObjectResult; }
23
+
24
+ #include "DetectedObject.hpp"
25
+ #include <vector>
26
+ #include <NitroModules/Promise.hpp>
27
+ #include "ObjectRect.hpp"
28
+ #include "ObjectLabel.hpp"
29
+ #include <string>
30
+ #include "BatchObjectResult.hpp"
31
+ #include <optional>
32
+
33
+ #include "NitroMLKitObjects-Swift-Cxx-Umbrella.hpp"
34
+
35
+ namespace margelo::nitro::mlkit::objects {
36
+
37
+ /**
38
+ * The C++ part of HybridObjectDetectorSpec_cxx.swift.
39
+ *
40
+ * HybridObjectDetectorSpecSwift (C++) accesses HybridObjectDetectorSpec_cxx (Swift), and might
41
+ * contain some additional bridging code for C++ <> Swift interop.
42
+ *
43
+ * Since this obviously introduces an overhead, I hope at some point in
44
+ * the future, HybridObjectDetectorSpec_cxx can directly inherit from the C++ class HybridObjectDetectorSpec
45
+ * to simplify the whole structure and memory management.
46
+ */
47
+ class HybridObjectDetectorSpecSwift: public virtual HybridObjectDetectorSpec {
48
+ public:
49
+ // Constructor from a Swift instance
50
+ explicit HybridObjectDetectorSpecSwift(const NitroMLKitObjects::HybridObjectDetectorSpec_cxx& swiftPart):
51
+ HybridObject(HybridObjectDetectorSpec::TAG),
52
+ _swiftPart(swiftPart) { }
53
+
54
+ public:
55
+ // Get the Swift part
56
+ inline NitroMLKitObjects::HybridObjectDetectorSpec_cxx& getSwiftPart() noexcept {
57
+ return _swiftPart;
58
+ }
59
+
60
+ public:
61
+ inline size_t getExternalMemorySize() noexcept override {
62
+ return _swiftPart.getMemorySize();
63
+ }
64
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
65
+ if (auto otherCast = std::dynamic_pointer_cast<HybridObjectDetectorSpecSwift>(other)) {
66
+ return _swiftPart.equals(otherCast->_swiftPart);
67
+ }
68
+ return false;
69
+ }
70
+ void dispose() noexcept override {
71
+ _swiftPart.dispose();
72
+ }
73
+ std::string toString() override {
74
+ return _swiftPart.toString();
75
+ }
76
+
77
+ public:
78
+ // Properties
79
+
80
+
81
+ public:
82
+ // Methods
83
+ inline std::shared_ptr<Promise<std::vector<DetectedObject>>> detect(const std::string& imageUri) override {
84
+ auto __result = _swiftPart.detect(imageUri);
85
+ if (__result.hasError()) [[unlikely]] {
86
+ std::rethrow_exception(__result.error());
87
+ }
88
+ auto __value = std::move(__result.value());
89
+ return __value;
90
+ }
91
+ inline std::shared_ptr<Promise<std::vector<BatchObjectResult>>> detectBatch(const std::vector<std::string>& imageUris, double concurrency) override {
92
+ auto __result = _swiftPart.detectBatch(imageUris, std::forward<decltype(concurrency)>(concurrency));
93
+ if (__result.hasError()) [[unlikely]] {
94
+ std::rethrow_exception(__result.error());
95
+ }
96
+ auto __value = std::move(__result.value());
97
+ return __value;
98
+ }
99
+ inline bool isAvailable() override {
100
+ auto __result = _swiftPart.isAvailable();
101
+ if (__result.hasError()) [[unlikely]] {
102
+ std::rethrow_exception(__result.error());
103
+ }
104
+ auto __value = std::move(__result.value());
105
+ return __value;
106
+ }
107
+
108
+ private:
109
+ NitroMLKitObjects::HybridObjectDetectorSpec_cxx _swiftPart;
110
+ };
111
+
112
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,63 @@
1
+ ///
2
+ /// BatchObjectResult.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `BatchObjectResult`, backed by a C++ struct.
12
+ */
13
+ public typealias BatchObjectResult = margelo.nitro.mlkit.objects.BatchObjectResult
14
+
15
+ public extension BatchObjectResult {
16
+ private typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `BatchObjectResult`.
20
+ */
21
+ init(index: Double, objects: [DetectedObject], success: Bool, error: String?) {
22
+ self.init(index, { () -> bridge.std__vector_DetectedObject_ in
23
+ var __vector = bridge.create_std__vector_DetectedObject_(objects.count)
24
+ for __item in objects {
25
+ __vector.push_back(__item)
26
+ }
27
+ return __vector
28
+ }(), success, { () -> bridge.std__optional_std__string_ in
29
+ if let __unwrappedValue = error {
30
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
31
+ } else {
32
+ return .init()
33
+ }
34
+ }())
35
+ }
36
+
37
+ @inline(__always)
38
+ var index: Double {
39
+ return self.__index
40
+ }
41
+
42
+ @inline(__always)
43
+ var objects: [DetectedObject] {
44
+ return self.__objects.map({ __item in __item })
45
+ }
46
+
47
+ @inline(__always)
48
+ var success: Bool {
49
+ return self.__success
50
+ }
51
+
52
+ @inline(__always)
53
+ var error: String? {
54
+ return { () -> String? in
55
+ if bridge.has_value_std__optional_std__string_(self.__error) {
56
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__error)
57
+ return String(__unwrapped)
58
+ } else {
59
+ return nil
60
+ }
61
+ }()
62
+ }
63
+ }
@@ -0,0 +1,45 @@
1
+ ///
2
+ /// DetectedObject.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `DetectedObject`, backed by a C++ struct.
12
+ */
13
+ public typealias DetectedObject = margelo.nitro.mlkit.objects.DetectedObject
14
+
15
+ public extension DetectedObject {
16
+ private typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `DetectedObject`.
20
+ */
21
+ init(bounds: ObjectRect, trackingId: Double, labels: [ObjectLabel]) {
22
+ self.init(bounds, trackingId, { () -> bridge.std__vector_ObjectLabel_ in
23
+ var __vector = bridge.create_std__vector_ObjectLabel_(labels.count)
24
+ for __item in labels {
25
+ __vector.push_back(__item)
26
+ }
27
+ return __vector
28
+ }())
29
+ }
30
+
31
+ @inline(__always)
32
+ var bounds: ObjectRect {
33
+ return self.__bounds
34
+ }
35
+
36
+ @inline(__always)
37
+ var trackingId: Double {
38
+ return self.__trackingId
39
+ }
40
+
41
+ @inline(__always)
42
+ var labels: [ObjectLabel] {
43
+ return self.__labels.map({ __item in __item })
44
+ }
45
+ }
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_std__exception_ptr.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ error: Error) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_std__exception_ptr {
15
+ public typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
16
+
17
+ private let closure: (_ error: Error) -> Void
18
+
19
+ public init(_ closure: @escaping (_ error: Error) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(error: std.exception_ptr) -> Void {
25
+ self.closure(RuntimeError.from(cppError: error))
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
44
+ return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_std__vector_BatchObjectResult_.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ value: [BatchObjectResult]) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_std__vector_BatchObjectResult_ {
15
+ public typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
16
+
17
+ private let closure: (_ value: [BatchObjectResult]) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: [BatchObjectResult]) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: bridge.std__vector_BatchObjectResult_) -> Void {
25
+ self.closure(value.map({ __item in __item }))
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_std__vector_BatchObjectResult_`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__vector_BatchObjectResult_>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_BatchObjectResult_ {
44
+ return Unmanaged<Func_void_std__vector_BatchObjectResult_>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_std__vector_DetectedObject_.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ value: [DetectedObject]) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_std__vector_DetectedObject_ {
15
+ public typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
16
+
17
+ private let closure: (_ value: [DetectedObject]) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: [DetectedObject]) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: bridge.std__vector_DetectedObject_) -> Void {
25
+ self.closure(value.map({ __item in __item }))
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_std__vector_DetectedObject_`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__vector_DetectedObject_>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_DetectedObject_ {
44
+ return Unmanaged<Func_void_std__vector_DetectedObject_>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -0,0 +1,57 @@
1
+ ///
2
+ /// HybridObjectDetectorSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /// See ``HybridObjectDetectorSpec``
11
+ public protocol HybridObjectDetectorSpec_protocol: HybridObject {
12
+ // Properties
13
+
14
+
15
+ // Methods
16
+ func detect(imageUri: String) throws -> Promise<[DetectedObject]>
17
+ func detectBatch(imageUris: [String], concurrency: Double) throws -> Promise<[BatchObjectResult]>
18
+ func isAvailable() throws -> Bool
19
+ }
20
+
21
+ public extension HybridObjectDetectorSpec_protocol {
22
+ /// Default implementation of ``HybridObject.toString``
23
+ func toString() -> String {
24
+ return "[HybridObject ObjectDetector]"
25
+ }
26
+ }
27
+
28
+ /// See ``HybridObjectDetectorSpec``
29
+ open class HybridObjectDetectorSpec_base {
30
+ private weak var cxxWrapper: HybridObjectDetectorSpec_cxx? = nil
31
+ public init() { }
32
+ public func getCxxWrapper() -> HybridObjectDetectorSpec_cxx {
33
+ #if DEBUG
34
+ guard self is any HybridObjectDetectorSpec else {
35
+ fatalError("`self` is not a `HybridObjectDetectorSpec`! Did you accidentally inherit from `HybridObjectDetectorSpec_base` instead of `HybridObjectDetectorSpec`?")
36
+ }
37
+ #endif
38
+ if let cxxWrapper = self.cxxWrapper {
39
+ return cxxWrapper
40
+ } else {
41
+ let cxxWrapper = HybridObjectDetectorSpec_cxx(self as! any HybridObjectDetectorSpec)
42
+ self.cxxWrapper = cxxWrapper
43
+ return cxxWrapper
44
+ }
45
+ }
46
+ }
47
+
48
+ /**
49
+ * A Swift base-protocol representing the ObjectDetector HybridObject.
50
+ * Implement this protocol to create Swift-based instances of ObjectDetector.
51
+ * ```swift
52
+ * class HybridObjectDetector : HybridObjectDetectorSpec {
53
+ * // ...
54
+ * }
55
+ * ```
56
+ */
57
+ public typealias HybridObjectDetectorSpec = HybridObjectDetectorSpec_protocol & HybridObjectDetectorSpec_base
@@ -0,0 +1,188 @@
1
+ ///
2
+ /// HybridObjectDetectorSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * A class implementation that bridges HybridObjectDetectorSpec over to C++.
12
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
13
+ *
14
+ * Also, some Swift types need to be bridged with special handling:
15
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
16
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
17
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
18
+ */
19
+ open class HybridObjectDetectorSpec_cxx {
20
+ /**
21
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::mlkit::objects::bridge::swift`)
22
+ * from `NitroMLKitObjects-Swift-Cxx-Bridge.hpp`.
23
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
24
+ */
25
+ public typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
26
+
27
+ /**
28
+ * Holds an instance of the `HybridObjectDetectorSpec` Swift protocol.
29
+ */
30
+ private var __implementation: any HybridObjectDetectorSpec
31
+
32
+ /**
33
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
34
+ */
35
+ private var __cxxPart: bridge.std__weak_ptr_HybridObjectDetectorSpec_
36
+
37
+ /**
38
+ * Create a new `HybridObjectDetectorSpec_cxx` that wraps the given `HybridObjectDetectorSpec`.
39
+ * All properties and methods bridge to C++ types.
40
+ */
41
+ public init(_ implementation: any HybridObjectDetectorSpec) {
42
+ self.__implementation = implementation
43
+ self.__cxxPart = .init()
44
+ /* no base class */
45
+ }
46
+
47
+ /**
48
+ * Get the actual `HybridObjectDetectorSpec` instance this class wraps.
49
+ */
50
+ @inline(__always)
51
+ public func getHybridObjectDetectorSpec() -> any HybridObjectDetectorSpec {
52
+ return __implementation
53
+ }
54
+
55
+ /**
56
+ * Casts this instance to a retained unsafe raw pointer.
57
+ * This acquires one additional strong reference on the object!
58
+ */
59
+ public func toUnsafe() -> UnsafeMutableRawPointer {
60
+ return Unmanaged.passRetained(self).toOpaque()
61
+ }
62
+
63
+ /**
64
+ * Casts an unsafe pointer to a `HybridObjectDetectorSpec_cxx`.
65
+ * The pointer has to be a retained opaque `Unmanaged<HybridObjectDetectorSpec_cxx>`.
66
+ * This removes one strong reference from the object!
67
+ */
68
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridObjectDetectorSpec_cxx {
69
+ return Unmanaged<HybridObjectDetectorSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
70
+ }
71
+
72
+ /**
73
+ * Gets (or creates) the C++ part of this Hybrid Object.
74
+ * The C++ part is a `std::shared_ptr<HybridObjectDetectorSpec>`.
75
+ */
76
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridObjectDetectorSpec_ {
77
+ let cachedCxxPart = self.__cxxPart.lock()
78
+ if Bool(fromCxx: cachedCxxPart) {
79
+ return cachedCxxPart
80
+ } else {
81
+ let newCxxPart = bridge.create_std__shared_ptr_HybridObjectDetectorSpec_(self.toUnsafe())
82
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridObjectDetectorSpec_(newCxxPart)
83
+ return newCxxPart
84
+ }
85
+ }
86
+
87
+
88
+
89
+ /**
90
+ * Get the memory size of the Swift class (plus size of any other allocations)
91
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
92
+ */
93
+ @inline(__always)
94
+ public var memorySize: Int {
95
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
96
+ }
97
+
98
+ /**
99
+ * Compares this object with the given [other] object for reference equality.
100
+ */
101
+ @inline(__always)
102
+ public func equals(other: HybridObjectDetectorSpec_cxx) -> Bool {
103
+ return self.__implementation === other.__implementation
104
+ }
105
+
106
+ /**
107
+ * Call dispose() on the Swift class.
108
+ * This _may_ be called manually from JS.
109
+ */
110
+ @inline(__always)
111
+ public func dispose() {
112
+ self.__implementation.dispose()
113
+ }
114
+
115
+ /**
116
+ * Call toString() on the Swift class.
117
+ */
118
+ @inline(__always)
119
+ public func toString() -> String {
120
+ return self.__implementation.toString()
121
+ }
122
+
123
+ // Properties
124
+
125
+
126
+ // Methods
127
+ @inline(__always)
128
+ public final func detect(imageUri: std.string) -> bridge.Result_std__shared_ptr_Promise_std__vector_DetectedObject____ {
129
+ do {
130
+ let __result = try self.__implementation.detect(imageUri: String(imageUri))
131
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_DetectedObject___ in
132
+ let __promise = bridge.create_std__shared_ptr_Promise_std__vector_DetectedObject___()
133
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_DetectedObject___(__promise)
134
+ __result
135
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_DetectedObject_ in
136
+ var __vector = bridge.create_std__vector_DetectedObject_(__result.count)
137
+ for __item in __result {
138
+ __vector.push_back(__item)
139
+ }
140
+ return __vector
141
+ }()) })
142
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
143
+ return __promise
144
+ }()
145
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_DetectedObject____(__resultCpp)
146
+ } catch (let __error) {
147
+ let __exceptionPtr = __error.toCpp()
148
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_DetectedObject____(__exceptionPtr)
149
+ }
150
+ }
151
+
152
+ @inline(__always)
153
+ public final func detectBatch(imageUris: bridge.std__vector_std__string_, concurrency: Double) -> bridge.Result_std__shared_ptr_Promise_std__vector_BatchObjectResult____ {
154
+ do {
155
+ let __result = try self.__implementation.detectBatch(imageUris: imageUris.map({ __item in String(__item) }), concurrency: concurrency)
156
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_BatchObjectResult___ in
157
+ let __promise = bridge.create_std__shared_ptr_Promise_std__vector_BatchObjectResult___()
158
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_BatchObjectResult___(__promise)
159
+ __result
160
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_BatchObjectResult_ in
161
+ var __vector = bridge.create_std__vector_BatchObjectResult_(__result.count)
162
+ for __item in __result {
163
+ __vector.push_back(__item)
164
+ }
165
+ return __vector
166
+ }()) })
167
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
168
+ return __promise
169
+ }()
170
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_BatchObjectResult____(__resultCpp)
171
+ } catch (let __error) {
172
+ let __exceptionPtr = __error.toCpp()
173
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_BatchObjectResult____(__exceptionPtr)
174
+ }
175
+ }
176
+
177
+ @inline(__always)
178
+ public final func isAvailable() -> bridge.Result_bool_ {
179
+ do {
180
+ let __result = try self.__implementation.isAvailable()
181
+ let __resultCpp = __result
182
+ return bridge.create_Result_bool_(__resultCpp)
183
+ } catch (let __error) {
184
+ let __exceptionPtr = __error.toCpp()
185
+ return bridge.create_Result_bool_(__exceptionPtr)
186
+ }
187
+ }
188
+ }
@@ -0,0 +1,39 @@
1
+ ///
2
+ /// ObjectLabel.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `ObjectLabel`, backed by a C++ struct.
12
+ */
13
+ public typealias ObjectLabel = margelo.nitro.mlkit.objects.ObjectLabel
14
+
15
+ public extension ObjectLabel {
16
+ private typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `ObjectLabel`.
20
+ */
21
+ init(text: String, confidence: Double, index: Double) {
22
+ self.init(std.string(text), confidence, index)
23
+ }
24
+
25
+ @inline(__always)
26
+ var text: String {
27
+ return String(self.__text)
28
+ }
29
+
30
+ @inline(__always)
31
+ var confidence: Double {
32
+ return self.__confidence
33
+ }
34
+
35
+ @inline(__always)
36
+ var index: Double {
37
+ return self.__index
38
+ }
39
+ }