blob: da0c6471ef46e644094e4272d6a813c2759aaf73 [file] [log] [blame]
Andreas Gamped299c072017-10-17 10:50:00 -07001/*
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#if __cplusplus >= 201103L
26#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
27 TypeName(const TypeName&) = delete; \
28 void operator=(const TypeName&) = delete
29#else
30#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
31 TypeName(const TypeName&); \
32 void operator=(const TypeName&)
33#endif // __has_feature(cxx_deleted_functions)
34#endif // !defined(DISALLOW_COPY_AND_ASSIGN)
35
36#ifndef NATIVEHELPER_JNIHELP_H_
37// This seems a header-only include. Provide NPE throwing.
38static inline int jniThrowNullPointerException(JNIEnv* env, const char* msg) {
39 if (env->ExceptionCheck()) {
40 // Drop any pending exception.
41 env->ExceptionClear();
42 }
43
44 jclass e_class = env->FindClass("java/lang/NullPointerException");
45 if (e_class == nullptr) {
46 return -1;
47 }
48
49 if (env->ThrowNew(e_class, msg) != JNI_OK) {
50 env->DeleteLocalRef(e_class);
51 return -1;
52 }
53
54 env->DeleteLocalRef(e_class);
55 return 0;
56}
57#endif // NATIVEHELPER_JNIHELP_H_
58
59#endif // defined(__cplusplus)
60
61#endif // NATIVEHELPER_MACROS_H_