VTK
dox/Common/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 "vtkObjectBase.h"
00029 
00030 class VTK_COMMON_EXPORT vtkSmartPointerBase
00031 {
00032 public:
00034   vtkSmartPointerBase();
00035 
00037   vtkSmartPointerBase(vtkObjectBase* r);
00038 
00041   vtkSmartPointerBase(const vtkSmartPointerBase& r);
00042 
00044   ~vtkSmartPointerBase();
00045 
00047 
00049   vtkSmartPointerBase& operator=(vtkObjectBase* r);
00050   vtkSmartPointerBase& operator=(const vtkSmartPointerBase& r);
00052 
00054 
00055   vtkObjectBase* GetPointer() const
00056     {
00057     // Inline implementation so smart pointer comparisons can be fully
00058     // inlined.
00059     return this->Object;
00060     }
00062 
00064   void Report(vtkGarbageCollector* collector, const char* desc);
00065 
00066 protected:
00067 
00068   // Initialize smart pointer to given object, but do not increment
00069   // reference count.  The destructor will still decrement the count.
00070   // This effectively makes it an auto-ptr.
00071   class NoReference {};
00072   vtkSmartPointerBase(vtkObjectBase* r, const NoReference&);
00073 
00074   // Pointer to the actual object.
00075   vtkObjectBase* Object;
00076 
00077 private:
00078   // Internal utility methods.
00079   void Swap(vtkSmartPointerBase& r);
00080   void Register();
00081 };
00082 
00083 //----------------------------------------------------------------------------
00084 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
00085   inline bool \
00086   operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
00087     { \
00088     return (static_cast<void*>(l.GetPointer()) op \
00089             static_cast<void*>(r.GetPointer())); \
00090     } \
00091   inline bool \
00092   operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
00093     { \
00094     return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
00095     } \
00096   inline bool \
00097   operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
00098     { \
00099     return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
00100     }
00101 
00102 
00103 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(==)
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(>=)
00110 
00111 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
00112 
00114 
00115 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
00116                                         const vtkSmartPointerBase& p);
00118 
00119 #endif