vtkNew< T > Class Template Reference

#include <vtkNew.h>

Inheritance diagram for vtkNew< T >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class T>
class vtkNew< T >

Allocate and hold a VTK object.

vtkNew is a class template that on construction allocates and initializes an instance of its template argument using T::New(). It assumes ownership of one reference during its lifetime, and calls T->Delete() on destruction.

Automatic casting is intentionally unavailable, calling GetPointer() will return a raw pointer. Users of this method should ensure that they do not return this pointer if the vtkNew will go out of scope without incrementing its reference count using vtkSmartPointer or similar.

 vtkNew<vtkClass> a;
 a->SomeMethod();

 vtkSmartPointer<vtkClass> b = a.GetPointer();
 b->SomeOtherMethod();

It should be noted that vtkNew is not a drop in replacement for vtkSmartPointer as it is not implicitly cast to a pointer in functions requiring a pointer. The GetPointer() method must be used, for example,

 vtkNew<vtkRenderer> ren;
 vtkNew<vtkRenderWindow> renWin;
 renWin->AddRenderer(ren.GetPointer());
 vtkNew<vtkRenderWindowInteractor> iren;
 iren->SetRenderWindow(renWin.GetPointer());

See also:
vtkSmartPointer vtkWeakPointer
Tests:
vtkNew (Tests)

Definition at line 63 of file vtkNew.h.

 vtkNew ()

Public Member Functions

 ~vtkNew ()
T * operator-> () const
T * GetPointer () const

Constructor & Destructor Documentation

template<class T>
vtkNew< T >::vtkNew (  )  [inline]

Compile time checking that the class is derived from vtkObjectBase.

Definition at line 71 of file vtkNew.h.

template<class T>
vtkNew< T >::~vtkNew (  )  [inline]

Deletes reference to instance of T on destruction.

Definition at line 79 of file vtkNew.h.


Member Function Documentation

template<class T>
T* vtkNew< T >::operator-> (  )  const [inline]

Enable pointer-like dereference syntax. Returns a pointer to the contained object.

Definition at line 93 of file vtkNew.h.

template<class T>
T* vtkNew< T >::GetPointer (  )  const [inline]

Get a raw pointer to the contained object. When using this function be careful that the reference count does not drop to 0 when using the pointer returned. This will happen when the vtkNew object goes out of scope for example.

Definition at line 104 of file vtkNew.h.


The documentation for this class was generated from the following file:

Generated on Wed Aug 24 11:49:41 2011 for VTK by  doxygen 1.5.6