java/*: add noexcept

This commit is contained in:
Max Kellermann
2018-08-28 13:27:28 +02:00
parent 7137ca375a
commit 35eca08d48
10 changed files with 50 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2011 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -49,23 +49,25 @@ namespace Java {
/**
* The local reference is obtained by the caller.
*/
LocalRef(JNIEnv *_env, T _value):env(_env), value(_value) {
LocalRef(JNIEnv *_env, T _value) noexcept
:env(_env), value(_value)
{
assert(env != nullptr);
assert(value != nullptr);
}
~LocalRef() {
~LocalRef() noexcept {
env->DeleteLocalRef(value);
}
LocalRef(const LocalRef &other) = delete;
LocalRef &operator=(const LocalRef &other) = delete;
T Get() const {
T Get() const noexcept {
return value;
}
operator T() const {
operator T() const noexcept {
return value;
}
};
@@ -84,14 +86,16 @@ namespace Java {
*/
GlobalRef() = default;
GlobalRef(JNIEnv *env, T _value):value(_value) {
GlobalRef(JNIEnv *env, T _value) noexcept
:value(_value)
{
assert(env != nullptr);
assert(value != nullptr);
value = (T)env->NewGlobalRef(value);
}
~GlobalRef() {
~GlobalRef() noexcept {
GetEnv()->DeleteGlobalRef(value);
}
@@ -102,17 +106,17 @@ namespace Java {
* Sets the object, ignoring the previous value. This is only
* allowed once after the default constructor was used.
*/
void Set(JNIEnv *env, T _value) {
void Set(JNIEnv *env, T _value) noexcept {
assert(_value != nullptr);
value = (T)env->NewGlobalRef(_value);
}
T Get() const {
T Get() const noexcept {
return value;
}
operator T() const {
operator T() const noexcept {
return value;
}
};
@@ -129,12 +133,12 @@ namespace Java {
T value;
public:
constexpr TrivialRef() {};
TrivialRef() = default;
TrivialRef(const TrivialRef &other) = delete;
TrivialRef &operator=(const TrivialRef &other) = delete;
bool IsDefined() const {
bool IsDefined() const noexcept {
return value != nullptr;
}
@@ -142,7 +146,7 @@ namespace Java {
* Obtain a global reference on the specified object and store it.
* This object must not be set already.
*/
void Set(JNIEnv *env, T _value) {
void Set(JNIEnv *env, T _value) noexcept {
assert(value == nullptr);
assert(_value != nullptr);
@@ -152,7 +156,7 @@ namespace Java {
/**
* Release the global reference and clear this object.
*/
void Clear(JNIEnv *env) {
void Clear(JNIEnv *env) noexcept {
assert(value != nullptr);
env->DeleteGlobalRef(value);
@@ -163,16 +167,16 @@ namespace Java {
* Release the global reference and clear this object. It is
* allowed to call this method without ever calling Set().
*/
void ClearOptional(JNIEnv *env) {
void ClearOptional(JNIEnv *env) noexcept {
if (value != nullptr)
Clear(env);
}
T Get() const {
T Get() const noexcept {
return value;
}
operator T() const {
operator T() const noexcept {
return value;
}
};