Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkWeakPointer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkWeakPointer.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/01/15 18:57:31 $
00007   Version:   $Revision: 1.6 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkWeakPointer_h
00018 #define __itkWeakPointer_h
00019 
00020 #include "itkMacro.h"
00021 #include <iostream>
00022 
00023 namespace itk
00024 {
00025 
00042 template <class TObjectType>
00043 class ITK_EXPORT WeakPointer 
00044 {
00045 public:
00047   typedef TObjectType ObjectType;
00048   
00050   WeakPointer () 
00051     { m_Pointer = 0; }
00052 
00054   WeakPointer (const WeakPointer<ObjectType> &p):
00055     m_Pointer(p.m_Pointer) { }
00056 
00058   WeakPointer (ObjectType *p):
00059     m_Pointer(p) { }                             
00060   
00062   ~WeakPointer ()
00063     { m_Pointer = 0; }
00064   
00066   ObjectType *operator -> () const
00067     { return m_Pointer; }
00068 
00070   operator ObjectType * () const 
00071     { return m_Pointer; }
00072   
00074   template <typename R>
00075   bool operator == (R r) const
00076     {
00077     return (m_Pointer == (ObjectType*)r);
00078     }
00079   template <typename R>
00080   bool operator != (R r) const
00081     {
00082     return (m_Pointer != (ObjectType*)r);
00083     }
00084     
00086   ObjectType *GetPointer () const 
00087     { return m_Pointer; }
00088   
00090   bool operator < (const WeakPointer &r)
00091     { return (void*)m_Pointer < (void*) r.m_Pointer; }
00092   
00094   bool operator > (const WeakPointer &r)
00095     { return (void*)m_Pointer > (void*) r.m_Pointer; }
00096 
00098   bool operator <= (const WeakPointer &r)
00099     { return (void*)m_Pointer <= (void*) r.m_Pointer; }
00100 
00102   bool operator >= (const WeakPointer &r)
00103     { return (void*)m_Pointer >= (void*) r.m_Pointer; }
00104 
00106   WeakPointer &operator = (const WeakPointer &r)
00107     { return this->operator = (r.GetPointer()); }
00108   
00110   WeakPointer &operator = (ObjectType *r)
00111    {
00112     m_Pointer = r; 
00113     return *this;
00114     }
00115   
00117   ObjectType *Print (std::ostream& os) const 
00118     { 
00119     // This prints the object pointed to by the pointer  
00120     (*m_Pointer).Print(os);  
00121     return m_Pointer;
00122     } 
00123 
00124 private:
00126   ObjectType* m_Pointer;
00127 };  
00128 
00129   
00130 template <typename T>
00131 std::ostream& operator<< (std::ostream& os, WeakPointer<T> p) 
00132 {
00133   p.Print(os); 
00134   return os;
00135 }
00136 
00137 } // end namespace itk
00138   
00139 #endif

Generated at Wed Mar 12 01:13:14 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000