[vtk-developers] Proposing vtkObjectMacro

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


On Thu, Sep 13, 2012 at 6:48 AM, Aashish Chaudhary
<aashish.chaudhary at kitware.com> wrote:
> +1, can we add virtual keyword in front of the ~className()?
>
> Or are you going to rely on the fact that the parent class has defined its
> destructor virtual (like vtkObject?)

The macro is only intended for classes deriving from vtkObject (really
vtkObjectBase) so declaring the destructor as virtual would be
redundant.

>
> Thanks!
>
>
> On Thu, Sep 13, 2012 at 9: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
>>
>
>
>
> --
> | Aashish Chaudhary
> | R&D Engineer
> | Kitware Inc.
> | www.kitware.com



More information about the vtk-developers mailing list