Commit 98ddb3e1 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

Created new vtk*NewMacros to replace some factories

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.

Change-Id: I06f713d70fc6d97ae086186c424a78f524592a4d
parent fdcdf8a1
......@@ -9,11 +9,21 @@ option(VTK_USE_64BIT_IDS "Build VTK with 64 bit ids"
${VTK_USE_64BIT_IDS_DEFAULT})
option(VTK_DEBUG_LEAKS "Build leak checking support into VTK." OFF)
mark_as_advanced(VTK_DEBUG_LEAKS VTK_USE_64BIT_IDS)
# This option determines the behavior of the New methods of vtkObject derived
# classes. If this option is off then only classes specifically using the
# vtkObjectFactoryNewMacro and vtkAbstractObjectFactoryNewMacro will allow for
# overrides. If the method is on then vtkStandardNewMacro will use the
# vtkObjectFactoryNewMacro's implementation body.
option(VTK_ALL_NEW_OBJECT_FACTORY
"Build all vtkObject derived classes with object factory new methods." OFF)
mark_as_advanced(VTK_DEBUG_LEAKS VTK_USE_64BIT_IDS VTK_ALL_NEW_OBJECT_FACTORY)
set(vtkCommonCore_EXPORT_OPTIONS
VTK_DEBUG_LEAKS
VTK_USE_64BIT_IDS
VTK_ALL_NEW_OBJECT_FACTORY
)
#-----------------------------------------------------------------------------
......
......@@ -148,6 +148,12 @@
#cmakedefine VTK_LEGACY_REMOVE
#cmakedefine VTK_LEGACY_SILENT
/* Debug leaks support. */
#cmakedefine VTK_DEBUG_LEAKS
/* Should all New methods use the object factory override. */
#cmakedefine VTK_ALL_NEW_OBJECT_FACTORY
/*--------------------------------------------------------------------------*/
/* Setup VTK based on platform features and configuration. */
......
......@@ -75,8 +75,16 @@ vtkObject* vtkObjectFactory::CreateInstance(const char* vtkclassname)
return 0;
}
#ifdef VTK_DEBUG_LEAKS
void vtkObjectFactory::ConstructInstance(const char* vtkclassname)
{
vtkDebugLeaks::ConstructClass(vtkclassname);
}
#else
void vtkObjectFactory::ConstructInstance(const char*)
{
}
#endif
// A one time initialization method.
void vtkObjectFactory::Init()
......
......@@ -32,14 +32,9 @@
// with the vtkObjectFactory::RegisterFactory method.
//
#ifndef __vtkObjectFactory_h
#define __vtkObjectFactory_h
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkObject.h"
......@@ -59,6 +54,11 @@ public:
// first factory returns the object no other factories are asked.
static vtkObject* CreateInstance(const char* vtkclassname);
// Description:
// Call vtkDebugLeaks::ConstructClass if necessary. Does not attempt
// to use the object factory to create an instance.
static void ConstructInstance(const char* vtkclassname);
// Description:
// Create all possible instances of the named vtk object.
// Each registered vtkObjectFactory will be asked, and the
......
......@@ -640,22 +640,68 @@ virtual double *Get##name() \
# define vtkCxxRevisionMacro(thisClass, revision)
#endif
// Macro to implement the body of the object factory form of the New() method.
#define VTK_OBJECT_FACTORY_NEW_BODY(thisClass) \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
if(ret) \
{ \
return static_cast<thisClass*>(ret); \
} \
return new thisClass;
// Macro to implement the body of the abstract object factory form of the New()
// method, i.e. an abstract base class that can only be instantiated if the
// object factory overrides it.
#define VTK_ABSTRACT_OBJECT_FACTORY_NEW_BODY(thisClass) \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
if(ret) \
{ \
return static_cast<thisClass*>(ret); \
} \
return NULL;
// Macro to implement the body of the standard form of the New() method.
#if defined(VTK_ALL_NEW_OBJECT_FACTORY)
# define VTK_STANDARD_NEW_BODY(thisClass) \
VTK_OBJECT_FACTORY_NEW_BODY(thisClass)
#elif defined(VTK_DEBUG_LEAKS)
# define VTK_STANDARD_NEW_BODY(thisClass) \
vtkObjectFactory::ConstructInstance(#thisClass); \
return new thisClass;
#else
# define VTK_STANDARD_NEW_BODY(thisClass) \
return new thisClass;
#endif
// Macro to implement the standard form of the New() method.
#define vtkStandardNewMacro(thisClass) \
thisClass* thisClass::New() \
{ \
vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
if(ret) \
{ \
return static_cast<thisClass*>(ret); \
} \
return new thisClass; \
VTK_STANDARD_NEW_BODY(thisClass) \
} \
vtkInstantiatorNewMacro(thisClass)
// Macro to implement the object factory form of the New() method.
#define vtkObjectFactoryNewMacro(thisClass) \
thisClass* thisClass::New() \
{ \
VTK_OBJECT_FACTORY_NEW_BODY(thisClass) \
} \
vtkInstantiatorNewMacro(thisClass)
// Macro to implement the abstract object factory form of the New() method.
// That is an abstract base class that can only be instantiated of the
// object factory overrides it.
#define vtkAbstractObjectFactoryNewMacro(thisClass) \
thisClass* thisClass::New() \
{ \
VTK_ABSTRACT_OBJECT_FACTORY_NEW_BODY(thisClass) \
} \
vtkInstantiatorNewMacro(thisClass)
// Macro to implement the instantiator's wrapper around the New()
// method. Use this macro if and only if vtkStandardNewMacro is not
// used by the class.
// method. Use this macro if and only if vtkStandardNewMacro or
// vtkObjectFactoryNewMacro is not used by the class.
#define vtkInstantiatorNewMacro(thisClass) \
extern vtkObject* vtkInstantiator##thisClass##New(); \
vtkObject* vtkInstantiator##thisClass##New() \
......
......@@ -28,9 +28,6 @@
/*--------------------------------------------------------------------------*/
/* Other Configuration Options */
/* Debug leaks support. */
#cmakedefine VTK_DEBUG_LEAKS
/* Whether VTK is using vfw32 and if it supports video capture */
#cmakedefine VTK_USE_VIDEO_FOR_WINDOWS
#cmakedefine VTK_VFW_SUPPORTS_CAPTURE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment