diff options
author | Elliott Hughes <enh@google.com> | 2010-05-17 22:34:46 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-05-17 22:34:46 -0700 |
commit | 8044bf6b446c93cd29c5753544246316f269064f (patch) | |
tree | a4989bebccaae59e33770577c0c1cd9b9f87eae2 /include/ScopedLocalRef.h | |
parent | b35597648f05db8d67c6a11d63044102a76cffda (diff) | |
download | libcore-8044bf6b446c93cd29c5753544246316f269064f.zip libcore-8044bf6b446c93cd29c5753544246316f269064f.tar.gz libcore-8044bf6b446c93cd29c5753544246316f269064f.tar.bz2 |
Make ScopedLocalRef more convenient, and use it more widely.
Even though every reference type is a jobject, it's useful to be able to use
more specific types.
Change-Id: Id8056d0e18380675c90f08c4173a8b34b4d5d983
Diffstat (limited to 'include/ScopedLocalRef.h')
-rw-r--r-- | include/ScopedLocalRef.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/include/ScopedLocalRef.h b/include/ScopedLocalRef.h index 2cf4673..84ee11a 100644 --- a/include/ScopedLocalRef.h +++ b/include/ScopedLocalRef.h @@ -1,12 +1,12 @@ /* * Copyright (C) 2010 The Android Open Source Project - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,9 +20,10 @@ #include "JNIHelp.h" // A smart pointer that deletes a JNI local reference when it goes out of scope. +template<typename T> class ScopedLocalRef { public: - ScopedLocalRef(JNIEnv* env, jobject localRef) + ScopedLocalRef(JNIEnv* env, T localRef) : mEnv(env), mLocalRef(localRef) { } @@ -38,13 +39,13 @@ public: } } - jobject get() const { + T get() const { return mLocalRef; } private: JNIEnv* mEnv; - jobject mLocalRef; + T mLocalRef; // Disallow copy and assignment. ScopedLocalRef(const ScopedLocalRef&); |