I have written a tool for VTK that generates a text file that describes the class hierarchy as one of the first steps in the build process. Why would I do this? Well, one of the problems with the VTK wrappers has always been that the wrapper-generators see only one header file at a time. This leads to a few complications:
- method inheritance must be dealt with at run time
- parameter type-checking must be done at run time
- return-value construction can become a mess when typing is uncertain
Fortunately, (1) can be dealt with efficiently at run time for Java, Python, and Tcl. However, (2) and (3) require run-time type lookup on both the expected parameter type and the type of the value that is passed. This can be expensive, and to make things even worse, a switch statement would be needed to properly deal with the possible outcomes. This could easily double the amount of code in the wrappers. Right now, the wrapper generators avoid this by assuming that any type beginning with "vtk" is derived from vtkObjectBase (except certain other types like vtkIdType which are automatically converted to int). This is not a safe assumption, and in fact, wrapping a method that takes a "vtkSomething *" that is not derived from vtkObjectBase can result in a segfault.
The solution is a pre-wrapping step called Hierarchy Wrapping builds a text file that describes the class hierarchies of all classes that are encountered in the header files. With the benefit of this file, the wrapper-generators for Tcl, Python, and Java can know, at code-generation time, the base class of any encountered type is. I have written Hierarchy Wrapping code for my WrapVTK project, and will merge it into VTK itself in the coming weeks.