Main Page Class Hierarchy Alphabetical List Compound List File List Compound 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   Language:  C++
    00006
    00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
    00008   All rights reserved.
    00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
    00010
    00011      This software is distributed WITHOUT ANY WARRANTY; without even
    00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00013      PURPOSE.  See the above copyright notice for more information.
    00014
    00015 =========================================================================*/
    00039 #ifndef __vtkSmartPointerBase_h
    00040 #define __vtkSmartPointerBase_h
    00041
    00042 #include "vtkObjectBase.h"
    00043
    00044 class VTK_COMMON_EXPORT vtkSmartPointerBase
    00045 {
    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     // Inline implementation so smart pointer comparisons can be fully
    00072     // inlined.
    00073     return this->Object;
    00074     }
    00076 protected:
    00077
    00078   // Internal utility methods.
    00079   void Swap(vtkSmartPointerBase& r);
    00080   void Register();
    00081   void UnRegister();
    00082
    00083   // Pointer to the actual object.
    00084   vtkObjectBase* Object;
    00085 };
    00086
    00087 //----------------------------------------------------------------------------
    00088 // Need to switch on bool type because std::less requires bool return
    00089 // type from operators.  This example should not be used to justify
    00090 // using bool elsewhere in VTK.
    00091 #ifdef VTK_COMPILER_HAS_BOOL
    00092 # define VTK_SMART_POINTER_BASE_BOOL bool
    00093 #else
    00094 # define VTK_SMART_POINTER_BASE_BOOL int
    00095 #endif
    00096
    00097 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
    00098   inline VTK_SMART_POINTER_BASE_BOOL \
    00099   operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
    00100     { \
    00101     return (static_cast<void*>(l.GetPointer()) op \
    00102             static_cast<void*>(r.GetPointer())); \
    00103     } \
    00104   inline VTK_SMART_POINTER_BASE_BOOL \
    00105   operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
    00106     { \
    00107     return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
    00108     } \
    00109   inline VTK_SMART_POINTER_BASE_BOOL \
    00110   operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
    00111     { \
    00112     return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
    00113     }
    00114
    00115 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(==)
    00116 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(!=)
    00117 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<)
    00118 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<=)
    00119 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>)
    00120 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>=)
    00121
    00122 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
    00123 #undef VTK_SMART_POINTER_BASE_BOOL
    00124
    00126
    00127 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
    00128                                         const vtkSmartPointerBase& p);
    00130
    00131 #endif