Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class JNISharedPtr final {
* each time. It is not safe to call this multiple times if you use enable_shared_from_this.
* Instead, use HybridObject::shared().
*/
template <typename T, typename std::enable_if<is_base_template_of<T, jni::HybridClass>::value, int>::type = 0>
template <typename T>
requires is_base_template_of<T, jni::HybridClass>::value
static std::shared_ptr<T> make_shared_from_jni(const jni::global_ref<typename T::javaobject>& ref) {
#ifdef NITRO_DEBUG
if (ref == nullptr || ref->cthis() == nullptr) [[unlikely]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct JSIConverter;
#include "NitroDefines.hpp"
#include <jsi/jsi.h>
#include <memory>
#include <type_traits>

namespace margelo::nitro {

Expand All @@ -35,7 +34,8 @@ struct MutableBufferNativeState final : public jsi::NativeState {

// MutableBuffer <> ArrayBuffer
template <typename T>
struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_v<T, jsi::MutableBuffer>>> final {
requires SharedPtrTo<T, jsi::MutableBuffer>
struct JSIConverter<T> final {
static inline std::shared_ptr<ArrayBuffer> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
#ifdef NITRO_DEBUG
if (!arg.isObject()) [[unlikely]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include "NitroDefines.hpp"
#include "NitroTypeInfo.hpp"
#include <jsi/jsi.h>
#include <type_traits>

namespace margelo::nitro {

using namespace facebook;

// jsi::HostObject <> {}
template <typename T>
struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_v<T, jsi::HostObject>>> final {
requires SharedPtrTo<T, jsi::HostObject>
struct JSIConverter<T> final {
using TPointee = typename T::element_type;

static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class HybridObject;
#include "NitroDefines.hpp"
#include "NitroTypeInfo.hpp"
#include <jsi/jsi.h>
#include <type_traits>

namespace margelo::nitro {

using namespace facebook;

// NativeState <> {}
template <typename T>
struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_v<T, jsi::NativeState>>> final {
requires SharedPtrTo<T, jsi::NativeState>
struct JSIConverter<T> final {
using TPointee = typename T::element_type;

static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

#pragma once

#include <memory>
#include <type_traits>

namespace margelo::nitro {

using namespace facebook;

// Returns whether the given type T is a shared_ptr to type P.
template <typename T, typename P>
struct is_shared_ptr_to : std::false_type {};
Expand All @@ -24,4 +23,7 @@ struct is_shared_ptr_to<std::shared_ptr<T>, P> : std::is_base_of<typename std::r
template <typename T, typename P>
constexpr bool is_shared_ptr_to_v = is_shared_ptr_to<T, P>::value;

template <typename T, typename P>
concept SharedPtrTo = is_shared_ptr_to_v<T, P>;

} // namespace margelo::nitro
Loading