VTK
vtkNew.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkNew.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
55 #ifndef __vtkNew_h
56 #define __vtkNew_h
57 
58 #include "vtkIOStream.h"
59 
60 class vtkObjectBase;
61 
62 template <class T>
63 class vtkNew
64 {
66 
67  void CheckObjectBase(vtkObjectBase*) {}
68 public:
70 
71 
72  vtkNew() : Object(T::New())
73  {
74  this->CheckObjectBase(this->Object);
75  }
77 
79 
81  {
82  T* obj = this->Object;
83  if (obj)
84  {
85  this->Object = 0;
86  obj->Delete();
87  }
88  }
90 
92 
94  T* operator->() const
95  {
96  return this->Object;
97  }
99 
101 
105  T* GetPointer() const
106  {
107  return this->Object;
108  }
110 
111 private:
112  vtkNew(vtkNew<T> const&); // Not implemented.
113  void operator=(vtkNew<T> const&); // Not implemented.
114  T* Object;
115 };
116 
118 
119 template <class T>
120 inline ostream& operator << (ostream& os, const vtkNew<T>& p)
121 {
122  return os << p.GetPointer();
123 }
125 
126 #endif