Skip to content

Commit

Permalink
move-only optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
li-feng-sc committed Jul 26, 2024
1 parent 7494022 commit 954a8a9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions support-lib/composer/djinni_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ struct Optional {
static ComposerType fromCpp(const OptionalType<typename T::CppType>& c) {
return c ? T::Boxed::fromCpp(*c) : Composer::Value::undefined();
}
static ComposerType fromCpp(OptionalType<typename T::CppType>&& c) {
return c ? T::Boxed::fromCpp(std::move(*c)) : Composer::Value::undefined();
}
template<typename C = T>
static ComposerType fromCpp(const typename C::CppOptType& cppOpt) {
return T::Boxed::fromCppOpt(cppOpt);
Expand Down
5 changes: 5 additions & 0 deletions support-lib/jni/Marshal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ namespace djinni
return c ? T::Boxed::fromCpp(jniEnv, *c) : LocalRef<JniType>{};
}

static LocalRef<JniType> fromCpp(JNIEnv* jniEnv, OptionalType<typename T::CppType>&& c)
{
return c ? T::Boxed::fromCpp(jniEnv, std::move(*c)) : LocalRef<JniType>{};
}

// fromCpp used for nullable shared_ptr
template <typename C = T>
static LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const typename C::CppOptType & cppOpt) {
Expand Down
3 changes: 3 additions & 0 deletions support-lib/objc/DJIMarshal+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ class Optional {
static ObjcType fromCpp(const OptionalType<typename T::CppType>& opt) {
return opt ? T::Boxed::fromCpp(*opt) : nil;
}
static ObjcType fromCpp(OptionalType<typename T::CppType>&& opt) {
return opt ? T::Boxed::fromCpp(std::move(*opt)) : nil;
}

// fromCpp used for nullable shared_ptr
template <typename C = T>
Expand Down
3 changes: 3 additions & 0 deletions support-lib/swiftxx/djinni_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ struct Optional {
static AnyValue fromCpp(const OptionalType<typename T::CppType>& c) {
return c ? T::fromCpp(*c) : makeVoidValue();
}
static AnyValue fromCpp(OptionalType<typename T::CppType>&& c) {
return c ? T::fromCpp(std::move(*c)) : makeVoidValue();
}
static CppType toCpp(const AnyValue& v) {
if (std::holds_alternative<VoidValue>(v)) {
return CppType{};
Expand Down
3 changes: 3 additions & 0 deletions support-lib/wasm/djinni_wasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ struct Optional
static JsType fromCpp(const OptionalType<typename T::CppType>& c) {
return c ? T::Boxed::fromCpp(*c) : em::val::undefined();
}
static JsType fromCpp(OptionalType<typename T::CppType>&& c) {
return c ? T::Boxed::fromCpp(std::move(*c)) : em::val::undefined();
}
template <typename C = T>
static JsType fromCpp(const typename C::CppOptType& cppOpt) {
return T::Boxed::fromCppOpt(cppOpt);
Expand Down

0 comments on commit 954a8a9

Please sign in to comment.