[vtk-developers] vtkNew<>

David Gobbi david.gobbi at gmail.com
Fri Jan 29 13:33:46 EST 2010


I have a slightly crazy idea for vtkNew.  The only places where it
calls any vtkObjectBase methods are in the constructor and destructor.
 Does that mean that we could actually use vtkNew<> in our header
files if we split vtkNew.h into a vtkNew.h and a vtkNew.txx?  We'd
include vtkNew.h in our header files, and include vtkNew.txx (with
definitions of the constructor and destructor) in our .cxx files.

My kerthunker isn't working well enough today to convince myself that
this would work.

  David


On Fri, Jan 29, 2010 at 10:16 AM, Brad King <brad.king at kitware.com> wrote:
> Will Schroeder wrote:
>> Well I have to say the vtkSmartPointer macro discussion was one of the
>> most entertaining threads I've had the pleasure of participating in.
>> It's good to know that after 17 years we finally know how to instantiate
>> objects in VTK and that we are making progress :-)
>
> March of progress:
>
> 1980: C
>    printf("%10.2f", x);
> 1988: C++
>    cout << setw(10) << setprecision(2) << showpoint << x;
> 1996: Java
>    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
>    formatter.setMinimumFractionDigits(2);
>    formatter.setMaximumFractionDigits(2);
>    String s = formatter.format(x);
>    for (int i = s.length(); i < 10; i++) System.out.print(' ');
>    System.out.print(s);
> 2004: Java
>    System.out.printf("%10.2f", x);
>
> -----------------------------------
>
> 1994:
>    vtkPolyData* pd = vtkPolyData::New();
>    ...
>    if(some_error)
>      {
>      pd->Delete(); // Hopefully we remember this one.
>      return;
>      }
>    ...
>    pd->Delete();
> 2004:
>    vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New()
> 2010:
>    vtkNew<vtkPolyData> pd;
>
> I guess we did better than formatted printing.
>
>> Has anyone thought about how we are going to roll this out?
> [snip]
>> I assume Bill and others are going to continue with experiments
>
> That is my understanding.
>
>> and if we still like it what then? We've got examples,
>> tests, code base, tutorials, books, etc. to contend with.
>
> When the vtkSmartPointer<>::New() approach was added, it just slowly
> moved into tests and examples.  It probably hasn't finished yet either.
> Unlike vtkSmartPointer<>, vtkNew<> is useable only for local variables.
> Perhaps its brevity and clear purpose will lead to quicker adoption.
>
>> My current favorite solution is to ask Brad to fix everything
>
> Hey, I voted for (1)!
>
> -Brad
> _______________________________________________
> 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