1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBNATIVEHELPER_HEADER_ONLY_INCLUDE_NATIVEHELPER_NATIVEHELPER_UTILS_H_
18 #define LIBNATIVEHELPER_HEADER_ONLY_INCLUDE_NATIVEHELPER_NATIVEHELPER_UTILS_H_
19 
20 #if defined(__cplusplus)
21 
22 #if !defined(DISALLOW_COPY_AND_ASSIGN)
23 // DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private:
24 // declarations in a class.
25 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
26   TypeName(const TypeName&) = delete;  \
27   void operator=(const TypeName&) = delete
28 #endif  // !defined(DISALLOW_COPY_AND_ASSIGN)
29 
30 // This seems a header-only include. Provide NPE throwing.
31 static inline int jniThrowNullPointerException(JNIEnv* env) {
32     if (env->ExceptionCheck()) {
33         // Drop any pending exception.
34         env->ExceptionClear();
35     }
36 
37     jclass e_class = env->FindClass("java/lang/NullPointerException");
38     if (e_class == nullptr) {
39         return -1;
40     }
41 
42     if (env->ThrowNew(e_class, nullptr) != JNI_OK) {
43         env->DeleteLocalRef(e_class);
44         return -1;
45     }
46 
47     env->DeleteLocalRef(e_class);
48     return 0;
49 }
50 
51 #endif  // defined(__cplusplus)
52 
53 #endif  // LIBNATIVEHELPER_HEADER_ONLY_INCLUDE_NATIVEHELPER_NATIVEHELPER_UTILS_H_
54