[vtk-developers] Proposing vtkObjectMacro

Aashish Chaudhary aashish.chaudhary at kitware.com
Thu Sep 13 10:16:52 EDT 2012


On Thu, Sep 13, 2012 at 9:53 AM, Kyle Lutz <kyle.lutz at kitware.com> wrote:

> 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.
>

Yes, but in general IMO, it is not a good practice to leave virtual keyword
out just because base class has declared virtual destructor.  Also implicit
something is not good unless properly documented. Since we are talking
about a macro, I don't think its too bad to have virtual keyword in front
of the desctructor.

I am OK with not having it, but would prefer other way.


>
> >
> > 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
>



-- 
| Aashish Chaudhary
| R&D Engineer
| Kitware Inc.
| www.kitware.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20120913/5e533b9c/attachment.html>


More information about the vtk-developers mailing list