/* generate the code that calls the C++ method */ static void vtkWrapPython_GenerateMethodCall( FILE *fp, FunctionInfo *currentFunction, ClassInfo *data, HierarchyInfo *hinfo, int is_vtkobject) { char methodname[256]; ValueInfo *arg; int totalArgs; int is_constructor; int i, k, n; totalArgs = vtkWrap_CountWrappedParameters(currentFunction); is_constructor = vtkWrap_IsConstructor(data, currentFunction); /* for vtkobjects, do a bound call and an unbound call */ n = 1; if (is_vtkobject && !currentFunction->IsStatic && !currentFunction->IsPureVirtual && !is_constructor) { n = 2; } if (!is_constructor && !vtkWrap_IsVoid(currentFunction->ReturnValue)) { /* temp variable for C++-type return value */ fprintf(fp, " "); vtkWrap_DeclareVariable(fp, data, currentFunction->ReturnValue, "tempr", -1, VTK_WRAP_RETURN | VTK_WRAP_NOSEMI); fprintf(fp, " ="); } /* handle both bound and unbound calls */ if (n == 2) { if (!is_constructor && !vtkWrap_IsVoid(currentFunction->ReturnValue)) { fprintf(fp, " (ap.IsBound() ?\n" " "); } else { fprintf(fp, " if (ap.IsBound())\n" " {\n" " "); } } /* print the code that calls the method */ for (k = 0; k < n; k++) { if (k == 1) { /* unbound method call */ sprintf(methodname, "op->%s::%s", data->Name, currentFunction->Name); } else if (currentFunction->IsStatic) { /* static method call */ sprintf(methodname, "%s::%s", data->Name, currentFunction->Name); } else if (is_constructor) { /* constructor call */ sprintf(methodname, "new %s", currentFunction->Name); } else { /* standard bound method call */ sprintf(methodname, "op->%s", currentFunction->Name); } if (is_constructor) { fprintf(fp, " %s *op = new %s(", data->Name, data->Name); } else if (vtkWrap_IsVoid(currentFunction->ReturnValue)) { fprintf(fp, " %s(", methodname); } else if (vtkWrap_IsRef(currentFunction->ReturnValue)) { fprintf(fp, " &%s(", methodname); } else { fprintf(fp, " %s(", methodname); } /* print all the arguments in the call */ for (i = 0; i < totalArgs; i++) { arg = currentFunction->Parameters[i]; if (vtkWrap_IsFunction(arg)) { fprintf(fp,"\n" " (temp%d == Py_None ? NULL : vtkPythonVoidFunc),\n" " (temp%d == Py_None ? NULL : temp%d));\n", i, i, i); fprintf(fp, " if (temp%d != Py_None)\n" " {\n" " Py_INCREF(temp%d);\n" " }\n" " %sArgDelete(\n" " (temp%d == Py_None ? NULL : vtkPythonVoidFuncArgDelete)", i, i, methodname, i); break; } if (i) { fprintf(fp,", "); } if ((vtkWrap_IsSpecialObject(arg) || vtkWrap_IsQtObject(arg)) && !vtkWrap_IsPointer(arg)) { fprintf(fp, "*temp%i", i); } else { fprintf(fp, "temp%i", i); } } fprintf(fp, ")"); /* handle ternary operator for ap.IsBound() */ if (n == 2) { if (!is_constructor && !vtkWrap_IsVoid(currentFunction->ReturnValue)) { fprintf(fp, (k == 0 ? " :\n " : ");\n")); } else if (k == 0) { fprintf(fp, ";\n" " }\n" " else\n" " {\n" " "); } else { fprintf(fp, ";\n" " }\n"); } } else { fprintf(fp, ";\n"); } } if (is_constructor) { /* initialize tuples created with default constructor */ if (currentFunction->NumberOfParameters == 0 && hinfo) { n = vtkWrap_GetTupleSize(data, hinfo); for (i = 0; i < n; i++) { fprintf(fp, " (*op)[%d] = 0;\n", i); } } } fprintf(fp, "\n"); }
/* This sets the CountHint for vtkDataArray methods where the * tuple size is equal to GetNumberOfComponents. */ void vtkWrap_FindCountHints( ClassInfo *data, FileInfo *finfo, HierarchyInfo *hinfo) { int i; int count; const char *countMethod; FunctionInfo *theFunc; /* add hints for vtkInformation get methods */ if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkInformation")) { countMethod = "Length(temp0)"; for (i = 0; i < data->NumberOfFunctions; i++) { theFunc = data->Functions[i]; if (strcmp(theFunc->Name, "Get") == 0 && theFunc->NumberOfParameters >= 1 && theFunc->Parameters[0]->Type == VTK_PARSE_OBJECT_PTR && (strcmp(theFunc->Parameters[0]->Class, "vtkInformationIntegerVectorKey") == 0 || strcmp(theFunc->Parameters[0]->Class, "vtkInformationDoubleVectorKey") == 0)) { if (theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 && theFunc->NumberOfParameters == 1) { theFunc->ReturnValue->CountHint = countMethod; } } } } /* add hints for array GetTuple methods */ if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkDataArray")) { countMethod = "GetNumberOfComponents()"; for (i = 0; i < data->NumberOfFunctions; i++) { theFunc = data->Functions[i]; if ((strcmp(theFunc->Name, "GetTuple") == 0 || strcmp(theFunc->Name, "GetTupleValue") == 0) && theFunc->ReturnValue && theFunc->ReturnValue->Count == 0 && theFunc->NumberOfParameters == 1 && theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE) { theFunc->ReturnValue->CountHint = countMethod; } else if ((strcmp(theFunc->Name, "SetTuple") == 0 || strcmp(theFunc->Name, "SetTupleValue") == 0 || strcmp(theFunc->Name, "GetTuple") == 0 || strcmp(theFunc->Name, "GetTupleValue") == 0 || strcmp(theFunc->Name, "InsertTuple") == 0 || strcmp(theFunc->Name, "InsertTupleValue") == 0) && theFunc->NumberOfParameters == 2 && theFunc->Parameters[0]->Type == VTK_PARSE_ID_TYPE && theFunc->Parameters[1]->Count == 0) { theFunc->Parameters[1]->CountHint = countMethod; } else if ((strcmp(theFunc->Name, "InsertNextTuple") == 0 || strcmp(theFunc->Name, "InsertNextTupleValue") == 0) && theFunc->NumberOfParameters == 1 && theFunc->Parameters[0]->Count == 0) { theFunc->Parameters[0]->CountHint = countMethod; } } } /* add hints for interpolator Interpolate methods */ if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkAbstractImageInterpolator")) { countMethod = "GetNumberOfComponents()"; for (i = 0; i < data->NumberOfFunctions; i++) { theFunc = data->Functions[i]; if (strcmp(theFunc->Name, "Interpolate") == 0 && theFunc->NumberOfParameters == 2 && theFunc->Parameters[0]->Type == (VTK_PARSE_DOUBLE_PTR|VTK_PARSE_CONST) && theFunc->Parameters[0]->Count == 3 && theFunc->Parameters[1]->Type == VTK_PARSE_DOUBLE_PTR && theFunc->Parameters[1]->Count == 0) { theFunc->Parameters[1]->CountHint = countMethod; } } } for (i = 0; i < data->NumberOfFunctions; i++) { theFunc = data->Functions[i]; /* hints for constructors that take arrays */ if (vtkWrap_IsConstructor(data, theFunc) && theFunc->NumberOfParameters == 1 && vtkWrap_IsPointer(theFunc->Parameters[0]) && vtkWrap_IsNumeric(theFunc->Parameters[0]) && theFunc->Parameters[0]->Count == 0 && hinfo) { count = vtkWrap_GetTupleSize(data, hinfo); if (count) { char counttext[24]; sprintf(counttext, "%d", count); theFunc->Parameters[0]->Count = count; vtkParse_AddStringToArray( &theFunc->Parameters[0]->Dimensions, &theFunc->Parameters[0]->NumberOfDimensions, vtkParse_CacheString(finfo->Strings, counttext, strlen(counttext))); } } /* hints for operator[] index range */ if (theFunc->IsOperator && theFunc->Name && strcmp(theFunc->Name, "operator[]") == 0) { if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkTuple")) { theFunc->SizeHint = "GetSize()"; } else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayCoordinates") || vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtents") || vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArraySort")) { theFunc->SizeHint = "GetDimensions()"; } else if (vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayExtentsList") || vtkWrap_IsTypeOf(hinfo, data->Name, "vtkArrayWeights")) { theFunc->SizeHint = "GetCount()"; } } } }