/* Write the code to convert one argument with vtkPythonArgs */ void vtkWrapPython_GetSingleArgument( FILE *fp, ClassInfo *data, int i, ValueInfo *arg, int static_call) { const char *prefix = "ap."; const char *cp; char argname[32]; char pythonname[1024]; size_t l; argname[0] = '\0'; if (static_call) { prefix = "vtkPythonArgs::"; sprintf(argname, "arg%d, ", i); } if (vtkWrap_IsEnumMember(data, arg)) { fprintf(fp, "%sGetEnumValue(%stemp%d, \"%s.%s\")", prefix, argname, i, data->Name, arg->Class); } else if (arg->IsEnum) { cp = arg->Class; for (l = 0; cp[l] != '\0'; l++) { if (cp[l] == ':') { break; } } if (cp[l] == ':' && cp[l+1] == ':') { fprintf(fp, "%sGetEnumValue(%stemp%d, \"%*.*s.%s\")", prefix, argname, i, (int)l, (int)l, cp, &cp[l+2]); } else { fprintf(fp, "%sGetEnumValue(%stemp%d, \"%s\")", prefix, argname, i, cp); } } else if (vtkWrap_IsPythonObject(arg)) { fprintf(fp, "%s%sGetPythonObject(temp%d)", prefix, argname, i); } else if (vtkWrap_IsVTKObject(arg)) { vtkWrapText_PythonName(arg->Class, pythonname); if (strcmp(arg->Class, pythonname) != 0) { /* use typeid() for templated names */ fprintf(fp, "%sGetVTKObject(%stemp%d, typeid(%s).name())", prefix, argname, i, arg->Class); } else { fprintf(fp, "%sGetVTKObject(%stemp%d, \"%s\")", prefix, argname, i, pythonname); } } else if (vtkWrap_IsSpecialObject(arg) && !vtkWrap_IsNonConstRef(arg)) { vtkWrapText_PythonName(arg->Class, pythonname); fprintf(fp, "%sGetSpecialObject(%stemp%d, pobj%d, \"%s\")", prefix, argname, i, i, pythonname); } else if (vtkWrap_IsSpecialObject(arg) && vtkWrap_IsNonConstRef(arg)) { vtkWrapText_PythonName(arg->Class, pythonname); fprintf(fp, "%sGetSpecialObject(%stemp%d, \"%s\")", prefix, argname, i, pythonname); } else if (vtkWrap_IsQtEnum(arg)) { fprintf(fp, "%sGetSIPEnumValue(%stemp%d, \"%s\")", prefix, argname, i, arg->Class); } else if (vtkWrap_IsQtObject(arg)) { fprintf(fp, "%sGetSIPObject(%stemp%d, \"%s\")", prefix, argname, i, arg->Class); } else if (vtkWrap_IsFunction(arg)) { fprintf(fp, "%sGetFunction(%stemp%d)", prefix, argname, i); } else if (vtkWrap_IsVoidPointer(arg)) { fprintf(fp, "%sGetBuffer(%stemp%d, &pbuf%d)", prefix, argname, i, i); } else if (vtkWrap_IsString(arg) || vtkWrap_IsCharPointer(arg)) { fprintf(fp, "%sGetValue(%stemp%d)", prefix, argname, i); } else if (vtkWrap_IsNumeric(arg) && vtkWrap_IsScalar(arg)) { fprintf(fp, "%sGetValue(%stemp%d)", prefix, argname, i); } else if (vtkWrap_IsNArray(arg)) { fprintf(fp, "%sGetNArray(%s%.*stemp%d, %d, size%d)", prefix, argname, (int)(arg->NumberOfDimensions-1), "**********", i, arg->NumberOfDimensions, i); } else if (vtkWrap_IsArray(arg)) { fprintf(fp, "%sGetArray(%stemp%d, size%d)", prefix, argname, i, i); } else if (vtkWrap_IsPODPointer(arg)) { fprintf(fp, "%sGetArray(%stemp%d, size%d)", prefix, argname, i, i); } }
/* 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()"; } } } }
int vtkWrap_IsPODPointer(ValueInfo *val) { unsigned int t = (val->Type & VTK_PARSE_BASE_TYPE); return (t != VTK_PARSE_CHAR && vtkWrap_IsNumeric(val) && vtkWrap_IsPointer(val)); }
void vtkWrapPython_AddPublicConstants( FILE *fp, const char *indent, const char *dictvar, const char *objvar, NamespaceInfo *data) { const char *nextindent = " "; ValueInfo *val; ValueInfo *firstval; const char *scope; int scopeType, scopeValue; unsigned int valtype; const char *typeName; const char *tname; int j = 0; int count, k, i; size_t l, m; /* get the next indent to use */ l = strlen(indent); m = strlen(nextindent); if (m > l + 2) { nextindent += m - l - 2; } /* get the name of the namespace, or NULL if global */ scope = data->Name; if (scope && scope[0] == '\0') { scope = 0; } /* go through the constants, collecting them by type */ while (j < data->NumberOfConstants) { val = data->Constants[j]; if (val->Access != VTK_ACCESS_PUBLIC) { j++; continue; } /* write a single constant if not numerical */ if (j+1 == data->NumberOfConstants || val->Type != data->Constants[j+1]->Type || !vtkWrap_IsScalar(val) || (!val->IsEnum && !vtkWrap_IsNumeric(val))) { vtkWrapPython_AddConstant( fp, indent, dictvar, objvar, scope, val); j++; continue; } /* get important information about the value */ valtype = val->Type; typeName = (val->IsEnum ? val->Class : vtkWrap_GetTypeName(val)); scopeType = (scope && val->IsEnum && strcmp(typeName, "int") != 0); scopeValue = (scope && val->IsEnum); /* count a series of constants of the same type */ firstval = val; count = 0; for (k = j; k < data->NumberOfConstants; k++) { val = data->Constants[k]; if (val->Access == VTK_ACCESS_PUBLIC) { tname = (val->IsEnum ? val->Class : vtkWrap_GetTypeName(val)); if (val->Type != valtype || strcmp(tname, typeName) != 0) { break; } count++; } } /* if no constants to generate, then continue */ if (count == 0) { j = k; continue; } /* check to make sure there won't be a name conflict between an enum type and some other class member, it happens specifically for vtkImplicitBoolean which has a variable and enum type both with the name OperationType */ if (scopeType) { int conflict = 0; for (i = 0; i < data->NumberOfVariables && !conflict; i++) { conflict = (strcmp(data->Variables[i]->Name, typeName) == 0); } if (conflict) { valtype = VTK_PARSE_INT; typeName = "int"; scopeType = 0; } } /* generate the code */ fprintf(fp, "%sfor (int c = 0; c < %d; c++)\n" "%s {\n", indent, count, indent); if (scopeType) { fprintf(fp, "%s typedef %s::%s cxx_enum_type;\n\n", indent, scope, typeName); } fprintf(fp, "%s static const struct { const char *name; %s value; }\n" "%s constants[%d] = {\n", indent, (scopeType ? "cxx_enum_type" : typeName), indent, count); while (j < k) { val = data->Constants[j++]; if (val->Access == VTK_ACCESS_PUBLIC) { fprintf(fp, "%s { \"%s\", %s%s%s },\n", indent, val->Name, (scopeValue ? scope : ""), (scopeValue ? "::" : ""), (val->IsEnum ? val->Name : val->Value)); } } fprintf(fp, "%s };\n" "\n", indent); vtkWrapPython_AddConstantHelper( fp, nextindent, dictvar, objvar, scope, "constants[c].name", "constants[c].value", firstval); fprintf(fp, "%s }\n\n", indent); } }