| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkSmartPointerForwardReference.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:48 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkSmartPointerForwardReference_h |
| 18 |
|
#define __itkSmartPointerForwardReference_h |
| 19 |
|
|
| 20 |
|
#include "itkMacro.h" |
| 21 |
|
#include "itkWeakPointer.h" |
| 22 |
|
|
| 23 |
|
#include <iostream> |
| 24 |
|
|
| 25 |
|
namespace itk |
| 26 |
|
{ |
| 27 |
|
|
| 28 |
|
/** \class SmartPointerForwardReference |
| 29 |
|
* \brief Implements transparent reference counting in situations where forward |
| 30 |
|
* references / cyclic include depndencies are a problem. |
| 31 |
|
* |
| 32 |
|
* SmartPointerForwardReference implements reference counting by overloading |
| 33 |
|
* operator -> (and *) among others. This allows natural interface |
| 34 |
|
* to the class referred to by the pointer without having to invoke |
| 35 |
|
* special Register()/UnRegister() methods directly. |
| 36 |
|
* |
| 37 |
|
* This class is nearly identical to itkSmartPointer except that is used in |
| 38 |
|
* situations where forward references or cyclic include dependencies become |
| 39 |
|
* a problem. This class requires that the .h file is included in the .h file |
| 40 |
|
* of the class using it, and the .txx file is included in the .cxx/.txx file |
| 41 |
|
* of the class using it. (Make sure that SmartPointerForwardReference.txx is |
| 42 |
|
* included last in the .cxx/.txx list of includes.) |
| 43 |
|
* |
| 44 |
|
* \ingroup ITKSystemObjects |
| 45 |
|
* \ingroup DataAccess |
| 46 |
|
*/ |
| 47 |
|
template <class T> |
| 48 |
|
class ITK_EXPORT SmartPointerForwardReference |
| 49 |
|
{ |
| 50 |
|
public: |
| 51 |
|
/** Constructor */ |
| 52 |
|
SmartPointerForwardReference () |
| 53 |
|
{m_Pointer = 0;} |
| 54 |
|
|
| 55 |
|
/** Const constructor */ |
| 56 |
|
SmartPointerForwardReference (const SmartPointerForwardReference<T> &p); |
| 57 |
|
|
| 58 |
|
/** Construct from a WeakPointer */ |
| 59 |
|
SmartPointerForwardReference (const WeakPointer<T> &p); |
| 60 |
|
|
| 61 |
|
/** Constructor to pointer p */ |
| 62 |
|
SmartPointerForwardReference (T *p); |
| 63 |
|
|
| 64 |
|
/** Destructor */ |
| 65 |
|
~SmartPointerForwardReference (); |
| 66 |
|
|
| 67 |
|
/** Overload operator -> */ |
| 68 |
|
T *operator -> () const; |
| 69 |
|
|
| 70 |
|
/** Return pointer to object. */ |
| 71 |
|
operator T * () const; |
| 72 |
|
|
| 73 |
|
/** Access function to pointer. */ |
| 74 |
|
T *GetPointer () const; |
| 75 |
|
|
| 76 |
|
/** Comparison of pointers. Less than comparison. */ |
| 77 |
|
bool operator < (const SmartPointerForwardReference &r); |
| 78 |
|
|
| 79 |
|
/** Comparison of pointers. Greater than comparison. */ |
| 80 |
|
bool operator > (const SmartPointerForwardReference &r); |
| 81 |
|
|
| 82 |
|
/** Comparison of pointers. Less than or equal to comparison. */ |
| 83 |
|
bool operator <= (const SmartPointerForwardReference &r); |
| 84 |
|
|
| 85 |
|
/** Comparison of pointers. Greater than or equal to comparison. */ |
| 86 |
|
bool operator >= (const SmartPointerForwardReference &r); |
| 87 |
|
|
| 88 |
|
/** Overload operator assignment. */ |
| 89 |
LEN |
SmartPointerForwardReference &operator = (const SmartPointerForwardReference &r); |
| 90 |
|
|
| 91 |
|
/** Overload operator assignment. */ |
| 92 |
|
SmartPointerForwardReference &operator = (const WeakPointer<T> &r); |
| 93 |
|
|
| 94 |
|
/** Overload operator assignment. */ |
| 95 |
|
SmartPointerForwardReference &operator = (T *r); |
| 96 |
|
|
| 97 |
|
/** Function to print object pointed to */ |
| 98 |
|
T *Print (std::ostream& os) const; |
| 99 |
|
|
| 100 |
|
private: |
| 101 |
|
/** The pointer to the object referrred to by this smart pointer. */ |
| 102 |
|
T* m_Pointer; |
| 103 |
|
|
| 104 |
|
void Register(); |
| 105 |
|
void UnRegister(); |
| 106 |
|
|
| 107 |
|
}; |
| 108 |
|
|
| 109 |
IND |
**template <typename T> |
| 110 |
LEN,IND |
**std::ostream& operator<< (std::ostream& os, SmartPointerForwardReference<T> p) |
| 111 |
IND |
**{ |
| 112 |
IND |
****p.Print(os); |
| 113 |
IND |
****return os; |
| 114 |
IND |
**} |
| 115 |
|
|
| 116 |
|
} // end namespace itk |
| 117 |
|
|
| 118 |
|
#endif |
| 119 |
|
|