java/Ref: allow LocalRef to be nullable
Makes using the Java glue classes simpler to use, at the cost of very little overhead.
This commit is contained in:
parent
791245dec2
commit
1d49f1108f
@ -47,13 +47,13 @@ namespace Java {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* The local reference is obtained by the caller.
|
* The local reference is obtained by the caller. May
|
||||||
|
* be nullptr.
|
||||||
*/
|
*/
|
||||||
LocalRef(JNIEnv *_env, T _value) noexcept
|
LocalRef(JNIEnv *_env, T _value) noexcept
|
||||||
:env(_env), value(_value)
|
:env(_env), value(_value)
|
||||||
{
|
{
|
||||||
assert(env != nullptr);
|
assert(env != nullptr);
|
||||||
assert(value != nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~LocalRef() noexcept {
|
~LocalRef() noexcept {
|
||||||
@ -67,6 +67,10 @@ namespace Java {
|
|||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator bool() const noexcept {
|
||||||
|
return value != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
T Get() const noexcept {
|
T Get() const noexcept {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user