[vtk-developers] const in set vector macros

David Cole david.cole at kitware.com
Fri Nov 7 14:44:19 EST 2008


I sort of agree with Karthik... It would be better if we could make VTK as a
whole honor const where it makes sense. This, however, does not seem like a
lightweight task by any means.
However, I also think we should make it easy for people not to have to
resort to const_cast madness.

Changing vtkSetGet.h is a good start, but there are many method overrides in
subclasses that will now have a different signature than their parent class
methods unless they are carefully sought out and changed to match the new
parent signature. You do not want to unintentionally change a method
override to a method overload.

After thinking about this for a little while, I'd be very hesitant to make
this change without reserving a lot of time for chasing down strange
behavior to follow...


David


On Fri, Nov 7, 2008 at 1:02 PM, Karthik Krishnan <
karthik.krishnan at kitware.com> wrote:

> VTK's public API as a whole does not respect constness. It might be
> more painful if we were to make bits and pieces of the public API
> const correct. Sometimes slightly correct is not better than
> fully incorrect.
>
> Did you also check if you would be causing the wrappers
> problems ?
>
> Thanks
> --
> karthik
>
> 2008/11/7 Burlen Loring <burlen.loring at kitware.com>:
> > Hi,
> >
> > would anyone object to changing the vtkSetVectorXMacro's to respect const
> > pointers?
> > for eg. the change to SetVector3Macro would be:
> >
> > -virtual void Set##name (type _arg[3]) \
> > +virtual void Set##name (const type _arg[3]) \
> >  { \
> >  this->Set##name (_arg[0], _arg[1], _arg[2]);\
> >  }
> >
> >
> > This would be helpful in a situation like:
> >
> > class A
> > {
> > public:
> >   const double *GetBlah(){ return this->Blah; }
> > private:
> >   double Blah[3];
> > };
> >
> > class B : public vtkObject
> > {
> > public:
> >   vtkSetVector3Macro(Bleh,double);
> > private:
> >   double Bleh[3];
> > };
> >
> > A a;
> > B *b=B::New();
> > b->SetBleh(a.GetBlah());
> >
> > where I want to return a pointer to an array for efficiency but want to
> > document, and enforce, that the array's contents aren't to be modified,
> and
> > don't want to end up using const_cast's everywhere I need to pass the
> array
> > to a vtkObject.
> >
> > --
> > Burlen Loring
> > Kitware, Inc.
> > R&D Engineer
> > 28 Corporate Drive
> > Clifton Park, NY 12065-8662
> > Phone: 518-371-3971 x137
> >
> >
> > _______________________________________________
> > vtk-developers mailing list
> > vtk-developers at vtk.org
> > http://www.vtk.org/mailman/listinfo/vtk-developers
> >
> >
>
>
>
> --
> Karthik Krishnan
> R&D Engineer,
> Kitware Inc.
> Ph: 518 371 3971 x119
> Fax: 518 371 3971
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20081107/4d248cff/attachment.html>


More information about the vtk-developers mailing list