Skip to content

Commit

Permalink
Merge branch 'hawtjni_shared_pointer' of https://github.com/ossdev07/…
Browse files Browse the repository at this point in the history
…hawtjni into ossdev07-hawtjni_shared_pointer
  • Loading branch information
gnodet committed Apr 2, 2019
2 parents bd514b7 + 27af76b commit ec9cc6c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void generateGetFields(JNIClass clazz) {
JNIClass superclazz = clazz.getSuperclass();
String clazzName = clazz.getNativeName();
String superName = superclazz.getNativeName();
String Methodname;
if (!superclazz.getName().equals("java.lang.Object")) {
/*
* Windows exception - cannot call get/set function of super class
Expand Down Expand Up @@ -281,28 +282,60 @@ void generateGetFields(JNIClass clazz) {
if (accessor == null || accessor.length() == 0)
accessor = field.getName();
if (type.isPrimitive()) {
output("\tlpStruct->");
output(accessor);
output(" = ");
output(field.getCast());
if( field.isPointer() ) {
if (field.isSharedPointer()) {
output("\tlpStruct->");
output(accessor);
output(" = ");
output("std::shared_ptr");
output("<");
Methodname =field.getCast();
String Method =Methodname.replace("*", ">");
Method =Method.replace("(", "");
Method =Method.replace(")", "");
output(Method);
output("(");
output(field.getCast());
output("(intptr_t)");
if (isCPP) {
output("env->Get");
} else {
output("(*env)->Get");
}
output(type.getTypeSignature1(!type.equals(type64)));
if (isCPP) {
output("Field(lpObject, ");
} else {
output("Field(env, lpObject, ");
}
output(field.getDeclaringClass().getSimpleName());
output("Fc.");
output(field.getName());
output(")");
output(");");
} else {
output("\tlpStruct->");
output(accessor);
output(" = ");
output(field.getCast());
if (field.isPointer()) {
output("(intptr_t)");
}
if (isCPP) {
output("env->Get");
} else {
output("(*env)->Get");
}
output(type.getTypeSignature1(!type.equals(type64)));
if (isCPP) {
output("Field(lpObject, ");
} else {
output("Field(env, lpObject, ");
}
output(field.getDeclaringClass().getSimpleName());
output("Fc.");
output(field.getName());
output(");");
}
if (isCPP) {
output("env->Get");
} else {
output("(*env)->Get");
}
output(type.getTypeSignature1(!type.equals(type64)));
if (isCPP) {
output("Field(lpObject, ");
} else {
output("Field(env, lpObject, ");
}
output(field.getDeclaringClass().getSimpleName());
output("Fc.");
output(field.getName());
output(");");
} else if (type.isArray()) {
JNIType componentType = type.getComponentType(), componentType64 = type64.getComponentType();
if (componentType.isPrimitive()) {
Expand Down Expand Up @@ -455,8 +488,14 @@ void generateSetFields(JNIClass clazz) {
if( field.isPointer() ) {
output("(intptr_t)");
}
output("lpStruct->"+accessor);
output(");");
if (field.isSharedPointer()) {
output("(&");
output("lpStruct->" + accessor);
output("));");
} else {
output("lpStruct->"+accessor);
output(");");
}
} else if (type.isArray()) {
JNIType componentType = type.getComponentType(), componentType64 = type64.getComponentType();
if (componentType.isPrimitive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public interface JNIField {
public String getConditional();
public boolean ignore();

public boolean isSharedPointer();
public boolean isPointer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public boolean isPointer() {
return getFlag(POINTER_FIELD) || ( type.getWrappedClass() == Long.TYPE && getCast().endsWith("*)") );
}

public boolean isSharedPointer() {
if( annotation == null ) {
return false;
}
return getFlag(SHARED_PTR) || ( type.getWrappedClass() == Long.TYPE && getCast().endsWith("*") );
}


public String getConditional() {
String parentConditional = getDeclaringClass().getConditional();
String myConditional = annotation == null ? null : emptyFilter(annotation.conditional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ public enum FieldFlag {
* Indicate that the field is a pointer.
*/
POINTER_FIELD,

/**
* Indicate that the field is a shared pointer.
*/

SHARED_PTR,

}
}

0 comments on commit ec9cc6c

Please sign in to comment.