[vtk-developers] Proposed new vtk*NewMacros

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed May 9 10:49:02 EDT 2012


Hi,

I just pushed a topic to Gerrit with some proposed new vtk*NewMacros.

http://review.source.kitware.com/#/t/584/

There are a couple of parts to the commit, quoting the commit message
for your convenience,

--
Factored the vtkStandardNewMacro into a VTK_STANDARD_NEW_BODY macro and
a vtkStandardNewMacro. Also introduced vtkObjectFactoryNewMacro and
vtkAbstractObjectFactoryNewMacro in order to replace the functionality
present in some of the hard coded factories remaining from before VTK
modularization.

The vtkObjectFactoryNewMacro does what the vtkStandardNewMacro did
previously (and will continue to do if the VTK_ALL_NEW_OBJECT_FACTORY
option is turned on) - use the object factory override of the new method
of the class. The vtkAbstractObjectFactoryNewMacro will attempt to
return a class from the vtkObjectFactory::CreateInstance method, or
return NULL if there are no overrides, i.e. the behavior of the
vtkGraphicsFactory which is necesasary for abstract base classes like
vtkRenderWindow.

The VTK_ALL_NEW_OBJECT_FACTORY method allows VTK to be compiled with the
previous behavior of all New methods using the object factory. A new
static method was added to vtkObjectFactory largely for pragmatic
reasons - all of those implementations already include vtkObjectFactory
but not vtkDebugLeaks and so this reduces the change necessary to still
work with VTK_DEBUG_LEAKS when that option is on.
--

The vtkStandardNewMacro behavior changes, but can revert back to
previous behavior. We need a new vtk*NewMacro for the case where the
class should have a static New method but is abstract. It might be
nice to add in a debug warning to warn that a pure abstract was
instantiated and returned null in that macro, but I didn't add that in
yet. This was the behavior of the vtkGraphicsFactory even for
non-abstract classes - it would return null if it didn't figure out
the right class to return (and is what we have right now in master).

Feel free to discuss here, I didn't convert all the classes that
should be converted in case adjustments need to be made to the new
macros naming convention etc. This will allow us to remove the
remaining object factory stubs that were hardwired at compile time
using #ifdefs before modularization.

Thanks,

Marcus



More information about the vtk-developers mailing list