[vtk-developers] Proposing vtkObjectMacro

Kyle Lutz kyle.lutz at kitware.com
Thu Sep 13 09:55:53 EDT 2012


On Thu, Sep 13, 2012 at 6:49 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> I think it's a great idea.  An additional macro would be needed for
> abstract classes.  Actually, because these macros are used in class
> definition (not object declarations per se), I would propose:
>
> vtkClassMacro(class,superclass);
> vtkAbstractClassMacro(class,superclass);

We were talking about adding an additional macro for abstract classes
but I wanted to start with just one. Later a macro for abstract
classes could be added.

I am also open to changing the name depending on what the consensus is.

-kyle

>
>  - David
>
> On Thu, Sep 13, 2012 at 7:36 AM, Kyle Lutz <kyle.lutz at kitware.com> wrote:
>> 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
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>



More information about the vtk-developers mailing list