[vtk-developers] Proposing vtkObjectMacro

Kyle Lutz kyle.lutz at kitware.com
Thu Sep 13 09:36:56 EDT 2012


I'd like to propose a new macro to ease the development of new
vtkObject derived classes. When implementing new
filters/algorithms/etc. a lot of boiler plate code is required and
most often just copy-pasted from other similar classes. I've
implemented a new macro named vtkObjectMacro() which reduces this
boilerplate to a single line of code to be included in the class's
declaration. This was inspired by the similar Q_OBJECT macro in Qt.

Here is the documentation for the macro:

// Description:
// Declares a vtkObject subclass.
//
// Notably, performs the following actions:
//   - invokes the vtkTypeMacro()
//   - declares its constructor and destructor as protected
//   - disables its copy constructor and assignment operator
//   - declares its static *New() method
//   - declares its PrintSelf() method
#define vtkObjectMacro(className, parentClassName)

For example, here is how it would be used when creating a new
poly-data algorithm named MyFilter:

// in myfilter.h
class MyFilter : public vtkPolyDataAlgorithm
{
public:
  vtkObjectMacro(MyFilter, vtkPolyDataAlgorithm)
};

// in myfilter.cxx
vtkStandardNewMacro(MyFilter)
MyFilter::MyFilter() { /* ... */ }
MyFilter::~MyFilter() { /* ... */ }
void MyFilter::PrintSelf(ostream &o, vtkIndent indent) { /* ... */ }

I've pushed a topic to gerrit with the implementation:
http://review.source.kitware.com/#/t/1276/

Thoughts? Comments? Concerns?

Thanks,
Kyle



More information about the vtk-developers mailing list