00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00025 #ifndef __vtkSmartPointer_h
00026 #define __vtkSmartPointer_h
00027
00028 #include "vtkSmartPointerBase.h"
00029
00030 template <class T>
00031 class vtkSmartPointer: public vtkSmartPointerBase
00032 {
00033 public:
00035 vtkSmartPointer() {}
00036
00038 vtkSmartPointer(T* r): vtkSmartPointerBase(r) {}
00039
00042 vtkSmartPointer(const vtkSmartPointerBase& r): vtkSmartPointerBase(r) {}
00043
00045
00047 vtkSmartPointer& operator=(T* r)
00048 {
00049 this->vtkSmartPointerBase::operator=(r);
00050 return *this;
00051 }
00053
00055
00057 vtkSmartPointer& operator=(const vtkSmartPointerBase& r)
00058 {
00059 this->vtkSmartPointerBase::operator=(r);
00060 return *this;
00061 }
00063
00065
00066 T* GetPointer() const
00067 {
00068 return static_cast<T*>(this->Object);
00069 }
00071
00073
00074 operator T* () const
00075 {
00076 return static_cast<T*>(this->Object);
00077 }
00079
00081
00083 T& operator*() const
00084 {
00085 return *static_cast<T*>(this->Object);
00086 }
00088
00090
00091 T* operator->() const
00092 {
00093 return static_cast<T*>(this->Object);
00094 }
00096
00098
00105 void TakeReference(T* t)
00106 {
00107 *this = vtkSmartPointer<T>(t, NoReference());
00108 }
00110
00112
00113 static vtkSmartPointer<T> New()
00114 {
00115 return vtkSmartPointer<T>(T::New(), NoReference());
00116 }
00118
00120
00121 static vtkSmartPointer<T> NewInstance(T* t)
00122 {
00123 return vtkSmartPointer<T>(t->NewInstance(), NoReference());
00124 }
00126
00128
00136 static vtkSmartPointer<T> Take(T* t)
00137 {
00138 return vtkSmartPointer<T>(t, NoReference());
00139 }
00141
00142
00143
00144
00145
00146
00147 #if defined(__HP_aCC)
00148 # define VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(op) \
00149 vtkstd_bool operator op (NullPointerOnly*) const \
00150 { \
00151 return ::operator op (*this, 0); \
00152 }
00153 private:
00154 class NullPointerOnly {};
00155 public:
00156 VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(==)
00157 VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(!=)
00158 VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(<)
00159 VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(<=)
00160 VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(>)
00161 VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND(>=)
00162 # undef VTK_SMART_POINTER_DEFINE_OPERATOR_WORKAROUND
00163 #endif
00164 protected:
00165 vtkSmartPointer(T* r, const NoReference& n): vtkSmartPointerBase(r, n) {}
00166 private:
00167
00168
00169 void TakeReference(const vtkSmartPointerBase&);
00170 static void Take(const vtkSmartPointerBase&);
00171 };
00172
00173 #define VTK_SMART_POINTER_DEFINE_OPERATOR(op) \
00174 template <class T> \
00175 inline vtkstd_bool \
00176 operator op (const vtkSmartPointer<T>& l, const vtkSmartPointer<T>& r) \
00177 { \
00178 return (l.GetPointer() op r.GetPointer()); \
00179 } \
00180 template <class T> \
00181 inline vtkstd_bool operator op (T* l, const vtkSmartPointer<T>& r) \
00182 { \
00183 return (l op r.GetPointer()); \
00184 } \
00185 template <class T> \
00186 inline vtkstd_bool operator op (const vtkSmartPointer<T>& l, T* r) \
00187 { \
00188 return (l.GetPointer() op r); \
00189 }
00190
00191 VTK_SMART_POINTER_DEFINE_OPERATOR(==)
00192 VTK_SMART_POINTER_DEFINE_OPERATOR(!=)
00193 VTK_SMART_POINTER_DEFINE_OPERATOR(<)
00194 VTK_SMART_POINTER_DEFINE_OPERATOR(<=)
00195 VTK_SMART_POINTER_DEFINE_OPERATOR(>)
00196 VTK_SMART_POINTER_DEFINE_OPERATOR(>=)
00197
00198 #undef VTK_SMART_POINTER_DEFINE_OPERATOR
00199
00201
00202 template <class T>
00203 inline ostream& operator << (ostream& os, const vtkSmartPointer<T>& p)
00205 {
00206 return os << static_cast<const vtkSmartPointerBase&>(p);
00207 }
00208
00209 #endif