/* 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); } }
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); } }