summaryrefslogtreecommitdiff
path: root/src/java/Ref.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-28 13:27:28 +0200
committerMax Kellermann <max@musicpd.org>2018-08-28 13:27:28 +0200
commit35eca08d4829f16a8330939505be4fccb7de8c4b (patch)
tree86e2dfa3f38bef0b107c3823f35f58883a10e313 /src/java/Ref.hxx
parent7137ca375afdd258a24f2cb6a50bbac98c16d805 (diff)
java/*: add `noexcept`
Diffstat (limited to 'src/java/Ref.hxx')
-rw-r--r--src/java/Ref.hxx38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/java/Ref.hxx b/src/java/Ref.hxx
index a6f2d5d84..a80856a79 100644
--- a/src/java/Ref.hxx
+++ b/src/java/Ref.hxx
@@ -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;
}
};