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 NATIVEHELPER_MACROS_H_
18 #define NATIVEHELPER_MACROS_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 #ifndef NATIVEHELPER_JNIHELP_H_
31 // This seems a header-only include. Provide NPE throwing.
jniThrowNullPointerException(JNIEnv * env,const char * msg)32 static inline int jniThrowNullPointerException(JNIEnv* env, const char* msg) {
33     if (env->ExceptionCheck()) {
34         // Drop any pending exception.
35         env->ExceptionClear();
36     }
37 
38     jclass e_class = env->FindClass("java/lang/NullPointerException");
39     if (e_class == nullptr) {
40         return -1;
41     }
42 
43     if (env->ThrowNew(e_class, msg) != JNI_OK) {
44         env->DeleteLocalRef(e_class);
45         return -1;
46     }
47 
48     env->DeleteLocalRef(e_class);
49     return 0;
50 }
51 #endif  // NATIVEHELPER_JNIHELP_H_
52 
53 #endif  // defined(__cplusplus)
54 
55 #endif  // NATIVEHELPER_MACROS_H_
56