forked from organicmaps/organicmaps
[android] Minor tuning of ScopedLocalRef. Now it can be used without .get() in some cases.
This commit is contained in:
parent
a661a122db
commit
e6169abec1
1 changed files with 8 additions and 12 deletions
|
@ -4,17 +4,13 @@
|
|||
|
||||
namespace jni
|
||||
{
|
||||
|
||||
// A smart pointer that deletes a JNI local reference when it goes out of scope.
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class ScopedLocalRef {
|
||||
public:
|
||||
ScopedLocalRef(JNIEnv * env, T localRef) : m_env(env), m_localRef(localRef) { }
|
||||
ScopedLocalRef(JNIEnv * env, T localRef) : m_env(env), m_localRef(localRef) {}
|
||||
|
||||
~ScopedLocalRef()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
~ScopedLocalRef() { reset(); }
|
||||
|
||||
void reset(T ptr = nullptr)
|
||||
{
|
||||
|
@ -26,17 +22,17 @@ public:
|
|||
m_localRef = ptr;
|
||||
}
|
||||
|
||||
T get() const
|
||||
{
|
||||
return m_localRef;
|
||||
}
|
||||
T get() const { return m_localRef; }
|
||||
|
||||
operator T() const { return m_localRef; }
|
||||
|
||||
private:
|
||||
JNIEnv * m_env;
|
||||
T m_localRef;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
ScopedLocalRef(ScopedLocalRef const &) = delete;
|
||||
void operator = (ScopedLocalRef const &) = delete;
|
||||
void operator=(ScopedLocalRef const &) = delete;
|
||||
};
|
||||
|
||||
} // namespace jni
|
||||
|
|
Loading…
Add table
Reference in a new issue