lime
Lime is a C++ library implementing Open Whisper System Signal protocol
npe.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <jni/functions.hpp>
4 
5 namespace jni
6  {
7  [[noreturn]] inline void ThrowNullPointerException(JNIEnv& env, const char* message = nullptr)
8  {
9  ThrowNew(env, FindClass(env, "java/lang/NullPointerException"), message);
10  }
11 
12  template < class T >
13  void NullCheck(JNIEnv& env, T* ptr, const char* message = nullptr)
14  {
15  if (!ptr) ThrowNullPointerException(env, message);
16  }
17 
18  template < class T >
19  T& SafeDereference(JNIEnv& env, T* ptr, const char* message = nullptr)
20  {
21  NullCheck(env, ptr, message);
22  return *ptr;
23  }
24  }
T & SafeDereference(JNIEnv &env, T *ptr, const char *message=nullptr)
Definition: npe.hpp:19
void ThrowNew(JNIEnv &env, jclass &clazz, const char *msg=nullptr)
Definition: functions.hpp:84
void ThrowNullPointerException(JNIEnv &env, const char *message=nullptr)
Definition: npe.hpp:7
Definition: advanced_ownership.hpp:5
jclass & FindClass(JNIEnv &env, const char *name)
Definition: functions.hpp:34
void NullCheck(JNIEnv &env, T *ptr, const char *message=nullptr)
Definition: npe.hpp:13