00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00055 #ifndef __vtkNew_h
00056 #define __vtkNew_h
00057
00058 #include "vtkIOStream.h"
00059
00060 class vtkObjectBase;
00061
00062 template <class T>
00063 class vtkNew
00064 {
00066
00067 void CheckObjectBase(vtkObjectBase*) {}
00068 public:
00069
00070
00071 vtkNew() : Object(T::New())
00072 {
00073 this->CheckObjectBase(this->Object);
00074 }
00076
00078
00079 ~vtkNew()
00080 {
00081 T* obj = this->Object;
00082 if (obj)
00083 {
00084 this->Object = 0;
00085 obj->Delete();
00086 }
00087 }
00089
00091
00093 T* operator->() const
00094 {
00095 return this->Object;
00096 }
00098
00100
00104 T* GetPointer() const
00105 {
00106 return this->Object;
00107 }
00109
00110 private:
00111 vtkNew(vtkNew<T> const&);
00112 void operator=(vtkNew<T> const&);
00113 T* Object;
00114 };
00115
00117
00118 template <class T>
00119 inline ostream& operator << (ostream& os, const vtkNew<T>& p)
00120 {
00121 return os << p.GetPointer();
00122 }
00124
00125 #endif