@nitro-mlkit/translation 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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/NitroMLKitTranslate.podspec +34 -0
  3. package/README.md +66 -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/translate/HybridTranslator.kt +67 -0
  9. package/android/src/main/kotlin/com/nitromlkit/translate/NitroMLKitTranslatePackage.kt +19 -0
  10. package/expo-module.config.json +9 -0
  11. package/ios/HybridTranslator.swift +160 -0
  12. package/nitro.json +16 -0
  13. package/nitrogen/generated/.gitattributes +1 -0
  14. package/nitrogen/generated/android/NitroMLKitTranslate+autolinking.cmake +81 -0
  15. package/nitrogen/generated/android/NitroMLKitTranslate+autolinking.gradle +27 -0
  16. package/nitrogen/generated/android/NitroMLKitTranslateOnLoad.cpp +54 -0
  17. package/nitrogen/generated/android/NitroMLKitTranslateOnLoad.hpp +34 -0
  18. package/nitrogen/generated/android/c++/JHybridTranslatorSpec.cpp +144 -0
  19. package/nitrogen/generated/android/c++/JHybridTranslatorSpec.hpp +68 -0
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/translate/HybridTranslatorSpec.kt +75 -0
  21. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/translate/NitroMLKitTranslateOnLoad.kt +35 -0
  22. package/nitrogen/generated/ios/NitroMLKitTranslate+autolinking.rb +62 -0
  23. package/nitrogen/generated/ios/NitroMLKitTranslate-Swift-Cxx-Bridge.cpp +73 -0
  24. package/nitrogen/generated/ios/NitroMLKitTranslate-Swift-Cxx-Bridge.hpp +261 -0
  25. package/nitrogen/generated/ios/NitroMLKitTranslate-Swift-Cxx-Umbrella.hpp +46 -0
  26. package/nitrogen/generated/ios/NitroMLKitTranslateAutolinking.mm +33 -0
  27. package/nitrogen/generated/ios/NitroMLKitTranslateAutolinking.swift +26 -0
  28. package/nitrogen/generated/ios/c++/HybridTranslatorSpecSwift.cpp +11 -0
  29. package/nitrogen/generated/ios/c++/HybridTranslatorSpecSwift.hpp +124 -0
  30. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  31. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  32. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  33. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
  34. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +46 -0
  35. package/nitrogen/generated/ios/swift/HybridTranslatorSpec.swift +60 -0
  36. package/nitrogen/generated/ios/swift/HybridTranslatorSpec_cxx.swift +239 -0
  37. package/nitrogen/generated/shared/c++/HybridTranslatorSpec.cpp +26 -0
  38. package/nitrogen/generated/shared/c++/HybridTranslatorSpec.hpp +69 -0
  39. package/package.json +54 -0
  40. package/src/index.ts +14 -0
  41. package/src/specs/Translator.nitro.ts +23 -0
@@ -0,0 +1,261 @@
1
+ ///
2
+ /// NitroMLKitTranslate-Swift-Cxx-Bridge.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
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridTranslatorSpec` to properly resolve imports.
12
+ namespace margelo::nitro::mlkit::translate { class HybridTranslatorSpec; }
13
+
14
+ // Forward declarations of Swift defined types
15
+ // Forward declaration of `HybridTranslatorSpec_cxx` to properly resolve imports.
16
+ namespace NitroMLKitTranslate { class HybridTranslatorSpec_cxx; }
17
+
18
+ // Include C++ defined types
19
+ #include "HybridTranslatorSpec.hpp"
20
+ #include <NitroModules/Promise.hpp>
21
+ #include <NitroModules/PromiseHolder.hpp>
22
+ #include <NitroModules/Result.hpp>
23
+ #include <exception>
24
+ #include <functional>
25
+ #include <memory>
26
+ #include <string>
27
+ #include <vector>
28
+
29
+ /**
30
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
31
+ * as well as helper functions to interact with those C++ types from Swift.
32
+ */
33
+ namespace margelo::nitro::mlkit::translate::bridge::swift {
34
+
35
+ // pragma MARK: std::shared_ptr<Promise<std::string>>
36
+ /**
37
+ * Specialized version of `std::shared_ptr<Promise<std::string>>`.
38
+ */
39
+ using std__shared_ptr_Promise_std__string__ = std::shared_ptr<Promise<std::string>>;
40
+ inline std::shared_ptr<Promise<std::string>> create_std__shared_ptr_Promise_std__string__() noexcept {
41
+ return Promise<std::string>::create();
42
+ }
43
+ inline PromiseHolder<std::string> wrap_std__shared_ptr_Promise_std__string__(std::shared_ptr<Promise<std::string>> promise) noexcept {
44
+ return PromiseHolder<std::string>(std::move(promise));
45
+ }
46
+
47
+ // pragma MARK: std::function<void(const std::string& /* result */)>
48
+ /**
49
+ * Specialized version of `std::function<void(const std::string&)>`.
50
+ */
51
+ using Func_void_std__string = std::function<void(const std::string& /* result */)>;
52
+ /**
53
+ * Wrapper class for a `std::function<void(const std::string& / * result * /)>`, this can be used from Swift.
54
+ */
55
+ class Func_void_std__string_Wrapper final {
56
+ public:
57
+ explicit Func_void_std__string_Wrapper(std::function<void(const std::string& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::string& /* result */)>>(std::move(func))) {}
58
+ inline void call(std::string result) const noexcept {
59
+ _function->operator()(result);
60
+ }
61
+ private:
62
+ std::unique_ptr<std::function<void(const std::string& /* result */)>> _function;
63
+ } SWIFT_NONCOPYABLE;
64
+ Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept;
65
+ inline Func_void_std__string_Wrapper wrap_Func_void_std__string(Func_void_std__string value) noexcept {
66
+ return Func_void_std__string_Wrapper(std::move(value));
67
+ }
68
+
69
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
70
+ /**
71
+ * Specialized version of `std::function<void(const std::exception_ptr&)>`.
72
+ */
73
+ using Func_void_std__exception_ptr = std::function<void(const std::exception_ptr& /* error */)>;
74
+ /**
75
+ * Wrapper class for a `std::function<void(const std::exception_ptr& / * error * /)>`, this can be used from Swift.
76
+ */
77
+ class Func_void_std__exception_ptr_Wrapper final {
78
+ public:
79
+ explicit Func_void_std__exception_ptr_Wrapper(std::function<void(const std::exception_ptr& /* error */)>&& func): _function(std::make_unique<std::function<void(const std::exception_ptr& /* error */)>>(std::move(func))) {}
80
+ inline void call(std::exception_ptr error) const noexcept {
81
+ _function->operator()(error);
82
+ }
83
+ private:
84
+ std::unique_ptr<std::function<void(const std::exception_ptr& /* error */)>> _function;
85
+ } SWIFT_NONCOPYABLE;
86
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept;
87
+ inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) noexcept {
88
+ return Func_void_std__exception_ptr_Wrapper(std::move(value));
89
+ }
90
+
91
+ // pragma MARK: std::shared_ptr<Promise<void>>
92
+ /**
93
+ * Specialized version of `std::shared_ptr<Promise<void>>`.
94
+ */
95
+ using std__shared_ptr_Promise_void__ = std::shared_ptr<Promise<void>>;
96
+ inline std::shared_ptr<Promise<void>> create_std__shared_ptr_Promise_void__() noexcept {
97
+ return Promise<void>::create();
98
+ }
99
+ inline PromiseHolder<void> wrap_std__shared_ptr_Promise_void__(std::shared_ptr<Promise<void>> promise) noexcept {
100
+ return PromiseHolder<void>(std::move(promise));
101
+ }
102
+
103
+ // pragma MARK: std::function<void()>
104
+ /**
105
+ * Specialized version of `std::function<void()>`.
106
+ */
107
+ using Func_void = std::function<void()>;
108
+ /**
109
+ * Wrapper class for a `std::function<void()>`, this can be used from Swift.
110
+ */
111
+ class Func_void_Wrapper final {
112
+ public:
113
+ explicit Func_void_Wrapper(std::function<void()>&& func): _function(std::make_unique<std::function<void()>>(std::move(func))) {}
114
+ inline void call() const noexcept {
115
+ _function->operator()();
116
+ }
117
+ private:
118
+ std::unique_ptr<std::function<void()>> _function;
119
+ } SWIFT_NONCOPYABLE;
120
+ Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept;
121
+ inline Func_void_Wrapper wrap_Func_void(Func_void value) noexcept {
122
+ return Func_void_Wrapper(std::move(value));
123
+ }
124
+
125
+ // pragma MARK: std::shared_ptr<Promise<bool>>
126
+ /**
127
+ * Specialized version of `std::shared_ptr<Promise<bool>>`.
128
+ */
129
+ using std__shared_ptr_Promise_bool__ = std::shared_ptr<Promise<bool>>;
130
+ inline std::shared_ptr<Promise<bool>> create_std__shared_ptr_Promise_bool__() noexcept {
131
+ return Promise<bool>::create();
132
+ }
133
+ inline PromiseHolder<bool> wrap_std__shared_ptr_Promise_bool__(std::shared_ptr<Promise<bool>> promise) noexcept {
134
+ return PromiseHolder<bool>(std::move(promise));
135
+ }
136
+
137
+ // pragma MARK: std::function<void(bool /* result */)>
138
+ /**
139
+ * Specialized version of `std::function<void(bool)>`.
140
+ */
141
+ using Func_void_bool = std::function<void(bool /* result */)>;
142
+ /**
143
+ * Wrapper class for a `std::function<void(bool / * result * /)>`, this can be used from Swift.
144
+ */
145
+ class Func_void_bool_Wrapper final {
146
+ public:
147
+ explicit Func_void_bool_Wrapper(std::function<void(bool /* result */)>&& func): _function(std::make_unique<std::function<void(bool /* result */)>>(std::move(func))) {}
148
+ inline void call(bool result) const noexcept {
149
+ _function->operator()(result);
150
+ }
151
+ private:
152
+ std::unique_ptr<std::function<void(bool /* result */)>> _function;
153
+ } SWIFT_NONCOPYABLE;
154
+ Func_void_bool create_Func_void_bool(void* NON_NULL swiftClosureWrapper) noexcept;
155
+ inline Func_void_bool_Wrapper wrap_Func_void_bool(Func_void_bool value) noexcept {
156
+ return Func_void_bool_Wrapper(std::move(value));
157
+ }
158
+
159
+ // pragma MARK: std::vector<std::string>
160
+ /**
161
+ * Specialized version of `std::vector<std::string>`.
162
+ */
163
+ using std__vector_std__string_ = std::vector<std::string>;
164
+ inline std::vector<std::string> create_std__vector_std__string_(size_t size) noexcept {
165
+ std::vector<std::string> vector;
166
+ vector.reserve(size);
167
+ return vector;
168
+ }
169
+
170
+ // pragma MARK: std::shared_ptr<Promise<std::vector<std::string>>>
171
+ /**
172
+ * Specialized version of `std::shared_ptr<Promise<std::vector<std::string>>>`.
173
+ */
174
+ using std__shared_ptr_Promise_std__vector_std__string___ = std::shared_ptr<Promise<std::vector<std::string>>>;
175
+ inline std::shared_ptr<Promise<std::vector<std::string>>> create_std__shared_ptr_Promise_std__vector_std__string___() noexcept {
176
+ return Promise<std::vector<std::string>>::create();
177
+ }
178
+ inline PromiseHolder<std::vector<std::string>> wrap_std__shared_ptr_Promise_std__vector_std__string___(std::shared_ptr<Promise<std::vector<std::string>>> promise) noexcept {
179
+ return PromiseHolder<std::vector<std::string>>(std::move(promise));
180
+ }
181
+
182
+ // pragma MARK: std::function<void(const std::vector<std::string>& /* result */)>
183
+ /**
184
+ * Specialized version of `std::function<void(const std::vector<std::string>&)>`.
185
+ */
186
+ using Func_void_std__vector_std__string_ = std::function<void(const std::vector<std::string>& /* result */)>;
187
+ /**
188
+ * Wrapper class for a `std::function<void(const std::vector<std::string>& / * result * /)>`, this can be used from Swift.
189
+ */
190
+ class Func_void_std__vector_std__string__Wrapper final {
191
+ public:
192
+ explicit Func_void_std__vector_std__string__Wrapper(std::function<void(const std::vector<std::string>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::vector<std::string>& /* result */)>>(std::move(func))) {}
193
+ inline void call(std::vector<std::string> result) const noexcept {
194
+ _function->operator()(result);
195
+ }
196
+ private:
197
+ std::unique_ptr<std::function<void(const std::vector<std::string>& /* result */)>> _function;
198
+ } SWIFT_NONCOPYABLE;
199
+ Func_void_std__vector_std__string_ create_Func_void_std__vector_std__string_(void* NON_NULL swiftClosureWrapper) noexcept;
200
+ inline Func_void_std__vector_std__string__Wrapper wrap_Func_void_std__vector_std__string_(Func_void_std__vector_std__string_ value) noexcept {
201
+ return Func_void_std__vector_std__string__Wrapper(std::move(value));
202
+ }
203
+
204
+ // pragma MARK: std::shared_ptr<HybridTranslatorSpec>
205
+ /**
206
+ * Specialized version of `std::shared_ptr<HybridTranslatorSpec>`.
207
+ */
208
+ using std__shared_ptr_HybridTranslatorSpec_ = std::shared_ptr<HybridTranslatorSpec>;
209
+ std::shared_ptr<HybridTranslatorSpec> create_std__shared_ptr_HybridTranslatorSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
210
+ void* NON_NULL get_std__shared_ptr_HybridTranslatorSpec_(std__shared_ptr_HybridTranslatorSpec_ cppType);
211
+
212
+ // pragma MARK: std::weak_ptr<HybridTranslatorSpec>
213
+ using std__weak_ptr_HybridTranslatorSpec_ = std::weak_ptr<HybridTranslatorSpec>;
214
+ inline std__weak_ptr_HybridTranslatorSpec_ weakify_std__shared_ptr_HybridTranslatorSpec_(const std::shared_ptr<HybridTranslatorSpec>& strong) noexcept { return strong; }
215
+
216
+ // pragma MARK: Result<std::shared_ptr<Promise<std::string>>>
217
+ using Result_std__shared_ptr_Promise_std__string___ = Result<std::shared_ptr<Promise<std::string>>>;
218
+ inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::shared_ptr<Promise<std::string>>& value) noexcept {
219
+ return Result<std::shared_ptr<Promise<std::string>>>::withValue(value);
220
+ }
221
+ inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::exception_ptr& error) noexcept {
222
+ return Result<std::shared_ptr<Promise<std::string>>>::withError(error);
223
+ }
224
+
225
+ // pragma MARK: Result<std::shared_ptr<Promise<void>>>
226
+ using Result_std__shared_ptr_Promise_void___ = Result<std::shared_ptr<Promise<void>>>;
227
+ inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::shared_ptr<Promise<void>>& value) noexcept {
228
+ return Result<std::shared_ptr<Promise<void>>>::withValue(value);
229
+ }
230
+ inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::exception_ptr& error) noexcept {
231
+ return Result<std::shared_ptr<Promise<void>>>::withError(error);
232
+ }
233
+
234
+ // pragma MARK: Result<std::shared_ptr<Promise<bool>>>
235
+ using Result_std__shared_ptr_Promise_bool___ = Result<std::shared_ptr<Promise<bool>>>;
236
+ inline Result_std__shared_ptr_Promise_bool___ create_Result_std__shared_ptr_Promise_bool___(const std::shared_ptr<Promise<bool>>& value) noexcept {
237
+ return Result<std::shared_ptr<Promise<bool>>>::withValue(value);
238
+ }
239
+ inline Result_std__shared_ptr_Promise_bool___ create_Result_std__shared_ptr_Promise_bool___(const std::exception_ptr& error) noexcept {
240
+ return Result<std::shared_ptr<Promise<bool>>>::withError(error);
241
+ }
242
+
243
+ // pragma MARK: Result<std::shared_ptr<Promise<std::vector<std::string>>>>
244
+ using Result_std__shared_ptr_Promise_std__vector_std__string____ = Result<std::shared_ptr<Promise<std::vector<std::string>>>>;
245
+ inline Result_std__shared_ptr_Promise_std__vector_std__string____ create_Result_std__shared_ptr_Promise_std__vector_std__string____(const std::shared_ptr<Promise<std::vector<std::string>>>& value) noexcept {
246
+ return Result<std::shared_ptr<Promise<std::vector<std::string>>>>::withValue(value);
247
+ }
248
+ inline Result_std__shared_ptr_Promise_std__vector_std__string____ create_Result_std__shared_ptr_Promise_std__vector_std__string____(const std::exception_ptr& error) noexcept {
249
+ return Result<std::shared_ptr<Promise<std::vector<std::string>>>>::withError(error);
250
+ }
251
+
252
+ // pragma MARK: Result<bool>
253
+ using Result_bool_ = Result<bool>;
254
+ inline Result_bool_ create_Result_bool_(bool value) noexcept {
255
+ return Result<bool>::withValue(std::move(value));
256
+ }
257
+ inline Result_bool_ create_Result_bool_(const std::exception_ptr& error) noexcept {
258
+ return Result<bool>::withError(error);
259
+ }
260
+
261
+ } // namespace margelo::nitro::mlkit::translate::bridge::swift
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// NitroMLKitTranslate-Swift-Cxx-Umbrella.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
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridTranslatorSpec` to properly resolve imports.
12
+ namespace margelo::nitro::mlkit::translate { class HybridTranslatorSpec; }
13
+
14
+ // Include C++ defined types
15
+ #include "HybridTranslatorSpec.hpp"
16
+ #include <NitroModules/Promise.hpp>
17
+ #include <NitroModules/Result.hpp>
18
+ #include <exception>
19
+ #include <memory>
20
+ #include <string>
21
+ #include <vector>
22
+
23
+ // C++ helpers for Swift
24
+ #include "NitroMLKitTranslate-Swift-Cxx-Bridge.hpp"
25
+
26
+ // Common C++ types used in Swift
27
+ #include <NitroModules/ArrayBufferHolder.hpp>
28
+ #include <NitroModules/AnyMapUtils.hpp>
29
+ #include <NitroModules/RuntimeError.hpp>
30
+ #include <NitroModules/DateToChronoDate.hpp>
31
+
32
+ // Forward declarations of Swift defined types
33
+ // Forward declaration of `HybridTranslatorSpec_cxx` to properly resolve imports.
34
+ namespace NitroMLKitTranslate { class HybridTranslatorSpec_cxx; }
35
+
36
+ // Include Swift defined types
37
+ #if __has_include("NitroMLKitTranslate-Swift.h")
38
+ // This header is generated by Xcode/Swift on every app build.
39
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroMLKitTranslate".
40
+ #include "NitroMLKitTranslate-Swift.h"
41
+ // Same as above, but used when building with frameworks (`use_frameworks`)
42
+ #elif __has_include(<NitroMLKitTranslate/NitroMLKitTranslate-Swift.h>)
43
+ #include <NitroMLKitTranslate/NitroMLKitTranslate-Swift.h>
44
+ #else
45
+ #error NitroMLKitTranslate's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroMLKitTranslate", and try building the app first.
46
+ #endif
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// NitroMLKitTranslateAutolinking.mm
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 <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+ #import "NitroMLKitTranslate-Swift-Cxx-Umbrella.hpp"
11
+ #import <type_traits>
12
+
13
+ #include "HybridTranslatorSpecSwift.hpp"
14
+
15
+ @interface NitroMLKitTranslateAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation NitroMLKitTranslateAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::mlkit::translate;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "Translator",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ std::shared_ptr<HybridTranslatorSpec> hybridObject = NitroMLKitTranslate::NitroMLKitTranslateAutolinking::createTranslator();
28
+ return hybridObject;
29
+ }
30
+ );
31
+ }
32
+
33
+ @end
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// NitroMLKitTranslateAutolinking.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 NitroMLKitTranslateAutolinking {
13
+ public typealias bridge = margelo.nitro.mlkit.translate.bridge.swift
14
+
15
+ public static func createTranslator() -> bridge.std__shared_ptr_HybridTranslatorSpec_ {
16
+ let hybridObject = HybridTranslator()
17
+ return { () -> bridge.std__shared_ptr_HybridTranslatorSpec_ in
18
+ let __cxxWrapped = hybridObject.getCxxWrapper()
19
+ return __cxxWrapped.getCxxPart()
20
+ }()
21
+ }
22
+
23
+ public static func isTranslatorRecyclable() -> Bool {
24
+ return HybridTranslator.self is any RecyclableView.Type
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridTranslatorSpecSwift.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 "HybridTranslatorSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::mlkit::translate {
11
+ } // namespace margelo::nitro::mlkit::translate
@@ -0,0 +1,124 @@
1
+ ///
2
+ /// HybridTranslatorSpecSwift.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 "HybridTranslatorSpec.hpp"
11
+
12
+ // Forward declaration of `HybridTranslatorSpec_cxx` to properly resolve imports.
13
+ namespace NitroMLKitTranslate { class HybridTranslatorSpec_cxx; }
14
+
15
+
16
+
17
+ #include <string>
18
+ #include <NitroModules/Promise.hpp>
19
+ #include <vector>
20
+
21
+ #include "NitroMLKitTranslate-Swift-Cxx-Umbrella.hpp"
22
+
23
+ namespace margelo::nitro::mlkit::translate {
24
+
25
+ /**
26
+ * The C++ part of HybridTranslatorSpec_cxx.swift.
27
+ *
28
+ * HybridTranslatorSpecSwift (C++) accesses HybridTranslatorSpec_cxx (Swift), and might
29
+ * contain some additional bridging code for C++ <> Swift interop.
30
+ *
31
+ * Since this obviously introduces an overhead, I hope at some point in
32
+ * the future, HybridTranslatorSpec_cxx can directly inherit from the C++ class HybridTranslatorSpec
33
+ * to simplify the whole structure and memory management.
34
+ */
35
+ class HybridTranslatorSpecSwift: public virtual HybridTranslatorSpec {
36
+ public:
37
+ // Constructor from a Swift instance
38
+ explicit HybridTranslatorSpecSwift(const NitroMLKitTranslate::HybridTranslatorSpec_cxx& swiftPart):
39
+ HybridObject(HybridTranslatorSpec::TAG),
40
+ _swiftPart(swiftPart) { }
41
+
42
+ public:
43
+ // Get the Swift part
44
+ inline NitroMLKitTranslate::HybridTranslatorSpec_cxx& getSwiftPart() noexcept {
45
+ return _swiftPart;
46
+ }
47
+
48
+ public:
49
+ inline size_t getExternalMemorySize() noexcept override {
50
+ return _swiftPart.getMemorySize();
51
+ }
52
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
53
+ if (auto otherCast = std::dynamic_pointer_cast<HybridTranslatorSpecSwift>(other)) {
54
+ return _swiftPart.equals(otherCast->_swiftPart);
55
+ }
56
+ return false;
57
+ }
58
+ void dispose() noexcept override {
59
+ _swiftPart.dispose();
60
+ }
61
+ std::string toString() override {
62
+ return _swiftPart.toString();
63
+ }
64
+
65
+ public:
66
+ // Properties
67
+
68
+
69
+ public:
70
+ // Methods
71
+ inline std::shared_ptr<Promise<std::string>> translate(const std::string& text, const std::string& sourceLanguage, const std::string& targetLanguage) override {
72
+ auto __result = _swiftPart.translate(text, sourceLanguage, targetLanguage);
73
+ if (__result.hasError()) [[unlikely]] {
74
+ std::rethrow_exception(__result.error());
75
+ }
76
+ auto __value = std::move(__result.value());
77
+ return __value;
78
+ }
79
+ inline std::shared_ptr<Promise<void>> downloadModel(const std::string& language, bool requireWifi) override {
80
+ auto __result = _swiftPart.downloadModel(language, std::forward<decltype(requireWifi)>(requireWifi));
81
+ if (__result.hasError()) [[unlikely]] {
82
+ std::rethrow_exception(__result.error());
83
+ }
84
+ auto __value = std::move(__result.value());
85
+ return __value;
86
+ }
87
+ inline std::shared_ptr<Promise<bool>> isModelDownloaded(const std::string& language) override {
88
+ auto __result = _swiftPart.isModelDownloaded(language);
89
+ if (__result.hasError()) [[unlikely]] {
90
+ std::rethrow_exception(__result.error());
91
+ }
92
+ auto __value = std::move(__result.value());
93
+ return __value;
94
+ }
95
+ inline std::shared_ptr<Promise<void>> deleteModel(const std::string& language) override {
96
+ auto __result = _swiftPart.deleteModel(language);
97
+ if (__result.hasError()) [[unlikely]] {
98
+ std::rethrow_exception(__result.error());
99
+ }
100
+ auto __value = std::move(__result.value());
101
+ return __value;
102
+ }
103
+ inline std::shared_ptr<Promise<std::vector<std::string>>> getDownloadedModels() override {
104
+ auto __result = _swiftPart.getDownloadedModels();
105
+ if (__result.hasError()) [[unlikely]] {
106
+ std::rethrow_exception(__result.error());
107
+ }
108
+ auto __value = std::move(__result.value());
109
+ return __value;
110
+ }
111
+ inline bool isAvailable() override {
112
+ auto __result = _swiftPart.isAvailable();
113
+ if (__result.hasError()) [[unlikely]] {
114
+ std::rethrow_exception(__result.error());
115
+ }
116
+ auto __value = std::move(__result.value());
117
+ return __value;
118
+ }
119
+
120
+ private:
121
+ NitroMLKitTranslate::HybridTranslatorSpec_cxx _swiftPart;
122
+ };
123
+
124
+ } // namespace margelo::nitro::mlkit::translate
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void.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 `() -> 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 {
15
+ public typealias bridge = margelo.nitro.mlkit.translate.bridge.swift
16
+
17
+ private let closure: () -> Void
18
+
19
+ public init(_ closure: @escaping () -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call() -> Void {
25
+ self.closure()
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`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void {
44
+ return Unmanaged<Func_void>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_bool.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: Bool) -> 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_bool {
15
+ public typealias bridge = margelo.nitro.mlkit.translate.bridge.swift
16
+
17
+ private let closure: (_ value: Bool) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: Bool) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: Bool) -> Void {
25
+ self.closure(value)
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_bool`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_bool>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_bool {
44
+ return Unmanaged<Func_void_bool>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -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.translate.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
+ }