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

Common/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 protected:
00063   
00064   // Internal utility methods.
00065   void Swap(vtkSmartPointerBase& r);
00066   void Register();
00067   void UnRegister();
00068   
00069   // Pointer to the actual object.
00070   vtkObjectBase* Object;
00071 };
00072 
00073 //----------------------------------------------------------------------------
00074 // Need to use vtkstd_bool type because std::less requires bool return
00075 // type from operators.  This example should not be used to justify
00076 // using bool elsewhere in VTK.
00077 
00078 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
00079   inline vtkstd_bool \
00080   operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
00081     { \
00082     return (static_cast<void*>(l.GetPointer()) op \
00083             static_cast<void*>(r.GetPointer())); \
00084     } \
00085   inline vtkstd_bool \
00086   operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
00087     { \
00088     return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
00089     } \
00090   inline vtkstd_bool \
00091   operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
00092     { \
00093     return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
00094     }
00095 
00096 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(==)  
00097 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(!=)
00098 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<)
00099 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<=)
00100 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>)
00101 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>=)
00102 
00103 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
00104 
00106 
00107 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
00108                                         const vtkSmartPointerBase& p);
00110 
00111 #endif