VTK
dox/Common/Core/vtkSmartPointerBase.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkSmartPointerBase.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 =========================================================================*/
00025 #ifndef __vtkSmartPointerBase_h
00026 #define __vtkSmartPointerBase_h
00027 
00028 #include "vtkCommonCoreModule.h" // For export macro
00029 #include "vtkObjectBase.h"
00030 
00031 class VTKCOMMONCORE_EXPORT vtkSmartPointerBase
00032 {
00033 public:
00035   vtkSmartPointerBase();
00036 
00038   vtkSmartPointerBase(vtkObjectBase* r);
00039 
00042   vtkSmartPointerBase(const vtkSmartPointerBase& r);
00043 
00045   ~vtkSmartPointerBase();
00046 
00048 
00050   vtkSmartPointerBase& operator=(vtkObjectBase* r);
00051   vtkSmartPointerBase& operator=(const vtkSmartPointerBase& r);
00053 
00055 
00056   vtkObjectBase* GetPointer() const
00057     {
00058     // Inline implementation so smart pointer comparisons can be fully
00059     // inlined.
00060     return this->Object;
00061     }
00063 
00065   void Report(vtkGarbageCollector* collector, const char* desc);
00066 
00067 protected:
00068 
00069   // Initialize smart pointer to given object, but do not increment
00070   // reference count.  The destructor will still decrement the count.
00071   // This effectively makes it an auto-ptr.
00072   class NoReference {};
00073   vtkSmartPointerBase(vtkObjectBase* r, const NoReference&);
00074 
00075   // Pointer to the actual object.
00076   vtkObjectBase* Object;
00077 
00078 private:
00079   // Internal utility methods.
00080   void Swap(vtkSmartPointerBase& r);
00081   void Register();
00082 };
00083 
00084 //----------------------------------------------------------------------------
00085 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
00086   inline bool \
00087   operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
00088     { \
00089     return (static_cast<void*>(l.GetPointer()) op \
00090             static_cast<void*>(r.GetPointer())); \
00091     } \
00092   inline bool \
00093   operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
00094     { \
00095     return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
00096     } \
00097   inline bool \
00098   operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
00099     { \
00100     return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
00101     }
00102 
00103 
00104 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(==)
00105 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(!=)
00106 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<)
00107 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<=)
00108 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>)
00109 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>=)
00111 
00112 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
00113 
00115 
00116 VTKCOMMONCORE_EXPORT ostream& operator << (ostream& os,
00117                                         const vtkSmartPointerBase& p);
00119 
00120 #endif
00121 // VTK-HeaderTest-Exclude: vtkSmartPointerBase.h