1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #ifndef JAVA_LOCAL_REF_H_
22 #define JAVA_LOCAL_REF_H_
27 template < typename T >
31 JavaLocalRef(JNIEnv *env, T obj) noexcept :
35 assert(env &&"JNIEnv is nullptr");
38 template< typename ENV >
39 JavaLocalRef(ENV *env, T obj) noexcept :
43 assert(env &&"JNIEnv is nullptr");
48 if (m_obj) m_env->DeleteLocalRef(m_obj);
51 operator bool() const noexcept { return m_obj; }
52 operator T() const noexcept { return m_obj; }
54 jobject get() const noexcept { return m_obj; }
56 JavaLocalRef(const JavaLocalRef &) = delete;
57 JavaLocalRef &operator=(const JavaLocalRef &) = delete;
59 JavaLocalRef &operator=(JavaLocalRef && ) = delete;
66 typedef JavaLocalRef< jobject > JavaLocalObject;
67 typedef JavaLocalRef< jstring > JavaLocalString;
68 typedef JavaLocalRef< jclass > JavaLocalClass;
70 #endif // JAVA_LOCAL_REF_H_