1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkSmartPointer.h,v $
6 Date: $Date: 2003/01/07 15:52:51 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkSmartPointer - Hold a reference to a vtkObjectBase instance.
19 // .SECTION Description
20 // vtkSmartPointer is a class template that provides automatic casting
21 // for objects held by the vtkSmartPointerBase superclass.
23 #ifndef __vtkSmartPointer_h
24 #define __vtkSmartPointer_h
26 #include "vtkSmartPointerBase.h"
29 class vtkSmartPointer: public vtkSmartPointerBase
33 // Initialize smart pointer to NULL.
37 // Initialize smart pointer to given object.
38 vtkSmartPointer(T* r): vtkSmartPointerBase(r) {}
41 // Initialize smart pointer with a new reference to the same object
42 // referenced by given smart pointer.
43 vtkSmartPointer(const vtkSmartPointerBase& r): vtkSmartPointerBase(r) {}
46 // Assign object to reference. This removes any reference to an old
48 vtkSmartPointer& operator=(T* r)
50 this->vtkSmartPointerBase::operator=(r);
55 // Assign object to reference. This removes any reference to an old
57 vtkSmartPointer& operator=(const vtkSmartPointerBase& r)
59 this->vtkSmartPointerBase::operator=(r);
64 // Get the contained pointer.
67 return static_cast<T*>(this->Object);
71 // Dereference the pointer and return a reference to the contained
75 return *static_cast<T*>(this->Object);
79 // Provides normal pointer target member access using operator ->.
82 return static_cast<T*>(this->Object);