vtkSmartPointerBase.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00036 #ifndef __vtkSmartPointerBase_h
00037 #define __vtkSmartPointerBase_h
00038
00039 #include "vtkObjectBase.h"
00040
00041 class VTK_COMMON_EXPORT vtkSmartPointerBase
00042 {
00043 private:
00044 struct SafeBoolDummy { void Dummy() {} };
00045 typedef void (SafeBoolDummy::* SafeBool)();
00046 public:
00048 vtkSmartPointerBase();
00049
00051 vtkSmartPointerBase(vtkObjectBase* r);
00052
00055 vtkSmartPointerBase(const vtkSmartPointerBase& r);
00056
00058 ~vtkSmartPointerBase();
00059
00061
00063 vtkSmartPointerBase& operator=(vtkObjectBase* r);
00064 vtkSmartPointerBase& operator=(const vtkSmartPointerBase& r);
00066
00068
00069 vtkObjectBase* GetPointer() const
00070 {
00071
00072
00073 return this->Object;
00074 }
00076
00078
00079 operator SafeBool()
00080 {
00081 return this->Object? &SafeBoolDummy::Dummy : 0;
00082 }
00084
00086
00087 SafeBool operator!()
00088 {
00089 return this->Object? 0 : &SafeBoolDummy::Dummy;
00090 }
00092 protected:
00093
00094
00095
00096
00097 class NoReference {};
00098 vtkSmartPointerBase(vtkObjectBase* r, const NoReference&);
00099
00100
00101 vtkObjectBase* Object;
00102
00103 private:
00104
00105 void Swap(vtkSmartPointerBase& r);
00106 void Register();
00107 };
00108
00109
00110
00111
00112
00113
00114 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
00115 inline vtkstd_bool \
00116 operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
00117 { \
00118 return (static_cast<void*>(l.GetPointer()) op \
00119 static_cast<void*>(r.GetPointer())); \
00120 } \
00121 inline vtkstd_bool \
00122 operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
00123 { \
00124 return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
00125 } \
00126 inline vtkstd_bool \
00127 operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
00128 { \
00129 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
00130 }
00131
00132 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(==)
00133 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(!=)
00134 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<)
00135 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<=)
00136 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>)
00137 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>=)
00138
00139 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
00140
00142
00143 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
00144 const vtkSmartPointerBase& p);
00146
00147 #endif