void outputFunction(FILE *fp, FileInfo *data) { int i; int args_ok = 1; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* NewInstance and SafeDownCast can not be wrapped because it is a (non-virtual) method which returns a pointer of the same type as the current pointer. Since all methods are virtual in Java, this looks like polymorphic return type. */ if (!strcmp("NewInstance",currentFunction->Name)) { return ; } if (!strcmp("SafeDownCast",currentFunction->Name)) { return ; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (currentFunction->ArgTypes[i] % 0x1000 == 0x9) args_ok = 0; if ((currentFunction->ArgTypes[i] % 0x10) == 0x8) args_ok = 0; if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 != 0x3)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x109)&& ((currentFunction->ArgTypes[i] % 0x1000)/0x100)) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x313) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ArgTypes[i] % 0x1000 == 0x31C) args_ok = 0; } if ((currentFunction->ReturnType % 0x10) == 0x8) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x9) args_ok = 0; if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&& (currentFunction->ReturnType % 0x1000 != 0x109)&& ((currentFunction->ReturnType % 0x1000)/0x100)) args_ok = 0; /* eliminate unsigned char * and unsigned short * */ if (currentFunction->ReturnType % 0x1000 == 0x314) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x315) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x316) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31A) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31B) args_ok = 0; if (currentFunction->ReturnType % 0x1000 == 0x31C) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == 0x5000) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 == 0x3)&& (currentFunction->ArgCounts[i] <= 0)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&& (currentFunction->ArgTypes[i] % 0x1000 != 0x303)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (currentFunction->ReturnType % 0x1000) { case 0x301: case 0x302: case 0x307: case 0x304: case 0x305: case 0x306: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E: case 0x313: args_ok = currentFunction->HaveHint; break; } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->ClassName) || !strcmp("vtkStructuredGridReader",data->ClassName) || !strcmp("vtkRectilinearGridReader",data->ClassName) || !strcmp("vtkUnstructuredGridReader",data->ClassName) || !strcmp("vtkStructuredPointsReader",data->ClassName) || !strcmp("vtkPolyDataReader",data->ClassName))) { HandleDataReader(fp,data); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->ClassName,currentFunction->Name) && strcmp(data->ClassName, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result_native(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",currentFunction->Name); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } /* if returning object, lookup in global hash */ if (currentFunction->ReturnType % 0x1000 == 0x109 || currentFunction->ReturnType % 0x1000 == 0x309) { fprintf(fp,") {"); fprintf(fp,"\n long temp = %s_%i(",currentFunction->Name, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,");\n"); fprintf(fp,"\n if (temp == 0) return null;"); fprintf(fp,"\n %s obj = null;", currentFunction->ReturnClass); fprintf(fp,"\n java.lang.ref.WeakReference ref = (java.lang.ref.WeakReference)vtkGlobalJavaHash.PointerToReference.get(new Long(temp));"); fprintf(fp,"\n if (ref != null) {"); fprintf(fp,"\n obj = (%s)ref.get();", currentFunction->ReturnClass); fprintf(fp,"\n }"); fprintf(fp,"\n if (obj == null) {"); fprintf(fp,"\n %s tempObj = new %s(temp);", currentFunction->ReturnClass, currentFunction->ReturnClass); fprintf(fp,"\n String className = tempObj.GetClassName();"); fprintf(fp,"\n try {"); fprintf(fp,"\n Class c = Class.forName(\"vtk.\" + className);"); fprintf(fp,"\n java.lang.reflect.Constructor cons = c.getConstructor(new Class[] {long.class} );"); fprintf(fp,"\n obj = (%s)cons.newInstance(new Object[] {new Long(temp)});", currentFunction->ReturnClass); fprintf(fp,"\n } catch (Exception e) {"); fprintf(fp,"\n e.printStackTrace();"); fprintf(fp,"\n }"); fprintf(fp,"\n tempObj.Delete();"); fprintf(fp,"\n }"); fprintf(fp,"\n return obj;"); fprintf(fp,"\n }\n"); } else { /* if not void then need return otherwise none */ if (currentFunction->ReturnType % 0x1000 == 0x2) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } if ((currentFunction->NumberOfArguments == 1) && (currentFunction->ArgTypes[0] == 0x5000)) fprintf(fp,",id1"); fprintf(fp,"); }\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } }
void outputFunction(FILE *fp, ClassInfo *data) { int i; unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); int args_ok = checkFunctionSignature(data); /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->Name) || !strcmp("vtkStructuredGridReader",data->Name) || !strcmp("vtkRectilinearGridReader",data->Name) || !strcmp("vtkUnstructuredGridReader",data->Name) || !strcmp("vtkStructuredPointsReader",data->Name) || !strcmp("vtkPolyDataReader",data->Name))) { HandleDataReader(fp); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result_native(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",currentFunction->Name); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); /* ignore args after function pointer */ if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION) { break; } } /* if returning object, lookup in global hash */ if (rType == VTK_PARSE_VTK_OBJECT_PTR) { fprintf(fp,") {"); fprintf(fp,"\n long temp = %s_%i(",currentFunction->Name, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,");\n"); fprintf(fp,"\n if (temp == 0) return null;"); fprintf(fp,"\n return (%s)vtkObject.JAVA_OBJECT_MANAGER.getJavaObject(temp);", currentFunction->ReturnClass); fprintf(fp,"\n }\n"); } else { /* if not void then need return otherwise none */ if (rType == VTK_PARSE_VOID) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,"); }\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } }
void outputFunction(FILE *fp, ClassInfo *data) { static unsigned int supported_types[] = { VTK_PARSE_VOID, VTK_PARSE_BOOL, VTK_PARSE_FLOAT, VTK_PARSE_DOUBLE, VTK_PARSE_CHAR, VTK_PARSE_UNSIGNED_CHAR, VTK_PARSE_SIGNED_CHAR, VTK_PARSE_INT, VTK_PARSE_UNSIGNED_INT, VTK_PARSE_SHORT, VTK_PARSE_UNSIGNED_SHORT, VTK_PARSE_LONG, VTK_PARSE_UNSIGNED_LONG, VTK_PARSE_ID_TYPE, VTK_PARSE_UNSIGNED_ID_TYPE, VTK_PARSE_LONG_LONG, VTK_PARSE_UNSIGNED_LONG_LONG, VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64, VTK_PARSE_VTK_OBJECT, VTK_PARSE_STRING, 0 }; int i, j; int args_ok = 1; unsigned int rType = (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE); unsigned int aType = 0; unsigned int baseType = 0; /* some functions will not get wrapped no matter what else */ if (currentFunction->IsOperator || currentFunction->ArrayFailure || !currentFunction->IsPublic || !currentFunction->Name) { return; } /* NewInstance and SafeDownCast can not be wrapped because it is a (non-virtual) method which returns a pointer of the same type as the current pointer. Since all methods are virtual in Java, this looks like polymorphic return type. */ if (!strcmp("NewInstance",currentFunction->Name)) { return ; } if (!strcmp("SafeDownCast",currentFunction->Name)) { return ; } /* The unwrappable methods in Filtering/vtkInformation.c */ if (strcmp(data->Name, "vtkInformation") == 0 && currentFunction->IsLegacy) { return; } /* The GetInput() in vtkMapper cannot be overriden with a * different return type, Java doesn't allow this */ if (strcmp(data->Name, "vtkMapper") == 0 && strcmp(currentFunction->Name, "GetInput") == 0) { return; } /* check to see if we can handle the args */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); baseType = (aType & VTK_PARSE_BASE_TYPE); if (currentFunction->ArgTypes[i] != VTK_PARSE_FUNCTION) { for (j = 0; supported_types[j] != 0; j++) { if (baseType == supported_types[j]) { break; } } if (supported_types[j] == 0) { args_ok = 0; } } if (baseType == VTK_PARSE_OBJECT) { if ((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) { args_ok = 0; } else if (hierarchyInfo) { if (vtkParseHierarchy_IsExtern(hierarchyInfo, currentFunction->ArgClasses[i]) || vtkParseHierarchy_GetProperty(hierarchyInfo, currentFunction->ArgClasses[i], "WRAP_EXCLUDE") || !vtkParseHierarchy_IsTypeOf(hierarchyInfo, currentFunction->ArgClasses[i], "vtkObjectBase")) { args_ok = 0; } } } if (aType == VTK_PARSE_VTK_OBJECT) args_ok = 0; if (((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((aType & VTK_PARSE_INDIRECT) != 0) && (aType != VTK_PARSE_STRING_REF)) args_ok = 0; if (aType == VTK_PARSE_STRING_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_CHAR_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0; if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0; } baseType = (rType & VTK_PARSE_BASE_TYPE); for (j = 0; supported_types[j] != 0; j++) { if (baseType == supported_types[j]) { break; } } if (supported_types[j] == 0) { args_ok = 0; } if (baseType == VTK_PARSE_OBJECT) { if ((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) { args_ok = 0; } else if (hierarchyInfo) { if (vtkParseHierarchy_IsExtern(hierarchyInfo, currentFunction->ReturnClass) || vtkParseHierarchy_GetProperty(hierarchyInfo, currentFunction->ReturnClass, "WRAP_EXCLUDE") || !vtkParseHierarchy_IsTypeOf(hierarchyInfo, currentFunction->ReturnClass, "vtkObjectBase")) { args_ok = 0; } } } if (((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) && ((rType & VTK_PARSE_INDIRECT) != 0) && (rType != VTK_PARSE_STRING_REF)) args_ok = 0; if (rType == VTK_PARSE_STRING_PTR) args_ok = 0; /* eliminate unsigned char * and unsigned short * */ if (rType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0; if (rType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0; if (currentFunction->NumberOfArguments && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION) &&(currentFunction->NumberOfArguments != 1)) args_ok = 0; /* make sure we have all the info we need for array arguments in */ for (i = 0; i < currentFunction->NumberOfArguments; i++) { aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE); if (((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER)&& (currentFunction->ArgCounts[i] <= 0)&& (aType != VTK_PARSE_VTK_OBJECT_PTR)&& (aType != VTK_PARSE_CHAR_PTR)) args_ok = 0; } /* if we need a return type hint make sure we have one */ switch (rType) { case VTK_PARSE_FLOAT_PTR: case VTK_PARSE_VOID_PTR: case VTK_PARSE_DOUBLE_PTR: case VTK_PARSE_INT_PTR: case VTK_PARSE_SHORT_PTR: case VTK_PARSE_LONG_PTR: case VTK_PARSE_ID_TYPE_PTR: case VTK_PARSE_LONG_LONG_PTR: case VTK_PARSE___INT64_PTR: case VTK_PARSE_SIGNED_CHAR_PTR: case VTK_PARSE_BOOL_PTR: case VTK_PARSE_UNSIGNED_CHAR_PTR: args_ok = currentFunction->HaveHint; break; } /* make sure there isn't a Java-specific override */ if (!strcmp("vtkObject",data->Name)) { /* remove the original vtkCommand observer methods */ if (!strcmp(currentFunction->Name,"AddObserver") || !strcmp(currentFunction->Name,"GetCommand") || (!strcmp(currentFunction->Name,"RemoveObserver") && (currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG)) || ((!strcmp(currentFunction->Name,"RemoveObservers") || !strcmp(currentFunction->Name,"HasObserver")) && (((currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG) && (currentFunction->ArgTypes[0] != (VTK_PARSE_CHAR_PTR|VTK_PARSE_CONST))) || (currentFunction->NumberOfArguments > 1))) || (!strcmp(currentFunction->Name,"RemoveAllObservers") && (currentFunction->NumberOfArguments > 0))) { args_ok = 0; } } else if (!strcmp("vtkObjectBase",data->Name)) { /* remove the special vtkObjectBase methods */ if (!strcmp(currentFunction->Name,"PrintRevisions") || !strcmp(currentFunction->Name,"Print")) { args_ok = 0; } } /* make sure it isn't a Delete or New function */ if (!strcmp("Delete",currentFunction->Name) || !strcmp("New",currentFunction->Name)) { args_ok = 0; } /* handle DataReader SetBinaryInputString as a special case */ if (!strcmp("SetBinaryInputString",currentFunction->Name) && (!strcmp("vtkDataReader",data->Name) || !strcmp("vtkStructuredGridReader",data->Name) || !strcmp("vtkRectilinearGridReader",data->Name) || !strcmp("vtkUnstructuredGridReader",data->Name) || !strcmp("vtkStructuredPointsReader",data->Name) || !strcmp("vtkPolyDataReader",data->Name))) { HandleDataReader(fp,data); wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } if (currentFunction->IsPublic && args_ok && strcmp(data->Name,currentFunction->Name) && strcmp(data->Name, currentFunction->Name + 1)) { /* make sure we haven't already done one of these */ if (!DoneOne()) { fprintf(fp,"\n private native "); return_result_native(fp); fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } fprintf(fp,");\n"); fprintf(fp," public "); return_result(fp); fprintf(fp,"%s(",currentFunction->Name); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } output_temp(fp,i); } /* if returning object, lookup in global hash */ if (rType == VTK_PARSE_VTK_OBJECT_PTR) { fprintf(fp,") {"); fprintf(fp,"\n long temp = %s_%i(",currentFunction->Name, numberOfWrappedFunctions); for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } fprintf(fp,");\n"); fprintf(fp,"\n if (temp == 0) return null;"); fprintf(fp,"\n %s obj = null;", currentFunction->ReturnClass); fprintf(fp,"\n java.lang.ref.WeakReference ref = (java.lang.ref.WeakReference)vtkGlobalJavaHash.PointerToReference.get(new Long(temp));"); fprintf(fp,"\n if (ref != null) {"); fprintf(fp,"\n obj = (%s)ref.get();", currentFunction->ReturnClass); fprintf(fp,"\n }"); fprintf(fp,"\n if (obj == null) {"); fprintf(fp,"\n %s tempObj = new %s(temp);", currentFunction->ReturnClass, currentFunction->ReturnClass); fprintf(fp,"\n String className = tempObj.GetClassName();"); fprintf(fp,"\n try {"); fprintf(fp,"\n Class c = Class.forName(\"vtk.\" + className);"); fprintf(fp,"\n java.lang.reflect.Constructor cons = c.getConstructor(new Class[] {long.class} );"); fprintf(fp,"\n obj = (%s)cons.newInstance(new Object[] {new Long(temp)});", currentFunction->ReturnClass); fprintf(fp,"\n } catch (Exception e) {"); fprintf(fp,"\n e.printStackTrace();"); fprintf(fp,"\n }"); fprintf(fp,"\n vtkObjectBase.VTKDeleteReference(temp);"); fprintf(fp,"\n }"); fprintf(fp,"\n return obj;"); fprintf(fp,"\n }\n"); } else { /* if not void then need return otherwise none */ if (rType == VTK_PARSE_VOID) { fprintf(fp,")\n { %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } else { fprintf(fp,")\n { return %s_%i(",currentFunction->Name, numberOfWrappedFunctions); } for (i = 0; i < currentFunction->NumberOfArguments; i++) { if (i) { fprintf(fp,","); } fprintf(fp,"id%i",i); } if ((currentFunction->NumberOfArguments == 1) && (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)) { fprintf(fp,",id1"); } fprintf(fp,"); }\n"); } wrappedFunctions[numberOfWrappedFunctions] = currentFunction; numberOfWrappedFunctions++; } } }