VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkNew.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00058 #ifndef __vtkNew_h 00059 #define __vtkNew_h 00060 00061 #include "vtkIOStream.h" 00062 00063 class vtkObjectBase; 00064 00065 template <class T> 00066 class vtkNew 00067 { 00069 00070 void CheckObjectBase(vtkObjectBase*) {} 00071 public: 00073 00074 00075 vtkNew() : Object(T::New()) 00076 { 00077 this->CheckObjectBase(this->Object); 00078 } 00080 00082 00083 ~vtkNew() 00084 { 00085 T* obj = this->Object; 00086 if (obj) 00087 { 00088 this->Object = 0; 00089 obj->Delete(); 00090 } 00091 } 00093 00095 00097 T* operator->() const 00098 { 00099 return this->Object; 00100 } 00102 00104 00108 T* GetPointer() const 00109 { 00110 return this->Object; 00111 } 00112 T* Get() const 00113 { 00114 return this->Object; 00115 } 00117 00118 private: 00119 vtkNew(vtkNew<T> const&); // Not implemented. 00120 void operator=(vtkNew<T> const&); // Not implemented. 00121 T* Object; 00122 }; 00123 00125 00126 template <class T> 00127 inline ostream& operator << (ostream& os, const vtkNew<T>& p) 00128 { 00129 return os << p.GetPointer(); 00130 } 00132 00133 #endif 00134 // VTK-HeaderTest-Exclude: vtkNew.h