OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / vtk / vtkSmartPointer.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkSmartPointer.h,v $
5   Language:  C++
6   Date:      $Date: 2003/01/07 15:52:51 $
7   Version:   $Revision: 1.1 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
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.
16
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.
22
23 #ifndef __vtkSmartPointer_h
24 #define __vtkSmartPointer_h
25
26 #include "vtkSmartPointerBase.h"
27
28 template <class T>
29 class vtkSmartPointer: public vtkSmartPointerBase
30 {
31 public:
32   // Description:
33   // Initialize smart pointer to NULL.
34   vtkSmartPointer() {}
35   
36   // Description:
37   // Initialize smart pointer to given object.
38   vtkSmartPointer(T* r): vtkSmartPointerBase(r) {}
39   
40   // Description:
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) {}
44   
45   // Description:
46   // Assign object to reference.  This removes any reference to an old
47   // object.
48   vtkSmartPointer& operator=(T* r)
49     {
50     this->vtkSmartPointerBase::operator=(r);
51     return *this;
52     }
53   
54   // Description:
55   // Assign object to reference.  This removes any reference to an old
56   // object.
57   vtkSmartPointer& operator=(const vtkSmartPointerBase& r)
58     {
59     this->vtkSmartPointerBase::operator=(r);
60     return *this;
61     }  
62   
63   // Description:
64   // Get the contained pointer.
65   T* GetPointer() const
66     {
67     return static_cast<T*>(this->Object);
68     }
69   
70   // Description:
71   // Dereference the pointer and return a reference to the contained
72   // object.
73   T& operator*() const
74     {
75     return *static_cast<T*>(this->Object);
76     }
77   
78   // Description:
79   // Provides normal pointer target member access using operator ->.
80   T* operator->() const
81     {
82     return static_cast<T*>(this->Object);
83     }
84 };
85
86 #endif