示例#1
0
/* print the parsed structures */
int main(int argc, char *argv[])
{
  OptionInfo *options;
  FileInfo *file_info;
  ClassInfo *data;
  FILE *fp;
  int i;

  /* pre-define a macro to identify the language */
  vtkParse_DefineMacro("__VTK_WRAP_JAVA__", 0);

  /* get command-line args and parse the header file */
  file_info = vtkParse_Main(argc, argv);

  /* some utility functions require the string cache */
  stringCache = file_info->Strings;

  /* get the command-line options */
  options = vtkParse_GetCommandLineOptions();

  /* get the output file */
  fp = fopen(options->OutputFileName, "w");

  if (!fp)
  {
    fprintf(stderr, "Error opening output file %s\n", options->OutputFileName);
    exit(1);
  }

  /* get the main class */
  if ((data = file_info->MainClass) == NULL)
  {
    fclose(fp);
    exit(1);
  }

  /* get the hierarchy info for accurate typing */
  if (options->HierarchyFileNames)
  {
    hierarchyInfo = vtkParseHierarchy_ReadFiles(
      options->NumberOfHierarchyFileNames, options->HierarchyFileNames);
    if (hierarchyInfo)
    {
      /* resolve using declarations within the header files */
      vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo);

      /* expand typedefs */
      vtkWrap_ExpandTypedefs(data, file_info, hierarchyInfo);
    }
  }

  fprintf(fp,"// java wrapper for %s object\n//\n",data->Name);
  fprintf(fp,"#define VTK_WRAPPING_CXX\n");
  if (strcmp("vtkObjectBase",data->Name) != 0)
  {
    /* Block inclusion of full streams.  */
    fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n");
  }
  fprintf(fp,"#include \"vtkSystemIncludes.h\"\n");
  fprintf(fp,"#include \"%s.h\"\n",data->Name);
  fprintf(fp,"#include \"vtkJavaUtil.h\"\n\n");
  fprintf(fp,"#include \"vtkStdString.h\"\n\n");
  fprintf(fp,"#include <sstream>\n");

  for (i = 0; i < data->NumberOfSuperClasses; i++)
  {
    char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
    const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];

    /* if a template class is detected add a typedef */
    if (safe_name)
    {
      fprintf(fp,"typedef %s %s;\n",
              data->SuperClasses[i], safe_name);
    }

    fprintf(fp,"extern \"C\" JNIEXPORT void* %s_Typecast(void *op,char *dType);\n",
            safe_superclass);

    free(safe_name);
  }

  fprintf(fp,"\nextern \"C\" JNIEXPORT void* %s_Typecast(void *me,char *dType)\n{\n",data->Name);
  if (data->NumberOfSuperClasses > 0)
  {
    fprintf(fp,"  void* res;\n");
  }
  fprintf(fp,"  if (!strcmp(\"%s\",dType)) { return me; }\n", data->Name);
  /* check our superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
  {
    char *safe_name = vtkWrap_SafeSuperclassName(data->SuperClasses[i]);
    const char *safe_superclass = safe_name ? safe_name : data->SuperClasses[i];

    fprintf(fp,"  if ((res= %s_Typecast(me,dType)) != NULL)",
            safe_superclass);
    fprintf(fp," { return res; }\n");

    free(safe_name);
  }
  fprintf(fp,"  return NULL;\n");
  fprintf(fp,"}\n\n");

  HandleDataArray(fp, data);

  /* insert function handling code here */
  for (i = 0; i < data->NumberOfFunctions; i++)
  {
    currentFunction = data->Functions[i];
    outputFunction(fp, data);
  }

  if ((!data->NumberOfSuperClasses)&&(data->HasDelete))
  {
    fprintf(fp,"\nextern \"C\" JNIEXPORT void JNICALL Java_vtk_%s_VTKDeleteReference(JNIEnv *,jclass,jlong id)\n",
            data->Name);
    fprintf(fp,"{\n  %s *op;\n",data->Name);
    fprintf(fp,"  op = reinterpret_cast<%s*>(id);\n",
            data->Name);
    fprintf(fp,"  op->Delete();\n");
    fprintf(fp,"}\n");

    fprintf(fp,"\nextern \"C\" JNIEXPORT jstring JNICALL Java_vtk_%s_VTKGetClassNameFromReference(JNIEnv *env,jclass,jlong id)\n",
            data->Name);
    fprintf(fp,"{\n");
    fprintf(fp,"  const char* name = \"\";\n");
    fprintf(fp,"  %s *op;\n", data->Name);
    fprintf(fp,"  if(id != 0)\n");
    fprintf(fp,"  {\n");
    fprintf(fp,"    op = reinterpret_cast<%s*>(id);\n", data->Name);
    //fprintf(fp,"    std::cout << \"cast pointer \" << id << std::endl;\n");
    fprintf(fp,"    name = op->GetClassName();\n");
    fprintf(fp,"  }\n");
    fprintf(fp,"  return vtkJavaMakeJavaString(env,name);\n");
    fprintf(fp,"}\n");

    fprintf(fp,"\nextern \"C\" JNIEXPORT void JNICALL Java_vtk_%s_VTKDelete(JNIEnv *env,jobject obj)\n",
            data->Name);
    fprintf(fp,"{\n  %s *op;\n",data->Name);
    fprintf(fp,"  op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n",
            data->Name);
    fprintf(fp,"  op->Delete();\n");
    fprintf(fp,"}\n");

    fprintf(fp,"\nextern \"C\" JNIEXPORT void JNICALL Java_vtk_%s_VTKRegister(JNIEnv *env,jobject obj)\n",
            data->Name);
    fprintf(fp,"{\n  %s *op;\n",data->Name);
    fprintf(fp,"  op = (%s *)vtkJavaGetPointerFromObject(env,obj);\n",
            data->Name);
    fprintf(fp,"  op->Register(op);\n");
    fprintf(fp,"}\n");
  }
  if (!data->IsAbstract)
  {
    fprintf(fp,"\nextern \"C\" JNIEXPORT jlong JNICALL Java_vtk_%s_VTKInit(JNIEnv *, jobject)",
            data->Name);
    fprintf(fp,"\n{");
    fprintf(fp,"\n  %s *aNewOne = %s::New();",data->Name, data->Name);
    fprintf(fp,"\n  return (jlong)(size_t)(void*)aNewOne;");
    fprintf(fp,"\n}\n");
  }

  /* for vtkRenderWindow we want to add a special method to support
   * native AWT rendering
   *
   * Including vtkJavaAwt.h provides inline implementations of
   * Java_vtk_vtkPanel_RenderCreate, Java_vtk_vtkPanel_Lock and
   * Java_vtk_vtkPanel_UnLock. */
  if (!strcmp("vtkRenderWindow",data->Name))
  {
    fprintf(fp,"\n#include \"vtkJavaAwt.h\"\n\n");
  }

  if (!strcmp("vtkObject",data->Name))
  {
    /* Add the Print method to vtkObjectBase. */
    fprintf(fp,"\nextern \"C\" JNIEXPORT jstring JNICALL Java_vtk_vtkObjectBase_Print(JNIEnv *env,jobject obj)\n");
    fprintf(fp,"{\n  vtkObjectBase *op;\n");
    fprintf(fp,"  jstring tmp;\n\n");
    fprintf(fp,"  op = (vtkObjectBase *)vtkJavaGetPointerFromObject(env,obj);\n");

    fprintf(fp,"  std::ostringstream vtkmsg_with_warning_C4701;\n");
    fprintf(fp,"  op->Print(vtkmsg_with_warning_C4701);\n");
    fprintf(fp,"  vtkmsg_with_warning_C4701.put('\\0');\n");
    fprintf(fp,"  tmp = vtkJavaMakeJavaString(env,vtkmsg_with_warning_C4701.str().c_str());\n");

    fprintf(fp,"  return tmp;\n");
    fprintf(fp,"}\n");

    fprintf(fp,"\nextern \"C\" JNIEXPORT jint JNICALL Java_vtk_vtkObject_AddObserver(JNIEnv *env,jobject obj, jstring id0, jobject id1, jstring id2)\n");
    fprintf(fp,"{\n  vtkObject *op;\n");

    fprintf(fp,"  vtkJavaCommand *cbc = vtkJavaCommand::New();\n");
    fprintf(fp,"  cbc->AssignJavaVM(env);\n");
    fprintf(fp,"  cbc->SetGlobalRef(env->NewGlobalRef(id1));\n");
    fprintf(fp,"  char    *temp2;\n");
    fprintf(fp,"  temp2 = vtkJavaUTFToChar(env,id2);\n");
    fprintf(fp,"  cbc->SetMethodID(env->GetMethodID(env->GetObjectClass(id1),temp2,\"()V\"));\n");
    fprintf(fp,"  char    *temp0;\n");
    fprintf(fp,"  temp0 = vtkJavaUTFToChar(env,id0);\n");
    fprintf(fp,"  op = (vtkObject *)vtkJavaGetPointerFromObject(env,obj);\n");
    fprintf(fp,"  unsigned long     temp20;\n");
    fprintf(fp,"  temp20 = op->AddObserver(temp0,cbc);\n");
    fprintf(fp,"  delete[] temp0;\n");
    fprintf(fp,"  delete[] temp2;\n");
    fprintf(fp,"  cbc->Delete();\n");
    fprintf(fp,"  return temp20;\n}\n");
  }

  vtkParse_Free(file_info);

  fclose(fp);

  return 0;
}
示例#2
0
/* print the parsed structures */
int main(int argc, char *argv[])
{
  OptionInfo *options;
  FileInfo *file_info;
  ClassInfo *data;
  FILE *fp;
  int i;

  /* pre-define a macro to identify the language */
  vtkParse_DefineMacro("__VTK_WRAP_JAVA__", 0);

  /* get command-line args and parse the header file */
  file_info = vtkParse_Main(argc, argv);

  /* some utility functions require the string cache */
  stringCache = file_info->Strings;

  /* get the command-line options */
  options = vtkParse_GetCommandLineOptions();

  /* get the hierarchy info for accurate typing */
  if (options->HierarchyFileNames)
  {
    hierarchyInfo = vtkParseHierarchy_ReadFiles(
      options->NumberOfHierarchyFileNames, options->HierarchyFileNames);
  }

  /* get the output file */
  fp = fopen(options->OutputFileName, "w");

  if (!fp)
  {
    fprintf(stderr, "Error opening output file %s\n", options->OutputFileName);
    exit(1);
  }

  /* get the main class */
  data = file_info->MainClass;
  if (data == NULL || data->IsExcluded)
  {
    fclose(fp);
    exit(0);
  }

  if (data->Template)
  {
    fclose(fp);
    exit(0);
  }

  for (i = 0; i < data->NumberOfSuperClasses; ++i)
  {
    if (strchr(data->SuperClasses[i], '<'))
    {
      fclose(fp);
      exit(0);
    }
  }

  if (hierarchyInfo)
  {
    if (!vtkWrap_IsTypeOf(hierarchyInfo, data->Name, "vtkObjectBase"))
    {
      fclose(fp);
      exit(0);
    }

    /* resolve using declarations within the header files */
    vtkWrap_ApplyUsingDeclarations(data, file_info, hierarchyInfo);

    /* expand typedefs */
    vtkWrap_ExpandTypedefs(data, file_info, hierarchyInfo);
  }

  fprintf(fp,"// java wrapper for %s object\n//\n",data->Name);
  fprintf(fp,"\npackage vtk;\n");

  if (strcmp("vtkObjectBase",data->Name))
  {
    fprintf(fp,"import vtk.*;\n");
  }
  fprintf(fp,"\npublic class %s",data->Name);
  if (strcmp("vtkObjectBase",data->Name))
  {
    if (data->NumberOfSuperClasses)
    {
      fprintf(fp," extends %s",data->SuperClasses[0]);
    }
  }
  fprintf(fp,"\n{\n");

  /* insert function handling code here */
  for (i = 0; i < data->NumberOfFunctions; i++)
  {
    currentFunction = data->Functions[i];
    outputFunction(fp, data);
  }

  HandleDataArray(fp, data);

  if (!data->NumberOfSuperClasses)
  {
    if ( strcmp("vtkObjectBase",data->Name) == 0 )
    {
      fprintf(fp,"\n  public static vtk.vtkJavaMemoryManager JAVA_OBJECT_MANAGER = new vtk.vtkJavaMemoryManagerImpl();");
    }
    if (!data->IsAbstract)
    {
      fprintf(fp,"\n  public %s() {", data->Name);
      fprintf(fp,"\n    this.vtkId = this.VTKInit();");
      fprintf(fp,"\n    vtkObjectBase.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);");
      fprintf(fp,"\n}\n");
    }
    else
    {
      fprintf(fp,"\n  public %s() { super(); }\n",data->Name);
    }
    fprintf(fp,"\n  public %s(long id) {", data->Name);
    fprintf(fp,"\n    super();");
    fprintf(fp,"\n    this.vtkId = id;");
    fprintf(fp,"\n    this.VTKRegister();");
    fprintf(fp,"\n    vtkObjectBase.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this);");
    fprintf(fp,"\n}\n");
    fprintf(fp,"\n  protected long vtkId;\n");
    fprintf(fp,"\n  public long GetVTKId() { return this.vtkId; }");

    /* if we are a base class and have a delete method */
    if (data->HasDelete)
    {
      fprintf(fp,"\n  public static native void VTKDeleteReference(long id);");
      fprintf(fp,"\n  public static native String VTKGetClassNameFromReference(long id);");
      fprintf(fp,"\n  protected native void VTKDelete();");
      fprintf(fp,"\n  protected native void VTKRegister();");
      fprintf(fp,"\n  public void Delete() {");
      fprintf(fp,"\n    vtkObjectBase.JAVA_OBJECT_MANAGER.unRegisterJavaObject(this.vtkId);");
      fprintf(fp,"\n    this.vtkId = 0;");
      fprintf(fp,"\n  }");
    }
  }
  else
  {
    fprintf(fp,"\n  public %s() { super(); }\n",data->Name);
    fprintf(fp,"\n  public %s(long id) { super(id); }\n",data->Name);
  }

  if (!data->IsAbstract)
  {
    fprintf(fp,"  public native long   VTKInit();\n");
  }

  /* fprintf(fp,"  protected native void   VTKCastInit();\n"); */

  if (!strcmp("vtkObjectBase",data->Name))
  {
    /* Add the Print method to vtkObjectBase. */
    fprintf(fp,"  public native String Print();\n");
    /* Add the default toString from java object */
    fprintf(fp,"  public String toString() { return Print(); }\n");
  }

  if (!strcmp("vtkObject",data->Name))
  {
    fprintf(fp,"  public native int AddObserver(String id0, Object id1, String id2);\n");
  }
  fprintf(fp,"\n}\n");
  fclose(fp);
  {
  size_t cc;
  size_t len;
  char *dir;
  char *fname;
  /*const */char javaDone[] = "VTKJavaWrapped";
  FILE* tfp;
  fname = options->OutputFileName;
  dir = (char*)malloc(strlen(fname) + strlen(javaDone) + 2);
  sprintf(dir, "%s", fname);
  len = strlen(dir);
  for ( cc = len-1; cc > 0; cc -- )
  {
    if ( dir[cc] == '/' || dir[cc] == '\\' )
    {
      dir[cc+1] = 0;
      break;
    }
  }
  strcat(dir, javaDone);
  tfp = fopen(dir, "w");
  if ( tfp )
  {
    fprintf(tfp, "File: %s\n", fname);
    fclose(tfp);
  }
  free(dir);
  }

  vtkParse_Free(file_info);

  return 0;
}
示例#3
0
/* Check the options: "multi" should be zero for wrapper tools that
 * only take one input file, or one for wrapper tools that take multiple
 * input files.  Returns zero for "--version" or "--help", or returns -1
 * if an error occurred.  Otherwise, it returns the number of args
 * that were successfully parsed. */
static int parse_check_options(int argc, char *argv[], int multi)
{
  int i;
  size_t j;
  char *cp;
  char c;

  options.NumberOfFiles = 0;
  options.Files = NULL;
  options.InputFileName = NULL;
  options.OutputFileName = NULL;
  options.IsAbstract = 0;
  options.IsConcrete = 0;
  options.IsVTKObject = 0;
  options.IsSpecialObject = 0;
  options.HierarchyFileName = 0;
  options.HintFileName = 0;

  for (i = 1; i < argc; i++)
    {
    if (strcmp(argv[i], "--help") == 0)
      {
      parse_print_help(stdout, argv[0], multi);
      return 0;
      }
    else if (strcmp(argv[i], "--version") == 0)
      {
      const char *ver = VTK_PARSE_VERSION;
      fprintf(stdout, "%s %s\n", parse_exename(argv[0]), ver);
      return 0;
      }
    else if (argv[i][0] != '-')
      {
      if (options.NumberOfFiles == 0)
        {
        options.Files = (char **)malloc(sizeof(char *));
        }
      else if ((options.NumberOfFiles & (options.NumberOfFiles - 1)) == 0)
        {
        options.Files = (char **)realloc(
          options.Files, 2*options.NumberOfFiles*sizeof(char *));
        }
      options.Files[options.NumberOfFiles++] = argv[i];
      }
    else if (argv[i][0] == '-' && isalpha(argv[i][1]))
      {
      c = argv[i][1];
      cp = &argv[i][2];
      if (*cp == '\0')
        {
        i++;
        if (i >= argc || argv[i][0] == '-')
          {
          return -1;
          }
        cp = argv[i];
        }

      if (c == 'o')
        {
        options.OutputFileName = cp;
        }
      else if (c == 'I')
        {
        vtkParse_IncludeDirectory(cp);
        }
      else if (c == 'D')
        {
        j = 0;
        while (cp[j] != '\0' && cp[j] != '=') { j++; }
        if (cp[j] == '=') { j++; }
        vtkParse_DefineMacro(cp, &cp[j]);
        }
      else if (c == 'U')
        {
        vtkParse_UndefineMacro(cp);
        }
      }
    else if (!multi && strcmp(argv[i], "--hints") == 0)
      {
      i++;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      options.HintFileName = argv[i];
      }
    else if (!multi && strcmp(argv[i], "--types") == 0)
      {
      i++;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      options.HierarchyFileName = argv[i];
      }
    else if (!multi && strcmp(argv[i], "--vtkobject") == 0)
      {
      options.IsVTKObject = 1;
      }
    else if (!multi && strcmp(argv[i], "--special") == 0)
      {
      options.IsSpecialObject = 1;
      }
    }

  return i;
}
示例#4
0
int main(int argc, char *argv[])
{
  ClassInfo *wrappedClasses[MAX_WRAPPED_CLASSES];
  unsigned char wrapAsVTKObject[MAX_WRAPPED_CLASSES];
  ClassInfo *data = NULL;
  NamespaceInfo *contents;
  OptionInfo *options;
  HierarchyInfo *hinfo = NULL;
  FileInfo *file_info;
  FILE *fp;
  const char *module = "vtkCommonCore";
  const char *name;
  char *name_from_file = NULL;
  int numberOfWrappedClasses = 0;
  int numberOfWrappedNamespaces = 0;
  int wrapped_anything = 0;
  int i, j;
  size_t k, m;
  int is_vtkobject;

  /* pre-define a macro to identify the language */
  vtkParse_DefineMacro("__VTK_WRAP_PYTHON__", 0);

  /* get command-line args and parse the header file */
  file_info = vtkParse_Main(argc, argv);

  /* get the command-line options */
  options = vtkParse_GetCommandLineOptions();

  /* get the output file */
  fp = fopen(options->OutputFileName, "w");

  if (!fp)
  {
    fprintf(stderr, "Error opening output file %s\n", options->OutputFileName);
    exit(1);
  }

  /* get the hierarchy info for accurate typing */
  if (options->HierarchyFileNames)
  {
    hinfo = vtkParseHierarchy_ReadFiles(
      options->NumberOfHierarchyFileNames, options->HierarchyFileNames);
  }

  /* get the filename without the extension */
  name = file_info->FileName;
  m = strlen(name);
  for (k = m; k > 0; k--)
  {
    if (name[k] == '.') { break; }
  }
  if (k > 0) { m = k; }
  for (k = m; k > 0; k--)
  {
    if (!((name[k-1] >= 'a' && name[k-1] <= 'z') ||
          (name[k-1] >= 'A' && name[k-1] <= 'Z') ||
          (name[k-1] >= '0' && name[k-1] <= '9') ||
          name[k-1] == '_')) { break; }
  }
  name_from_file = (char *)malloc(m - k + 1);
  strncpy(name_from_file, &name[k], m - k);
  name_from_file[m-k] = '\0';
  name = name_from_file;

  /* get the global namespace */
  contents = file_info->Contents;

  /* use the hierarchy file to expand typedefs */
  if (hinfo)
  {
    for (i = 0; i < contents->NumberOfClasses; i++)
    {
      vtkWrap_ApplyUsingDeclarations(contents->Classes[i], file_info, hinfo);
    }
    for (i = 0; i < contents->NumberOfClasses; i++)
    {
      vtkWrap_ExpandTypedefs(contents->Classes[i], file_info, hinfo);
    }
  }

  /* the VTK_WRAPPING_CXX tells header files where they're included from */
  fprintf(fp,
          "// python wrapper for %s\n//\n"
          "#define VTK_WRAPPING_CXX\n",
          name);

  /* unless this is vtkObjectBase.h, define VTK_STREAMS_FWD_ONLY */
  if (strcmp("vtkObjectBase", name) != 0)
  {
    /* Block inclusion of full streams.  */
    fprintf(fp,
            "#define VTK_STREAMS_FWD_ONLY\n");
  }

  /* lots of important utility functions are defined in vtkPythonArgs.h */
  fprintf(fp,
          "#include \"vtkPythonArgs.h\"\n"
          "#include \"vtkPythonOverload.h\"\n"
          "#include \"vtkConfigure.h\"\n"
          "#include <cstddef>\n"
          "#include <sstream>\n");

  /* vtkPythonCommand is needed to wrap vtkObject.h */
  if (strcmp("vtkObject", name) == 0)
  {
    fprintf(fp,
          "#include \"vtkPythonCommand.h\"\n");
  }

  /* generate includes for any special types that are used */
  vtkWrapPython_GenerateSpecialHeaders(fp, file_info, hinfo);

  /* the header file for the wrapped class */
  fprintf(fp,
          "#include \"%s.h\"\n\n",
          name);

  /* do the export of the main entry point */
  fprintf(fp,
          "extern \"C\" { %s void PyVTKAddFile_%s(PyObject *); }\n",
          "VTK_ABI_EXPORT", name);

  /* get the module that is being wrapped */
  data = file_info->MainClass;
  if (!data && file_info->Contents->NumberOfClasses > 0)
  {
    data = file_info->Contents->Classes[0];
  }
  if (data && hinfo)
  {
    module = vtkWrapPython_ClassModule(hinfo, data->Name);
  }

  /* Identify all enum types that are used by methods */
  vtkWrapPython_MarkAllEnums(file_info->Contents, hinfo);

  /* Wrap any enum types defined in the global namespace */
  for (i = 0; i < contents->NumberOfEnums; i++)
  {
    vtkWrapPython_GenerateEnumType(fp, module, NULL, contents->Enums[i]);
  }

  /* Wrap any namespaces */
  for (i = 0; i < contents->NumberOfNamespaces; i++)
  {
    if (contents->Namespaces[i]->NumberOfConstants > 0)
    {
      vtkWrapPython_WrapNamespace(fp, module, contents->Namespaces[i]);
      numberOfWrappedNamespaces++;
    }
  }

  /* Check for all special classes before any classes are wrapped */
  for (i = 0; i < contents->NumberOfClasses; i++)
  {
    data = contents->Classes[i];

    /* guess whether type is a vtkobject */
    is_vtkobject = (data == file_info->MainClass ? 1 : 0);
    if (hinfo)
    {
      is_vtkobject = vtkWrap_IsTypeOf(hinfo, data->Name, "vtkObjectBase");
    }

    if (!is_vtkobject)
    {
      /* mark class as abstract only if it has pure virtual methods */
      /* (does not check for inherited pure virtual methods) */
      data->IsAbstract = 0;
      for (j = 0; j < data->NumberOfFunctions; j++)
      {
        FunctionInfo *func = data->Functions[j];
        if (func && func->IsPureVirtual)
        {
          data->IsAbstract = 1;
          break;
        }
      }
    }

    wrapAsVTKObject[i] = (is_vtkobject ? 1 : 0);
  }

  /* Wrap all of the classes in the file */
  for (i = 0; i < contents->NumberOfClasses; i++)
  {
    data = contents->Classes[i];
    is_vtkobject = wrapAsVTKObject[i];

    /* if "hinfo" is present, wrap everything, else just the main class */
    if (hinfo || data == file_info->MainClass)
    {
      if (vtkWrapPython_WrapOneClass(
            fp, module, data->Name, data, file_info, hinfo, is_vtkobject))
      {
        /* re-index wrapAsVTKObject for wrapped classes */
        wrapAsVTKObject[numberOfWrappedClasses] = (is_vtkobject ? 1 : 0);
        wrappedClasses[numberOfWrappedClasses++] = data;
      }
    }
  }

  /* The function for adding everything to the module dict */
  wrapped_anything = (numberOfWrappedClasses ||
                      numberOfWrappedNamespaces ||
                      contents->NumberOfConstants);
  fprintf(fp,
          "void PyVTKAddFile_%s(\n"
          "  PyObject *%s)\n"
          "{\n"
          "%s",
          name,
          (wrapped_anything ? "dict" : ""),
          (wrapped_anything ? "  PyObject *o;\n" : ""));

  /* Add all of the namespaces */
  for (j = 0; j < contents->NumberOfNamespaces; j++)
  {
    if (contents->Namespaces[j]->NumberOfConstants > 0)
    {
      fprintf(fp,
            "  o = PyVTKNamespace_%s();\n"
            "  if (o && PyDict_SetItemString(dict, \"%s\", o) != 0)\n"
            "  {\n"
            "    Py_DECREF(o);\n"
            "  }\n"
            "\n",
            contents->Namespaces[j]->Name,
            contents->Namespaces[j]->Name);
    }
  }

  /* Add all of the classes that have been wrapped */
  for (i = 0; i < numberOfWrappedClasses; i++)
  {
    data = wrappedClasses[i];
    is_vtkobject = wrapAsVTKObject[i];

    if (data->Template)
    {
      /* Template generator */
      fprintf(fp,
             "  o = Py%s_TemplateNew();\n"
            "\n",
            data->Name);

      /* Add template specializations to dict */
      fprintf(fp,
             "  if (o)\n"
             "  {\n"
             "    PyObject *l = PyObject_CallMethod(o, (char *)\"values\", 0);\n"
             "    Py_ssize_t n = PyList_GET_SIZE(l);\n"
             "    for (Py_ssize_t i = 0; i < n; i++)\n"
             "    {\n"
             "      PyObject *ot = PyList_GET_ITEM(l, i);\n"
             "      const char *nt = NULL;\n"
             "      if (PyType_Check(ot))\n"
             "      {\n"
             "        nt = ((PyTypeObject *)ot)->tp_name;\n"
             "      }\n"
             "      else if (PyCFunction_Check(ot))\n"
             "      {\n"
             "        nt = ((PyCFunctionObject *)ot)->m_ml->ml_name;\n"
             "      }\n"
             "      if (nt)\n"
             "      {\n"
             "        PyDict_SetItemString(dict, nt, ot);\n"
             "      }\n"
             "    }\n"
             "    Py_DECREF(l);\n"
             "  }\n"
             "\n");
    }
    else if (is_vtkobject)
    {
      /* Class is derived from vtkObjectBase */
      fprintf(fp,
            "  o = Py%s_ClassNew();\n"
            "\n",
            data->Name);
    }
    else
    {
      /* Classes that are not derived from vtkObjectBase */
      fprintf(fp,
            "  o = Py%s_TypeNew();\n"
            "\n",
            data->Name);
    }

    fprintf(fp,
            "  if (o && PyDict_SetItemString(dict, \"%s\", o) != 0)\n"
            "  {\n"
            "    Py_DECREF(o);\n"
            "  }\n"
            "\n",
            data->Name);
  }

  /* add any enum types defined in the file */
  vtkWrapPython_AddPublicEnumTypes(fp, "  ", "dict", "o", contents);

  /* add any constants defined in the file */
  vtkWrapPython_AddPublicConstants(fp, "  ", "dict", "o", contents);

  /* close the AddFile function */
  fprintf(fp,
          "}\n\n");

  free(name_from_file);

  vtkParse_Free(file_info);

  return 0;
}
示例#5
0
/* Check the options */
static int check_options(int argc, char *argv[])
{
  int i;
  size_t j;

  options.InputFileName = NULL;
  options.OutputFileName = NULL;
  options.IsAbstract = 0;
  options.IsConcrete = 0;
  options.IsVTKObject = 0;
  options.IsSpecialObject = 0;
  options.HierarchyFileName = 0;
  options.HintFileName = 0;

  for (i = 1; i < argc && argv[i][0] == '-'; i++)
    {
    if (strcmp(argv[i], "--concrete") == 0)
      {
      options.IsConcrete = 1;
      }
    else if (strcmp(argv[i], "--abstract") == 0)
      {
      options.IsAbstract = 1;
      }
    else if (strcmp(argv[i], "--vtkobject") == 0)
      {
      options.IsVTKObject = 1;
      }
    else if (strcmp(argv[i], "--special") == 0)
      {
      options.IsSpecialObject = 1;
      }
    else if (strcmp(argv[i], "--hints") == 0)
      {
      i++;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      options.HintFileName = argv[i];
      }
    else if (strcmp(argv[i], "--types") == 0)
      {
      i++;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      options.HierarchyFileName = argv[i];
      }
    else if (strcmp(argv[i], "-I") == 0)
      {
      i++;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      vtkParse_IncludeDirectory(argv[i]);
      }
    else if (strcmp(argv[i], "-D") == 0)
      {
      i++;
      j = 0;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      while (argv[i][j] != '\0' && argv[i][j] != '=') { j++; }
      if (argv[i][j] == '=') { j++; }
      vtkParse_DefineMacro(argv[i], &argv[i][j]);
      }
    else if (strcmp(argv[i], "-U") == 0)
      {
      i++;
      if (i >= argc || argv[i][0] == '-')
        {
        return -1;
        }
      vtkParse_UndefineMacro(argv[i]);
      }
    }

  return i;
}