1 /* 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include "ReferenceAllocators.h" 20 21 namespace facebook { 22 namespace jni { 23 24 namespace detail { 25 struct JObjectBase { 26 jobject get() const noexcept; 27 void set(jobject reference) noexcept; 28 jobject this_; 29 }; 30 31 // RefReprType maps a type to the representation used by fbjni smart references. 32 template <typename T, typename Enable = void> 33 struct RefReprType; 34 35 template <typename T> 36 struct JavaObjectType; 37 38 template <typename T> 39 struct ReprAccess; 40 41 template <typename T, typename Enable = void> 42 struct PrimitiveOrJavaObjectType; 43 } // namespace detail 44 45 // Given T, either a jobject-like type or a JavaClass-derived type, ReprType<T> 46 // is the corresponding JavaClass-derived type and JniType<T> is the 47 // jobject-like type. 48 template <typename T> 49 using ReprType = typename detail::RefReprType<T>::type; 50 51 template <typename T> 52 using JniType = typename detail::JavaObjectType<T>::type; 53 54 template <typename T> 55 using PrimitiveOrJniType = typename detail::PrimitiveOrJavaObjectType<T>::type; 56 57 template <typename T, typename Alloc> 58 class base_owned_ref; 59 60 template <typename T, typename Alloc> 61 class basic_strong_ref; 62 63 template <typename T> 64 class weak_ref; 65 66 template <typename T> 67 class alias_ref; 68 69 /// A smart unique reference owning a local JNI reference 70 template <typename T> 71 using local_ref = basic_strong_ref<T, LocalReferenceAllocator>; 72 73 /// A smart unique reference owning a global JNI reference 74 template <typename T> 75 using global_ref = basic_strong_ref<T, GlobalReferenceAllocator>; 76 77 } // namespace jni 78 } // namespace facebook 79