[vtk-developers] Smart pointer declaration macro?

Karthik Krishnan karthik.krishnan at kitware.com
Fri Jan 8 15:33:49 EST 2010


Or have these as typdefs and/or factory methods in a VTK class, as is
done in ITK (that would be internally handled via macros in the
class), so that usage syntax looks like.

  vtkPoints::SmartPointer = vtkPoints::SmartNew();
or
  vtkPoints::SmartPointer instance(1);





On Fri, Jan 8, 2010 at 3:26 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Fri, Jan 8, 2010 at 1:15 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
>> I've seen the use of something like this:
>>
>> #define SPNEW(instance, type) \
>> vtkSmartPointer<type> instance = vtkSmartPointer<type>::New();
>>
>> in many of the tests and elsewhere. It seems like a reasonable savings
>> of a whole bunch of characters that appears many many times in most
>> functions. Could we standardize something like this so it can be used
>> universally without having to see this little #define in every file it
>> is used in?
>>
>> Thoughts?
>
> Doesn't VTK have enough macros already? ;)
>
> There are other ways to reduce the repetition, without using macros:
>
> 1) Add a new constructor argument for smart pointers:
>
> vtkSmartPointer<type> instance(1); // create an smart pointer and
> allocate an object at the same time
> vtkSmartPointer<type> instance(0); // create a smart pointer with
> "null" as the initial pointer
>
> 2) Add a non-static "New" method for smart pointers:
>
> vtkSmartPointer<type> instance;
> instance.InstantiateNew();
>
> etc.
>
>   David
> _______________________________________________
> 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