-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpp_native_delete.cpp
More file actions
61 lines (60 loc) · 3.58 KB
/
cpp_native_delete.cpp
File metadata and controls
61 lines (60 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//%%% Lines beginning with "//%%%" are template comments and removed from final output.
//%%% "%NAMESPACE%" will be replaced with namespace
//%%% "%HEADER%" will be replaced with header
//%%% "%HEADER_DEFINE%" will be replaced with defined value used to prevent multiple inclusion
//%%% "%CLASS_NAME%" will be replaced with className (not including package)
//%%% "%JNI_SIGNATURE% will be replaced with the JNI signature for the method.
//%%% "%METHOD_NAME% will be replaced with the actual methods arguments
//%%% "%METHOD_ARGS% will be replaced with the actual methods arguments
//%%% "%METHOD_ONFAIL% will be replaced with the code to execute on failure eg return -1
//%%% "%METHOD_CALL_TYPE% will be replaced with the type of Call<Type>Method needed.
//%%% "%METHOD_RETURN%" will be replaced with "return" or "" for void functions.
if(jthis == NULL) {
std::cerr << __FILE__ << ":" << __LINE__ <<" Call of method %METHOD_NAME% of %FULL_CLASS_NAME% with jthis == NULL." << std::endl;
%METHOD_ONFAIL%
}
jclass cls = env->GetObjectClass(jthis);
if(GetDebugJ4Cpp()) DebugPrintJObject(__FILE__,__LINE__," %CLASS_NAME%::%METHOD_NAME% jthis=",jthis);
%CLASS_NAME% *nativeAddress=0;
if (cls != NULL) {
jfieldID fid = env->GetFieldID(cls, "nativeAddress", "J");
if (NULL == fid) {
std::cerr << "Class %FULL_CLASS_NAME% has no field named nativeAddress with signature J." << std::endl;
env->ThrowNew(getRuntimeExceptionClass(),"Class %FULL_CLASS_NAME% has no field named nativeAddress with signature J.");
%METHOD_ONFAIL%
}
jfieldID fidB = env->GetFieldID(cls, "nativeDeleteOnClose", "Z");
if(NULL == fidB) {
std::cerr << "Class %FULL_CLASS_NAME% has no field named nativeAddress with signature J." << std::endl;
env->ThrowNew(getRuntimeExceptionClass(),"Class %FULL_CLASS_NAME% has no field named nativeAddress with signature J.");
%METHOD_ONFAIL%
} else {
nativeAddress = (%CLASS_NAME% *) env->GetLongField( jthis, fid );
jboolean nativeDeleteOnClose = env->GetBooleanField(jthis,fidB);
if(NULL == nativeAddress || nativeDeleteOnClose != JNI_TRUE) {
if(GetDebugJ4Cpp()) {
std::cerr << __FILE__ << ":" << __LINE__ <<" Ignoring all to deleteNative with nativeDeleteOnClose = " << nativeDeleteOnClose << std::endl;
}
%METHOD_ONFAIL%
}
}
}
if(nativeAddress == NULL) {
std::cerr << "Class %FULL_CLASS_NAME%::%METHOD_NAME% : nativeAddress==NULL" << std::endl;
env->ThrowNew(getRuntimeExceptionClass(),"Class %FULL_CLASS_NAME%::%METHOD_NAME% : nativeAddress==NULL");
%METHOD_ONFAIL%
}
if(nativeAddress->jthis == NULL) {
std::cerr << "Class %FULL_CLASS_NAME%::%METHOD_NAME% : nativeAddress->jthis==NULL" << std::endl;
env->ThrowNew(getRuntimeExceptionClass(),"Class %FULL_CLASS_NAME%::%METHOD_NAME% : nativeAddress->jthis==NULL");
%METHOD_ONFAIL%
}
if(nativeAddress->jthis != jthis && !env->IsSameObject(nativeAddress->jthis,jthis)) {
DebugPrintJObject(__FILE__,__LINE__," %CLASS_NAME%::%METHOD_NAME% jthis=",jthis);
DebugPrintJObject(__FILE__,__LINE__," %CLASS_NAME%::%METHOD_NAME% nativeAddress->jthis=",nativeAddress->jthis);
std::cerr << "Class %FULL_CLASS_NAME% : nativeAddress->jthis not same object as jthis" << std::endl;
env->ThrowNew(getRuntimeExceptionClass(),"Class %FULL_CLASS_NAME% : nativeAddress->jthis not same object as jthis");
%METHOD_ONFAIL%
}
if(GetDebugJ4Cpp()) std::cout << __FILE__ << ":" << __LINE__ <<" Call of delete %FULL_CLASS_NAME% with nativeAddress=" << nativeAddress << std::endl;
delete nativeAddress;