Make SmartLocalRef non-copyable

pull/726/head
Danke Xie 2015-12-19 09:12:35 -08:00
parent 2e831604e9
commit b0148641e9
1 changed files with 9 additions and 1 deletions

View File

@ -20,8 +20,16 @@ class SmartLocalRef {
private: private:
JNIEnv* mJniEnv; JNIEnv* mJniEnv;
jobject& mJavaObj; jobject& mJavaObj;
SmartLocalRef(const SmartLocalRef&); // non construction-copyable
SmartLocalRef& operator=(const SmartLocalRef&); // non copyable
public: public:
template<class T> SmartLocalRef(JNIEnv* env, T& object) : mJniEnv(env), mJavaObj((jobject&)object) {}; template<class T> SmartLocalRef(JNIEnv* env, T& object)
: mJniEnv(env)
, mJavaObj((jobject&)object)
{
};
~SmartLocalRef() { ~SmartLocalRef() {
if (mJavaObj != NULL) { if (mJavaObj != NULL) {
mJniEnv->DeleteLocalRef(mJavaObj); mJniEnv->DeleteLocalRef(mJavaObj);