Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkSmartPointerBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSmartPointerBase.h,v $
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 // Need to use vtkstd_bool type because std: :less requires bool return
00085 // type from operators.  This example should not be used to justify
00086 // using bool elsewhere in VTK.
00087 
00088 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
00089   inline vtkstd_bool \
00090   operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
00091     { \
00092     return (static_cast<void*>(l.GetPointer()) op \
00093             static_cast<void*>(r.GetPointer())); \
00094     } \
00095   inline vtkstd_bool \
00096   operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
00097     { \
00098     return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
00099     } \
00100   inline vtkstd_bool \
00101   operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
00102     { \
00103     return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
00104     }
00105 
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(<=)
00110 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>)
00111 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>=)
00112 
00113 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
00114 
00116 
00117 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
00118                                         const vtkSmartPointerBase& p);
00120 
00121 #endif

Generated on Mon Jan 21 23:07:18 2008 for VTK by  doxygen 1.4.3-20050530